seperated content value from retrodb

added local meta changing fucntionality to gxs 
also added msgrelated info id retrieval to tokeservice


git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5452 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2012-08-21 21:32:07 +00:00
parent 8a7c011c5d
commit 6dd18eea46
13 changed files with 983 additions and 746 deletions

View file

@ -0,0 +1,311 @@
/*
* util/contentvalue.cc, key val container
*
* Copyright 2012 Christopher Evi-Parker
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include <iostream>
#include <memory.h>
#include "contentvalue.h"
const uint8_t ContentValue::BOOL_TYPE = 1;
const uint8_t ContentValue::DATA_TYPE = 2;
const uint8_t ContentValue::STRING_TYPE = 3;
const uint8_t ContentValue::DOUBLE_TYPE = 4;
const uint8_t ContentValue::INT32_TYPE = 5;
const uint8_t ContentValue::INT64_TYPE = 6;
/**************** content value implementation ******************/
typedef std::pair<std::string, uint8_t> KeyTypePair;
ContentValue::ContentValue(){
}
ContentValue::~ContentValue(){
// release resources held in data
clearData();
}
ContentValue::ContentValue(ContentValue &from){
std::map<std::string, uint8_t> keyTypeMap;
from.getKeyTypeMap(keyTypeMap);
std::map<std::string, uint8_t>::const_iterator cit =
keyTypeMap.begin();
uint8_t type = 0;
std::string currKey;
std::string val = "";
char *src = NULL;
uint32_t data_len = 0;
for(; cit != keyTypeMap.end(); cit++){
type = cit->second;
currKey = cit->first;
switch(type){
case INT32_TYPE:
{
int32_t value;
from.getAsInt32(currKey, value);
put(currKey, value);
break;
}
case INT64_TYPE:
{
int64_t value;
from.getAsInt64(currKey, value);
put(currKey, value);
break;
}
case STRING_TYPE:
{
from.getAsString(currKey, val);
put(currKey, val);
break;
}
case BOOL_TYPE:
{
bool value;
from.getAsBool(currKey, value);
put(currKey, value);
break;
}
case DATA_TYPE:
{
from.getAsData(currKey, data_len, src);
put(currKey, data_len, src);
break;
}
case DOUBLE_TYPE:
double value;
from.getAsDouble(currKey, value);
put(currKey, value);
break;
default:
std::cerr << "ContentValue::ContentValue(ContentValue &from):"
<< "Error! Unrecognised data type!" << std::endl;
}
}
}
void ContentValue::put(const std::string &key, bool value){
if(mKvSet.find(key) != mKvSet.end())
removeKeyValue(key);
mKvSet.insert(KeyTypePair(key, BOOL_TYPE));
mKvBool.insert(std::pair<std::string, bool>(key, value));
}
void ContentValue::put(const std::string &key, const std::string &value){
if(mKvSet.find(key) != mKvSet.end())
removeKeyValue(key);
mKvSet.insert(KeyTypePair(key, STRING_TYPE));
mKvString.insert(std::pair<std::string, std::string>(key, value));
}
void ContentValue::put(const std::string &key, double value){
if(mKvSet.find(key) != mKvSet.end())
removeKeyValue(key);
mKvSet.insert(KeyTypePair(key,DOUBLE_TYPE));
mKvDouble.insert(std::pair<std::string, double>(key, value));
}
void ContentValue::put(const std::string &key, int32_t value){
if(mKvSet.find(key) != mKvSet.end())
removeKeyValue(key);
mKvSet.insert(KeyTypePair(key, INT32_TYPE));
mKvInt32.insert(std::pair<std::string, int32_t>(key, value));
}
void ContentValue::put(const std::string &key, int64_t value){
if(mKvSet.find(key) != mKvSet.end())
removeKeyValue(key);
mKvSet.insert(KeyTypePair(key, INT64_TYPE));
mKvInt64.insert(std::pair<std::string, int64_t>(key, value));
}
void ContentValue::put(const std::string &key, uint32_t len, const char* value){
// release memory from old key value if key
// exists
if(mKvSet.find(key) != mKvSet.end()) {
removeKeyValue(key);
}
mKvSet.insert(KeyTypePair(key, DATA_TYPE));
char* dest = NULL;
// len is zero then just put a NULL entry
if(len != 0){
dest = new char[len];
memcpy(dest, value, len);
}
mKvData.insert(std::pair<std::string, std::pair<uint32_t, char*> >
(key, std::pair<uint32_t, char*>(len, dest)));
}
bool ContentValue::getAsBool(const std::string &key, bool& value) const{
std::map<std::string, bool>::const_iterator it;
if((it = mKvBool.find(key)) == mKvBool.end())
return false;
value = it->second;
return true;
}
bool ContentValue::getAsInt32(const std::string &key, int32_t& value) const{
std::map<std::string, int32_t>::const_iterator it;
if((it = mKvInt32.find(key)) == mKvInt32.end())
return false;
value = it->second;
return true;
}
bool ContentValue::getAsInt64(const std::string &key, int64_t& value) const{
std::map<std::string, int64_t>::const_iterator it;
if((it = mKvInt64.find(key)) == mKvInt64.end())
return false;
value = it->second;
return true;
}
bool ContentValue::getAsString(const std::string &key, std::string &value) const{
std::map<std::string, std::string>::const_iterator it;
if((it = mKvString.find(key)) == mKvString.end())
return false;
value = it->second;
return true;
}
bool ContentValue::getAsData(const std::string& key, uint32_t &len, char*& value) const{
std::map<std::string, std::pair<uint32_t, char*> >::const_iterator it;
if((it = mKvData.find(key)) == mKvData.end())
return false;
const std::pair<uint32_t, char*> &kvRef = it->second;
len = kvRef.first;
value = kvRef.second;
return true;
}
bool ContentValue::getAsDouble(const std::string &key, double& value) const{
std::map<std::string, double>::const_iterator it;
if((it = mKvDouble.find(key)) == mKvDouble.end())
return false;
value = it->second;
return true;
}
bool ContentValue::removeKeyValue(const std::string &key){
std::map<std::string, uint8_t>::iterator mit;
if((mit = mKvSet.find(key)) == mKvSet.end())
return false;
if(mit->second == BOOL_TYPE)
mKvBool.erase(key);
if(mit->second == INT64_TYPE)
mKvInt64.erase(key);
if(mit->second == DATA_TYPE){
delete[] (mKvData[key].second);
mKvData.erase(key);
}
if(mit->second == DOUBLE_TYPE)
mKvDouble.erase(key);
if(mit->second == STRING_TYPE)
mKvString.erase(key);
if(mit->second == INT32_TYPE)
mKvInt32.erase(key);
mKvSet.erase(key);
return true;
}
void ContentValue::getKeyTypeMap(std::map<std::string, uint8_t> &keySet) const {
keySet = mKvSet;
}
void ContentValue::clear(){
mKvSet.clear();
mKvBool.clear();
mKvDouble.clear();
mKvString.clear();
mKvInt32.clear();
mKvInt64.clear();
clearData();
}
void ContentValue::clearData(){
std::map<std::string, std::pair<uint32_t, char*> >::iterator
mit = mKvData.begin();
for(; mit != mKvData.end(); mit++){
if(mit->second.first != 0)
delete[] (mit->second.second);
}
mKvData.clear();
}

View file

@ -0,0 +1,183 @@
#ifndef CONTENTVALUE_H
#define CONTENTVALUE_H
/*
* util/contentvalue.h, key val container
*
* Copyright 2012 Christopher Evi-Parker
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include <inttypes.h>
#include <string>
#include <map>
/*!
* @brief Convenience container for making additions to databases
* This class provides a means of holding column values to insert into a database
*/
class ContentValue {
public:
static const uint8_t INT32_TYPE;
static const uint8_t INT64_TYPE;
static const uint8_t DOUBLE_TYPE;
static const uint8_t STRING_TYPE;
static const uint8_t DATA_TYPE;
static const uint8_t BOOL_TYPE;
ContentValue();
/*!
* copy constructor that copys the key value set from another \n
* ContentValue object to this one
* makes a deep copy of raw data
* @param from ContentValue instance to copy key value set from
*/
ContentValue(ContentValue& from);
/*!
*
*
*
*/
~ContentValue();
/*!
* Adds a value to the set
* @param key the name of the value to put
* @param value the data for the value to put
* @warning cast string literals explicitly as string, observed string literal \n
* being casted to bool instead e.g. string("hello") rather than "hello"
*/
void put(const std::string& key, const std::string& value);
/*!
* Adds a value to the set
* @param key the name of the value to put
* @param value the data for the value to put
*/
void put(const std::string& key, bool value);
/*!
* Adds a value to the set
* @param key the name of the value to put
* @param value the data for the value to put
*/
void put(const std::string& key, int64_t value);
/*!
* Adds a value to the set
* @param key the name of the value to put
* @param value the data for the value to put
*/
void put(const std::string& key, int32_t value);
/*!
* Adds a value to the set
* @param key the name of the value to put
* @param value the data for the value to put
*/
void put(const std::string& key, double value);
/*!
* Adds a value to the set
* @param key the name of the value to put
* @param value the data for the value to put
*/
void put(const std::string& key, uint32_t len, const char* value);
/*!
* get value as 32 bit signed integer
* @param key the value to get
*/
bool getAsInt32(const std::string& key, int32_t& value) const;
/*!
* get value as 64 bit signed integer
* @param key the value to get
*/
bool getAsInt64(const std::string& key, int64_t& value) const;
/*!
* get value as bool
* @param key the value to get
*/
bool getAsBool(const std::string& key, bool& value) const;
/*!
* get as value double
* @param key the value to get
*/
bool getAsDouble(const std::string& key, double& value) const;
/*!
* get as value as string
* @param key the value to get
* @param value the data retrieved
*/
bool getAsString(const std::string& key, std::string& value) const;
/*!
* get as value as raw data
* @warning Deep copy of data reference should be made, if this instance ContentValue \n
* is destroyed pointer returned (value) is pointing to invalid memory
* @param key the value to get
*/
bool getAsData(const std::string&, uint32_t& len, char*& value) const;
/*!
* @param keySet the is set with key to type pairs contained in the ContentValue instance
*/
void getKeyTypeMap(std::map<std::string, uint8_t>& keySet) const;
/*!
* @param key the key of the key value pair to remove
* @return true if key was found and removed, false otherwise
*/
bool removeKeyValue(const std::string& key);
/*!
* clears this data structure of all its key value pairs held
*/
void clear();
private:
/*!
* release memory resource associated with mKvData
*/
void clearData();
private:
std::map<std::string, int32_t> mKvInt32;
std::map<std::string, int64_t> mKvInt64;
std::map<std::string, double> mKvDouble;
std::map<std::string, std::string> mKvString;
std::map<std::string, std::pair<uint32_t, char*> > mKvData;
std::map<std::string, bool> mKvBool;
std::map<std::string, uint8_t> mKvSet;
};
#endif // CONTENTVALUE_H

View file

@ -32,6 +32,8 @@
//#define RETRODB_DEBUG
void free_blob(void* dat){
char* c = (char*) dat;
@ -40,13 +42,6 @@ void free_blob(void* dat){
}
const uint8_t ContentValue::BOOL_TYPE = 1;
const uint8_t ContentValue::DATA_TYPE = 2;
const uint8_t ContentValue::STRING_TYPE = 3;
const uint8_t ContentValue::DOUBLE_TYPE = 4;
const uint8_t ContentValue::INT32_TYPE = 5;
const uint8_t ContentValue::INT64_TYPE = 6;
const int RetroDb::OPEN_READONLY = SQLITE_OPEN_READONLY;
const int RetroDb::OPEN_READWRITE = SQLITE_OPEN_READWRITE;
const int RetroDb::OPEN_READWRITE_CREATE = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
@ -234,9 +229,9 @@ bool RetroDb::sqlInsert(const std::string &table, const std::string& nullColumnH
uint8_t type = mit->second;
std::string key = mit->first;
switch(type){
case ContentValue::BOOL_TYPE:
if(ContentValue::BOOL_TYPE == type)
{
bool value;
cv.getAsBool(key, value);
@ -244,7 +239,7 @@ bool RetroDb::sqlInsert(const std::string &table, const std::string& nullColumnH
qValues += oStrStream.str();
break;
}
case ContentValue::DOUBLE_TYPE:
else if( ContentValue::DOUBLE_TYPE == type)
{
double value;
cv.getAsDouble(key, value);
@ -252,7 +247,7 @@ bool RetroDb::sqlInsert(const std::string &table, const std::string& nullColumnH
qValues += oStrStream.str();
break;
}
case ContentValue::DATA_TYPE:
else if( ContentValue::DATA_TYPE == type)
{
char* value;
uint32_t len;
@ -265,14 +260,14 @@ bool RetroDb::sqlInsert(const std::string &table, const std::string& nullColumnH
qValues += "?"; // parameter
break;
}
case ContentValue::STRING_TYPE:
else if ( ContentValue::STRING_TYPE == type)
{
std::string value;
cv.getAsString(key, value);
qValues += "'" + value +"'";
break;
}
case ContentValue::INT32_TYPE:
else if ( ContentValue::INT32_TYPE == type)
{
int32_t value;
cv.getAsInt32(key, value);
@ -280,7 +275,7 @@ bool RetroDb::sqlInsert(const std::string &table, const std::string& nullColumnH
qValues += oStrStream.str();
break;
}
case ContentValue::INT64_TYPE:
else if( ContentValue::INT64_TYPE == type)
{
int64_t value;
cv.getAsInt64(key, value);
@ -288,7 +283,7 @@ bool RetroDb::sqlInsert(const std::string &table, const std::string& nullColumnH
qValues += oStrStream.str();
break;
}
}
mit++;
if(mit != keyTypeMap.end()){ // add comma if more columns left
@ -419,9 +414,7 @@ bool RetroDb::sqlUpdate(const std::string &tableName, std::string whereClause, c
uint8_t type = mit->second;
std::string key = mit->first;
switch(type){
case ContentValue::BOOL_TYPE:
if( ContentValue::BOOL_TYPE == type)
{
bool value;
cv.getAsBool(key, value);
@ -429,7 +422,7 @@ bool RetroDb::sqlUpdate(const std::string &tableName, std::string whereClause, c
qValues += key + "='" + oStrStream.str();
break;
}
case ContentValue::DOUBLE_TYPE:
else if( ContentValue::DOUBLE_TYPE == type)
{
double value;
cv.getAsDouble(key, value);
@ -437,7 +430,7 @@ bool RetroDb::sqlUpdate(const std::string &tableName, std::string whereClause, c
qValues += key + "='" + oStrStream.str();
break;
}
case ContentValue::DATA_TYPE:
else if( ContentValue::DATA_TYPE == type)
{
char* value;
uint32_t len;
@ -446,14 +439,14 @@ bool RetroDb::sqlUpdate(const std::string &tableName, std::string whereClause, c
qValues += key + "='" + oStrStream.str() + "' ";
break;
}
case ContentValue::STRING_TYPE:
else if( ContentValue::STRING_TYPE == type)
{
std::string value;
cv.getAsString(key, value);
qValues += key + "='" + value + "' ";
break;
}
case ContentValue::INT32_TYPE:
else if( ContentValue::INT32_TYPE == type)
{
int32_t value;
cv.getAsInt32(key, value);
@ -461,7 +454,7 @@ bool RetroDb::sqlUpdate(const std::string &tableName, std::string whereClause, c
qValues += key + "='" + oStrStream.str() + "' ";
break;
}
case ContentValue::INT64_TYPE:
else if( ContentValue::INT64_TYPE == type)
{
int64_t value;
cv.getAsInt64(key, value);
@ -469,7 +462,7 @@ bool RetroDb::sqlUpdate(const std::string &tableName, std::string whereClause, c
qValues += key + "='" + oStrStream.str() + "' ";
break;
}
}
mit++;
if(mit != keyTypeMap.end()){ // add comma if more columns left
@ -715,276 +708,3 @@ const void* RetroCursor::getData(int columnIndex, uint32_t &datSize){
}
/**************** content value implementation ******************/
typedef std::pair<std::string, uint8_t> KeyTypePair;
ContentValue::ContentValue(){
}
ContentValue::~ContentValue(){
// release resources held in data
clearData();
}
ContentValue::ContentValue(ContentValue &from){
std::map<std::string, uint8_t> keyTypeMap;
from.getKeyTypeMap(keyTypeMap);
std::map<std::string, uint8_t>::const_iterator cit =
keyTypeMap.begin();
uint8_t type = 0;
std::string currKey;
std::string val = "";
char *src = NULL;
uint32_t data_len = 0;
for(; cit != keyTypeMap.end(); cit++){
type = cit->second;
currKey = cit->first;
switch(type){
case INT32_TYPE:
{
int32_t value;
from.getAsInt32(currKey, value);
put(currKey, value);
break;
}
case INT64_TYPE:
{
int64_t value;
from.getAsInt64(currKey, value);
put(currKey, value);
break;
}
case STRING_TYPE:
{
from.getAsString(currKey, val);
put(currKey, val);
break;
}
case BOOL_TYPE:
{
bool value;
from.getAsBool(currKey, value);
put(currKey, value);
break;
}
case DATA_TYPE:
{
from.getAsData(currKey, data_len, src);
put(currKey, data_len, src);
break;
}
case DOUBLE_TYPE:
double value;
from.getAsDouble(currKey, value);
put(currKey, value);
break;
default:
std::cerr << "ContentValue::ContentValue(ContentValue &from):"
<< "Error! Unrecognised data type!" << std::endl;
}
}
}
void ContentValue::put(const std::string &key, bool value){
if(mKvSet.find(key) != mKvSet.end())
removeKeyValue(key);
mKvSet.insert(KeyTypePair(key, BOOL_TYPE));
mKvBool.insert(std::pair<std::string, bool>(key, value));
}
void ContentValue::put(const std::string &key, const std::string &value){
if(mKvSet.find(key) != mKvSet.end())
removeKeyValue(key);
mKvSet.insert(KeyTypePair(key, STRING_TYPE));
mKvString.insert(std::pair<std::string, std::string>(key, value));
}
void ContentValue::put(const std::string &key, double value){
if(mKvSet.find(key) != mKvSet.end())
removeKeyValue(key);
mKvSet.insert(KeyTypePair(key,DOUBLE_TYPE));
mKvDouble.insert(std::pair<std::string, double>(key, value));
}
void ContentValue::put(const std::string &key, int32_t value){
if(mKvSet.find(key) != mKvSet.end())
removeKeyValue(key);
mKvSet.insert(KeyTypePair(key, INT32_TYPE));
mKvInt32.insert(std::pair<std::string, int32_t>(key, value));
}
void ContentValue::put(const std::string &key, int64_t value){
if(mKvSet.find(key) != mKvSet.end())
removeKeyValue(key);
mKvSet.insert(KeyTypePair(key, INT64_TYPE));
mKvInt64.insert(std::pair<std::string, int64_t>(key, value));
}
void ContentValue::put(const std::string &key, uint32_t len, const char* value){
// release memory from old key value if key
// exists
if(mKvSet.find(key) != mKvSet.end()) {
removeKeyValue(key);
}
mKvSet.insert(KeyTypePair(key, DATA_TYPE));
char* dest = NULL;
// len is zero then just put a NULL entry
if(len != 0){
dest = new char[len];
memcpy(dest, value, len);
}
mKvData.insert(std::pair<std::string, std::pair<uint32_t, char*> >
(key, std::pair<uint32_t, char*>(len, dest)));
}
bool ContentValue::getAsBool(const std::string &key, bool& value) const{
std::map<std::string, bool>::const_iterator it;
if((it = mKvBool.find(key)) == mKvBool.end())
return false;
value = it->second;
return true;
}
bool ContentValue::getAsInt32(const std::string &key, int32_t& value) const{
std::map<std::string, int32_t>::const_iterator it;
if((it = mKvInt32.find(key)) == mKvInt32.end())
return false;
value = it->second;
return true;
}
bool ContentValue::getAsInt64(const std::string &key, int64_t& value) const{
std::map<std::string, int64_t>::const_iterator it;
if((it = mKvInt64.find(key)) == mKvInt64.end())
return false;
value = it->second;
return true;
}
bool ContentValue::getAsString(const std::string &key, std::string &value) const{
std::map<std::string, std::string>::const_iterator it;
if((it = mKvString.find(key)) == mKvString.end())
return false;
value = it->second;
return true;
}
bool ContentValue::getAsData(const std::string& key, uint32_t &len, char*& value) const{
std::map<std::string, std::pair<uint32_t, char*> >::const_iterator it;
if((it = mKvData.find(key)) == mKvData.end())
return false;
const std::pair<uint32_t, char*> &kvRef = it->second;
len = kvRef.first;
value = kvRef.second;
return true;
}
bool ContentValue::getAsDouble(const std::string &key, double& value) const{
std::map<std::string, double>::const_iterator it;
if((it = mKvDouble.find(key)) == mKvDouble.end())
return false;
value = it->second;
return true;
}
bool ContentValue::removeKeyValue(const std::string &key){
std::map<std::string, uint8_t>::iterator mit;
if((mit = mKvSet.find(key)) == mKvSet.end())
return false;
if(mit->second == BOOL_TYPE)
mKvBool.erase(key);
if(mit->second == INT64_TYPE)
mKvInt64.erase(key);
if(mit->second == DATA_TYPE){
delete[] (mKvData[key].second);
mKvData.erase(key);
}
if(mit->second == DOUBLE_TYPE)
mKvDouble.erase(key);
if(mit->second == STRING_TYPE)
mKvString.erase(key);
if(mit->second == INT32_TYPE)
mKvInt32.erase(key);
mKvSet.erase(key);
return true;
}
void ContentValue::getKeyTypeMap(std::map<std::string, uint8_t> &keySet) const {
keySet = mKvSet;
}
void ContentValue::clear(){
mKvSet.clear();
mKvBool.clear();
mKvDouble.clear();
mKvString.clear();
mKvInt32.clear();
mKvInt64.clear();
clearData();
}
void ContentValue::clearData(){
std::map<std::string, std::pair<uint32_t, char*> >::iterator
mit = mKvData.begin();
for(; mit != mKvData.end(); mit++){
if(mit->second.first != 0)
delete[] (mit->second.second);
}
mKvData.clear();
}

View file

@ -31,8 +31,8 @@
#include <list>
#include <map>
#include "contentvalue.h"
class ContentValue;
class RetroCursor;
/*!
@ -288,157 +288,7 @@ private:
};
/*!
* @brief Convenience container for making additions to databases
* This class provides a means of holding column values to insert into a database
*/
class ContentValue {
public:
static const uint8_t INT32_TYPE;
static const uint8_t INT64_TYPE;
static const uint8_t DOUBLE_TYPE;
static const uint8_t STRING_TYPE;
static const uint8_t DATA_TYPE;
static const uint8_t BOOL_TYPE;
ContentValue();
/*!
* copy constructor that copys the key value set from another \n
* ContentValue object to this one
* makes a deep copy of raw data
* @param from ContentValue instance to copy key value set from
*/
ContentValue(ContentValue& from);
/*!
*
*
*
*/
~ContentValue();
/*!
* Adds a value to the set
* @param key the name of the value to put
* @param value the data for the value to put
* @warning cast string literals explicitly as string, observed string literal \n
* being casted to bool instead e.g. string("hello") rather than "hello"
*/
void put(const std::string& key, const std::string& value);
/*!
* Adds a value to the set
* @param key the name of the value to put
* @param value the data for the value to put
*/
void put(const std::string& key, bool value);
/*!
* Adds a value to the set
* @param key the name of the value to put
* @param value the data for the value to put
*/
void put(const std::string& key, int64_t value);
/*!
* Adds a value to the set
* @param key the name of the value to put
* @param value the data for the value to put
*/
void put(const std::string& key, int32_t value);
/*!
* Adds a value to the set
* @param key the name of the value to put
* @param value the data for the value to put
*/
void put(const std::string& key, double value);
/*!
* Adds a value to the set
* @param key the name of the value to put
* @param value the data for the value to put
*/
void put(const std::string& key, uint32_t len, const char* value);
/*!
* get value as 32 bit signed integer
* @param key the value to get
*/
bool getAsInt32(const std::string& key, int32_t& value) const;
/*!
* get value as 64 bit signed integer
* @param key the value to get
*/
bool getAsInt64(const std::string& key, int64_t& value) const;
/*!
* get value as bool
* @param key the value to get
*/
bool getAsBool(const std::string& key, bool& value) const;
/*!
* get as value double
* @param key the value to get
*/
bool getAsDouble(const std::string& key, double& value) const;
/*!
* get as value as string
* @param key the value to get
* @param value the data retrieved
*/
bool getAsString(const std::string& key, std::string& value) const;
/*!
* get as value as raw data
* @warning Deep copy of data reference should be made, if this instance ContentValue \n
* is destroyed pointer returned (value) is pointing to invalid memory
* @param key the value to get
*/
bool getAsData(const std::string&, uint32_t& len, char*& value) const;
/*!
* @param keySet the is set with key to type pairs contained in the ContentValue instance
*/
void getKeyTypeMap(std::map<std::string, uint8_t>& keySet) const;
/*!
* @param key the key of the key value pair to remove
* @return true if key was found and removed, false otherwise
*/
bool removeKeyValue(const std::string& key);
/*!
* clears this data structure of all its key value pairs held
*/
void clear();
private:
/*!
* release memory resource associated with mKvData
*/
void clearData();
private:
std::map<std::string, int32_t> mKvInt32;
std::map<std::string, int64_t> mKvInt64;
std::map<std::string, double> mKvDouble;
std::map<std::string, std::string> mKvString;
std::map<std::string, std::pair<uint32_t, char*> > mKvData;
std::map<std::string, bool> mKvBool;
std::map<std::string, uint8_t> mKvSet;
};
#endif // RSSQLITE_H