mStore.read(&value.front(), size);
}
+ void readInternal(char* &value)
+ {
+ size_t size;
+ readInternal(size);
+
+ value = new char[size + 1];
+ mStore.read(value, size);
+ value[size] = '\0';
+ }
+
void readInternal(config::FileDescriptor& fd)
{
fd = mStore.receiveFD();
value = g_variant_get_string(object, NULL);
}
+ static void fromGVariant(GVariant* object, char* &value)
+ {
+ checkType(object, G_VARIANT_TYPE_STRING);
+
+ const char* source = g_variant_get_string(object, NULL);
+ size_t len = std::strlen(source);
+
+ value = new char[len + 1];
+ std::strncpy(value, source, len);
+ value[len] = '\0';
+ }
+
static void fromGVariant(GVariant* object, config::FileDescriptor& value)
{
checkType(object, G_VARIANT_TYPE_INT32);
#include <json.h>
#include <string>
+#include <cstring>
#include <vector>
namespace config {
value = json_object_get_string(object);
}
+ static void fromJsonObject(json_object* object, char* &value)
+ {
+ checkType(object, json_type_string);
+
+ int len = json_object_get_string_len(object);
+ value = new char[len + 1];
+ std::strncpy(value, json_object_get_string(object), len);
+ value[len] = '\0';
+ }
+
template<typename T>
static void fromJsonObject(json_object* object, std::vector<T>& value)
{
checkType(object, json_type_string);
value = json_object_get_string(object);
}
+
+ static void fromJsonObject(json_object* object, char* &value)
+ {
+ checkType(object, json_type_string);
+
+ int len = json_object_get_string_len(object);
+ value = new char[len + 1];
+ std::strncpy(value, json_object_get_string(object), len);
+ value[len] = '\0';
+ }
};
} // namespace config
#include <memory>
#include <set>
#include <cassert>
+#include <cstring>
namespace config {
transaction.commit();
}
-void KVStore::setInternal(const std::string& key, const std::string& value)
+void KVStore::setInternal(const std::string& key, const char* value)
{
Transaction transaction(*this);
ScopedReset scopedReset(mSetValueStmt);
::sqlite3_bind_text(mSetValueStmt->get(), 1, key.c_str(), AUTO_DETERM_SIZE, SQLITE_STATIC);
- ::sqlite3_bind_text(mSetValueStmt->get(), 2, value.c_str(), AUTO_DETERM_SIZE, SQLITE_STATIC);
+ ::sqlite3_bind_text(mSetValueStmt->get(), 2, value, AUTO_DETERM_SIZE, SQLITE_STATIC);
if (::sqlite3_step(mSetValueStmt->get()) != SQLITE_DONE) {
transaction.commit();
}
+void KVStore::setInternal(const std::string& key, const std::string& value)
+{
+ setInternal(key, value.c_str());
+}
+
void KVStore::setInternal(const std::string& key, const std::initializer_list<std::string>& values)
{
setInternal(key, std::vector<std::string>(values));
return value;
}
+char* KVStore::getInternal(const std::string& key, char**)
+{
+ Transaction transaction(*this);
+ ScopedReset scopedReset(mGetValueStmt);
+
+ ::sqlite3_bind_text(mGetValueStmt->get(), 1, key.c_str(), AUTO_DETERM_SIZE, SQLITE_TRANSIENT);
+
+ int ret = ::sqlite3_step(mGetValueStmt->get());
+ if (ret == SQLITE_DONE) {
+ throw ConfigException("No value corresponding to the key: " + key + "@" + mPath);
+ }
+ if (ret != SQLITE_ROW) {
+ throw ConfigException("Error during stepping: " + mConn.getErrorMessage());
+ }
+
+ const char* source = reinterpret_cast<const char*>(sqlite3_column_text(mGetValueStmt->get(), FIRST_COLUMN));
+
+ size_t length = std::strlen(source);
+ char* value = new char[length + 1];
+
+ std::strncpy(value, source, length);
+ value[length] = '\0';
+
+ transaction.commit();
+ return value;
+}
+
std::vector<std::string> KVStore::getInternal(const std::string& key, std::vector<std::string>*)
{
Transaction transaction(*this);
bool mIsTransactionCommited;
void setInternal(const std::string& key, const std::string& value);
+ void setInternal(const std::string& key, const char* value);
void setInternal(const std::string& key, const std::initializer_list<std::string>& values);
void setInternal(const std::string& key, const std::vector<std::string>& values);
template<typename T>
void setInternal(const std::string& key, const std::vector<T>& values);
std::string getInternal(const std::string& key, std::string*);
+ char* getInternal(const std::string& key, char**);
std::vector<std::string> getInternal(const std::string& key, std::vector<std::string>*);
template<typename T>
T getInternal(const std::string& key, T*);
#include "config/types.hpp"
#include <string>
+#include <cstring>
namespace config {
mStore.write(value.c_str(), value.size());
}
+ void writeInternal(const char* &value)
+ {
+ size_t size = std::strlen(value);
+ writeInternal(size);
+ mStore.write(value, size);
+ }
+
void writeInternal(const config::FileDescriptor& fd)
{
mStore.sendFD(fd.value);
void writeInternal(bool value) { add("b", value); };
void writeInternal(double value) { add("d", value); };
void writeInternal(const std::string& value) { add("s", value.c_str()); };
+ void writeInternal(const char* value) { add("s", value); };
void writeInternal(const config::FileDescriptor& value) { add("h", value.value); };
template<typename T>
return json_object_new_string(value.c_str());
}
+ static json_object* toJsonObject(char* value)
+ {
+ return json_object_new_string(value);
+ }
+
template<typename T>
static json_object* toJsonObject(const std::vector<T>& value)
{
std::uint32_t uint32Val;
std::uint64_t uint64Val;
std::string stringVal;
+ char* cstringVal;
double doubleVal;
bool boolVal;
uint32Val,
uint64Val,
stringVal,
+ cstringVal,
doubleVal,
boolVal,
"\"uint32Val\": 123456, "
"\"uint64Val\": 1234567890123456789, "
"\"stringVal\": \"blah\", "
+ "\"cstringVal\": \"blah\", "
"\"doubleVal\": -1.234000, "
"\"boolVal\": true, "
"\"emptyIntVector\": [ ], "
"\"uint32Val\": 0, "
"\"uint64Val\": 0, "
"\"stringVal\": \"\", "
+ "\"cstringVal\": \"\", "
"\"boolVal\": false, "
"\"emptyIntVector\": [ ], "
"\"intVector\": [ ], "
BOOST_CHECK_EQUAL(123456, testConfig.uint32Val);
BOOST_CHECK_EQUAL(1234567890123456789ll, testConfig.uint64Val);
BOOST_CHECK_EQUAL("blah", testConfig.stringVal);
+ BOOST_CHECK_EQUAL("blah", testConfig.cstringVal);
BOOST_CHECK_CLOSE(-1.234, testConfig.doubleVal, TOLERANCE);
BOOST_CHECK_EQUAL(true, testConfig.boolVal);