RegistryBase.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 $Header$
00004 
00005 */
00006 
00007 #include "Error.h"
00008 
00009 #include "RegistryBase.h"
00010 
00011 // Public methods.
00012 
00013 RegistryBase::RegistryBase(const String &name, const String& manual, const RegistryFlags flags) :
00014   NamedObject(ajustName(name), manual),
00015   _isBinded(false),
00016   _owner(NULL)
00017 {
00018   _persistency = (RegistryPersistency)(flags & 0xFFU << REG_PERSISTENCY_SHIFT);
00019   _accessMode = (RegistryAccessMode)(flags & 0xFFU << REG_ACCESS_MODE_SHIFT);
00020   _visibility = (RegistryVisibility)(flags & 0xFFU << REG_VISIBILITY_SHIFT);
00021 }
00022 
00023 RegistryBase::~RegistryBase()
00024 {
00025 }
00026 
00027 RegistryAccessMode RegistryBase::accessMode() const
00028 {
00029   return _accessMode;
00030 }
00031 
00032 RegistryVisibility RegistryBase::visibility() const
00033 {
00034   return _visibility;
00035 }
00036 
00037 RegistryPersistency RegistryBase::persistency() const
00038 {
00039   return _persistency;
00040 }
00041 
00042 int RegistryBase::setStr(const String &name, const String &value, Object *owner)
00043 {
00044   RegistryBase *regBase;
00045   int res;
00046 
00047   if (FAILED(res = RegistryBase::get(ajustName(name), &regBase, owner)))
00048     return ERROR_BACKTRACE(res);
00049 
00050   if (FAILED(res = regBase->fromString(value)))
00051     return ERROR_BACKTRACE(res);
00052 
00053   return OK;
00054 }
00055 
00056 int RegistryBase::setStr(const String &name, const String &value, const ObjectId ownerId)
00057 {
00058   Object *owner;
00059   int res;
00060 
00061   if (FAILED(res = Object::get(ownerId, &owner)))
00062     return ERROR_BACKTRACE(res);
00063   if (FAILED(res = setStr(ajustName(name), value, owner)))
00064     return ERROR_BACKTRACE(res);
00065 
00066   return OK;
00067 }
00068 
00069 int RegistryBase::getStr(const String &name, String &value, Object *owner)
00070 {
00071   RegistryBase *regBase;
00072   int res;
00073 
00074   if (FAILED(res = RegistryBase::get(ajustName(name), &regBase, owner)))
00075     return ERROR_BACKTRACE(res);
00076 
00077   if (FAILED(res = regBase->toString(value)))
00078     return ERROR_BACKTRACE(res);
00079 
00080   return OK;
00081 }
00082 
00083 int RegistryBase::getStr(const String &name, String &value, const ObjectId ownerId)
00084 {
00085   Object *owner;
00086   int res;
00087 
00088   if (FAILED(res = Object::get(ownerId, &owner)))
00089     return ERROR_BACKTRACE(res);
00090   if (FAILED(res = getStr(ajustName(name), value, owner)))
00091     return ERROR_BACKTRACE(res);
00092 
00093   return OK;
00094 }
00095 
00096 int RegistryBase::bind(Object *owner)
00097 {
00098   if (_isBinded)
00099     return OK;
00100 
00101   int res;
00102 
00103   if (FAILED(res = Object::bindRegistry(owner, this)))
00104     return ERROR_BACKTRACE(res);
00105 
00106   _owner = owner;
00107   _isBinded = true;
00108 
00109   return OK;
00110 }
00111 
00112 bool RegistryBase::binded() const
00113 {
00114   return _isBinded;
00115 }
00116 
00117 // Protected methods.
00118 
00119 int RegistryBase::get(const String &name, RegistryBase **reg, Object *owner)
00120 {
00121   *reg = NULL;
00122 
00123   if (!reg)
00124     return ERROR(MSG_NULL_POINTER);
00125 
00126   if (name.empty())
00127     return ERROR(MSG_REGISTRY_EMPTY_NAME);
00128 
00129   RegistryList *list = owner ? &(owner->_registryPrivate) : &_registryStatic;
00130   String n(ajustName(name));
00131   RegistryList::const_iterator f = list->find(n);
00132 
00133   if (f == list->end())
00134     return ERROR(MSG_REGISTRY_NOT_FOUND, CSTRING(n));
00135 
00136   *reg = f->second;
00137 
00138   return OK;
00139 }

Generated on Thu Sep 6 20:11:25 2007 for Pylon Application Platform by  doxygen 1.5.1