66 lines
1.6 KiB
C++
66 lines
1.6 KiB
C++
#include "IPropertyHolder.h"
|
|
#include <assert.h>
|
|
namespace LifeCore
|
|
{
|
|
bool IPropertyHolder::Serialize(LifeCore::IMemoryStream* stm)
|
|
{
|
|
stm->Write(size_t(properties.size()));
|
|
for(PropertyCollectionItr it = properties.begin(); it != properties.end(); ++it){
|
|
(*it)->Serialize(stm);
|
|
}
|
|
return true;
|
|
}
|
|
bool IPropertyHolder::Deserialize(LifeCore::IMemoryStream* stm)
|
|
{
|
|
size_t prop_cnt;
|
|
stm->Read(&prop_cnt, sizeof(prop_cnt));
|
|
assert(prop_cnt == properties.size() && "Failed on IPropertyHolder deserialization!");
|
|
for(PropertyCollectionItr it = properties.begin(); it != properties.end(); ++it){
|
|
(*it)->Deserialize(stm);
|
|
}
|
|
return true;
|
|
}
|
|
PropertyCollection* IPropertyHolder::GetProperties()
|
|
{
|
|
return &properties;
|
|
}
|
|
void IPropertyHolder::RegisterProperty(IProperty* property)
|
|
{
|
|
properties.push_back(property);
|
|
}
|
|
void IPropertyHolder::UnregisterProperty(IProperty* property)
|
|
{
|
|
UNREFERENCED_PARAMETER(property);
|
|
//TODO remove prop
|
|
}
|
|
bool IPropertyHolder::GetPropertyByAttribute(const String& name, IProperty** prop)
|
|
{
|
|
for(PropertyCollectionItr it = properties.begin(); it != properties.end(); ++it)
|
|
{
|
|
IProperty* p = *it;
|
|
if(p->ContainsAttribute(name))
|
|
{
|
|
*prop = p;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
bool IPropertyHolder::GetPropertyByAttribute(const String& name, const String& value, IProperty** prop)
|
|
{
|
|
for(PropertyCollectionItr it = properties.begin(); it != properties.end(); ++it)
|
|
{
|
|
IProperty* p = *it;
|
|
String tmpVal;
|
|
if(p->GetAttribute(name, tmpVal) == SC_OK)
|
|
{
|
|
if(tmpVal == value)
|
|
{
|
|
*prop = p;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
} |