This class provides a mechanism to access the registry file. Registry consists of several sections and each section can have several entries, but only to a single depth. An entry consists of a name-value pair. The entry name must be unique inside the same section. The entry value must be one of the following data types: int, double, float, String, UuId, ByteBuffer.
Registry is an easy way to persist data.
To persist your data, you must create a section and add a value, as shown below:
//Osp::Io::Registry::Registry(void)
Osp::Io::Registry* pReg = new Osp::Io::Registry();
String regPath(L"regTest.ini");
result r = pReg->Construct(regPath, true);
TryCatch(r == E_SUCCESS, , "Failed to get a valid Registry. %s",
GetErrorMessage(r));
//create a section (data types: int, double, float, String,
//UuId, ByteBuffer)
r = pReg->AddSection(section);
TryCatch(r == E_SUCCESS, , "Failed to add the record section. %s",
GetErrorMessage(r));
//add a value to created section
//result AddValue (const Osp::Base::String §ionName,
//const Osp::Base::String &entryName,
//const Osp::Base::String &value)
//example: entryRecord = key, record = value
r = pReg->AddValue(section, entryRecord, record);
TryCatch(r == E_SUCCESS, , "Failed to add the record entry. %s",
GetErrorMessage(r));
//Writes the current contents of a registry in memory to
//the non-volatile storage.
r = pReg->Flush();
TryCatch(r == E_SUCCESS, , "Failed to save registry changes. %s",
GetErrorMessage(r));
}
return;
CATCH:
SetLastResult(r);
if(pReg != null){
delete pReg;
pReg = null;
}
If you need to recover registered data:
//result GetValue (const Osp::Base::String §ionName,
//const Osp::Base::String &entryName,
//Osp::Base::ByteBuffer &retVal) const
//result GetValue (const Osp::Base::String §ionName,
//const Osp::Base::String &entryName,
//Osp::Base::UuId &retVal) const
//result GetValue (const Osp::Base::String §ionName,
//const Osp::Base::String &entryName,
//Osp::Base::String &retVal) const
//result GetValue (const Osp::Base::String §ionName,
//const Osp::Base::String &entryName, float &retVal) const
//result GetValue (const Osp::Base::String §ionName,
//const Osp::Base::String &entryName, double &retVal) const
//result GetValue (const Osp::Base::String §ionName,
//const Osp::Base::String &entryName, int &retVal) const
r = pReg->GetValue(section, key, value);
TryCatch(r == E_SUCCESS, , "Failed to get the record from
the registry. %s", GetErrorMessage(r));
If you need to check if a section already exists:
bool
RegistryUtils::ContainsSection(Osp::Io::Registry& reg,
Osp::Base::String& section)
{
bool containsKey = false;
Osp::Base::Collection::IList* pList = reg.GetAllSectionNamesN();
Osp::Base::String* pSection = null;
for(int index = 0; index < pList->GetCount(); index++)
{
pSection = (Osp::Base::String*)pList->GetAt(index);
if(section.Equals(*(pSection), false))
{
containsKey = true;
break;
}
}
If you need more info (API, code examples, ...), try Osp::Io::Registry Class Reference.
You can see registry file in:
Thanks for your visit! :)
Next post: bada 2.0
Feel free to ask/suggest/comment.
Twitter: @oliveiraeduardo
Nenhum comentário:
Postar um comentário