Base classes for IDs for various objects. The idea is to use them to uniquely
identify the respective objects without actually holding a pointer to them. They will eventually also become persistable which will allow e.g. to associate (and store) settings with the objects. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31630 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "FunctionID.h"
|
||||||
|
|
||||||
|
#include "StringUtils.h"
|
||||||
|
|
||||||
|
|
||||||
|
FunctionID::FunctionID(const BString& idString)
|
||||||
|
:
|
||||||
|
fIDString(idString)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FunctionID::~FunctionID()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
FunctionID::operator==(const ObjectID& other) const
|
||||||
|
{
|
||||||
|
const FunctionID* functionID = dynamic_cast<const FunctionID*>(&other);
|
||||||
|
return functionID != NULL && fIDString == functionID->fIDString;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32
|
||||||
|
FunctionID::ComputeHashValue() const
|
||||||
|
{
|
||||||
|
return StringUtils::HashValue(fIDString);
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef FUNCTION_ID_H
|
||||||
|
#define FUNCTION_ID_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
#include "ObjectID.h"
|
||||||
|
|
||||||
|
|
||||||
|
class FunctionID : public ObjectID {
|
||||||
|
public:
|
||||||
|
FunctionID(const BString& idString);
|
||||||
|
virtual ~FunctionID();
|
||||||
|
|
||||||
|
virtual bool operator==(const ObjectID& other) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual uint32 ComputeHashValue() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const BString fIDString;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // FUNCTION_ID_H
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "FunctionParameterID.h"
|
||||||
|
|
||||||
|
|
||||||
|
FunctionParameterID::~FunctionParameterID()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef FUNCTION_PARAMETER_ID_H
|
||||||
|
#define FUNCTION_PARAMETER_ID_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "ObjectID.h"
|
||||||
|
|
||||||
|
|
||||||
|
class FunctionParameterID : public ObjectID {
|
||||||
|
public:
|
||||||
|
virtual ~FunctionParameterID();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // FUNCTION_PARAMETER_ID_H
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "LocalVariableID.h"
|
||||||
|
|
||||||
|
|
||||||
|
LocalVariableID::~LocalVariableID()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef LOCAL_VARIABLE_ID_H
|
||||||
|
#define LOCAL_VARIABLE_ID_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "ObjectID.h"
|
||||||
|
|
||||||
|
|
||||||
|
class LocalVariableID : public ObjectID {
|
||||||
|
public:
|
||||||
|
virtual ~LocalVariableID();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // LOCAL_VARIABLE_ID_H
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "ObjectID.h"
|
||||||
|
|
||||||
|
|
||||||
|
ObjectID::ObjectID()
|
||||||
|
:
|
||||||
|
fHashValue(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ObjectID::~ObjectID()
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef OBJECT_ID_H
|
||||||
|
#define OBJECT_ID_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <Referenceable.h>
|
||||||
|
|
||||||
|
|
||||||
|
class ObjectID : public Referenceable {
|
||||||
|
public:
|
||||||
|
ObjectID();
|
||||||
|
virtual ~ObjectID();
|
||||||
|
|
||||||
|
inline uint32 HashValue() const;
|
||||||
|
|
||||||
|
virtual bool operator==(const ObjectID& other) const = 0;
|
||||||
|
inline bool operator!=(const ObjectID& other) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual uint32 ComputeHashValue() const = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
mutable uint32 fHashValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
uint32
|
||||||
|
ObjectID::HashValue() const
|
||||||
|
{
|
||||||
|
if (fHashValue == 0)
|
||||||
|
fHashValue = ComputeHashValue();
|
||||||
|
return fHashValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ObjectID::operator!=(const ObjectID& other) const
|
||||||
|
{
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // OBJECT_ID_H
|
||||||
Reference in New Issue
Block a user