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:
Ingo Weinhold 2009-07-18 23:11:20 +00:00
parent 72e9c66b4d
commit d26889cca5
8 changed files with 192 additions and 0 deletions

View File

@ -0,0 +1,36 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* 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);
}

View File

@ -0,0 +1,29 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* 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

View File

@ -0,0 +1,13 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include "FunctionParameterID.h"
FunctionParameterID::~FunctionParameterID()
{
}

View File

@ -0,0 +1,18 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* 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

View File

@ -0,0 +1,13 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include "LocalVariableID.h"
LocalVariableID::~LocalVariableID()
{
}

View File

@ -0,0 +1,18 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* 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

View File

@ -0,0 +1,19 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include "ObjectID.h"
ObjectID::ObjectID()
:
fHashValue(0)
{
}
ObjectID::~ObjectID()
{
}

View File

@ -0,0 +1,46 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* 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