Added MStorage::merge function
This commit is contained in:
parent
a87e63a277
commit
d6b8759ee2
10
MStorage.cpp
10
MStorage.cpp
@ -350,6 +350,16 @@ void MStorage::setGroup(const std::string &key, MStorage *group) {
|
||||
insertRaw(key, group);
|
||||
}
|
||||
|
||||
void MStorage::merge(MStorage *group, bool replaceValues) {
|
||||
MValueMapIterator it = group->begin();
|
||||
while(it != group->end()) {
|
||||
if(replaceValues || !containsKey(it->first)) {
|
||||
insertRaw(it->first, it->second);
|
||||
}
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t MStorage::getInt(const std::string &key) {
|
||||
IMStorageBasicType *bval = getBasicType(key);
|
||||
return bval ? bval->getInt() : 0;
|
||||
|
@ -147,6 +147,7 @@ public:
|
||||
void setByte(const std::string &key, uint8_t val);
|
||||
void setString(const std::string &key, std::string val);
|
||||
void setGroup(const std::string &key, MStorage *group);
|
||||
void merge(MStorage *group, bool replaceValues);
|
||||
|
||||
int32_t getInt(const std::string &key);
|
||||
int32_t* getIntArray(const std::string &key, uint16_t *len);
|
||||
|
@ -40,6 +40,11 @@ int main(int argc, char const *argv[]) {
|
||||
int32_t _ints[] = {42, 34, 32323, 5573453};
|
||||
group->setIntArray("someIntArray", _ints, 4); // array is being copied
|
||||
|
||||
MStorage *groupToMerge = new MStorage();
|
||||
groupToMerge->setDouble("someDouble2", 1.23);
|
||||
|
||||
group->merge(groupToMerge, false);
|
||||
|
||||
storage->setGroup("someGroup", group);
|
||||
|
||||
print_fieds(storage);
|
||||
|
Loading…
x
Reference in New Issue
Block a user