21 sprintf(buf,
"%d", value);
51 std::string
Path(
const char* varname)
77 std::string path =
Path(subdir);
79 int status = db_find_key(
fDB, 0, path.c_str(), &hkey);
80 if (status == DB_SUCCESS) {
82 status = db_get_key(
fDB, hkey, &key);
83 if (status != DB_SUCCESS) {
99 status = db_create_key(
fDB, 0, path.c_str(),
TID_KEY);
100 if (status != DB_SUCCESS) {
110 std::string path =
Path(varname);
119 status = db_find_key(
fDB, 0, path.c_str(), &hkey);
120 if (status != DB_SUCCESS)
124 status = db_get_key(
fDB, hkey, &key);
125 if (status != DB_SUCCESS)
129 *num_elements = key.num_values;
132 *element_size = key.item_size;
135 void ReadKey(
const char* varname,
int *tid,
int *num_values,
int *total_size,
int *item_size,
MVOdbError* error)
138 if (num_values) *num_values = 0;
139 if (total_size) *total_size = 0;
140 if (item_size) *item_size = 0;
142 std::string path =
Path(varname);
147 status = db_find_key(
fDB, 0, path.c_str(), &hkey);
148 if (status != DB_SUCCESS) {
154 status = db_get_key(
fDB, hkey, &key);
155 if (status != DB_SUCCESS) {
164 *num_values = key.num_values;
167 *total_size = key.total_size;
170 *item_size = key.item_size;
175 void ReadDir(std::vector<std::string>* varname, std::vector<int> *tid, std::vector<int> *num_values, std::vector<int> *total_size, std::vector<int> *item_size,
MVOdbError* error)
183 std::string path =
Path(varname);
188 status = db_find_key(
fDB, 0, path.c_str(), &hkey);
190 if (status != DB_SUCCESS) {
195 status = db_set_num_values(
fDB, hkey, new_size);
196 if (status != SUCCESS) {
206 std::string path =
Path(varname);
208 int status = db_resize_string(
fDB, 0, path.c_str(), new_size, new_string_length);
209 if (status != SUCCESS) {
217 void R(
const char* varname,
int tid,
void *value,
int size,
bool create,
MVOdbError* error)
220 std::string path =
Path(varname);
221 int status = db_get_value(
fDB, 0, path.c_str(), value, &size, tid, create);
222 if (status != DB_SUCCESS) {
229 void RI(
const char* varname,
int *value,
bool create,
MVOdbError* error)
231 R(varname,
TID_INT, value,
sizeof(
int), create, error);
236 R(varname,
TID_WORD, value,
sizeof(uint16_t), create, error);
241 R(varname,
TID_DWORD, value,
sizeof(uint32_t), create, error);
244 void RD(
const char* varname,
double *value,
bool create,
MVOdbError* error)
246 R(varname,
TID_DOUBLE, value,
sizeof(
double), create, error);
249 void RF(
const char* varname,
float *value,
bool create,
MVOdbError* error)
251 R(varname,
TID_FLOAT, value,
sizeof(
float), create, error);
254 void RB(
const char* varname,
bool *value,
bool create,
MVOdbError* error)
258 R(varname,
TID_BOOL, &v,
sizeof(BOOL), create, error);
262 void RS(
const char* varname, std::string* value,
bool create,
int create_string_length,
MVOdbError* error)
265 std::string path =
Path(varname);
267 #ifdef HAVE_DB_GET_VALUE_STRING_CREATE_STRING_LENGTH
268 int status = db_get_value_string(
fDB, 0, path.c_str(), 0, value, create, create_string_length);
270 #warning This MIDAS has an old version of db_get_value_string() and RS() will ignore the create_string_length argument.
271 int status = db_get_value_string(
fDB, 0, path.c_str(), 0, value, create);
274 if (status != DB_SUCCESS) {
282 void RAI(
const char* varname,
int index,
int tid,
void *value,
int size,
MVOdbError* error)
285 std::string path =
Path(varname);
293 int status = db_get_value(
fDB, 0, path.c_str(), value, &size, tid,
FALSE);
294 if (status != DB_SUCCESS) {
303 RAI(varname, index,
TID_INT, value,
sizeof(
int), error);
308 RAI(varname, index,
TID_WORD, value,
sizeof(uint16_t), error);
313 RAI(varname, index,
TID_DWORD, value,
sizeof(uint32_t), error);
318 RAI(varname, index,
TID_DOUBLE, value,
sizeof(
double), error);
323 RAI(varname, index,
TID_FLOAT, value,
sizeof(
float), error);
330 RAI(varname, index,
TID_BOOL, &v,
sizeof(BOOL), error);
337 std::string path =
Path(varname);
344 int status = db_get_value_string(
fDB, 0, path.c_str(), index, value,
FALSE);
346 if (status != DB_SUCCESS) {
354 void RA(
const std::string& path,
int tid,
void* buf,
int size,
MVOdbError* error)
356 int status = db_get_value(
fDB, 0, path.c_str(), buf, &size, tid,
FALSE);
358 if (status != DB_SUCCESS) {
373 ReadKey(varname, &xtid, pnum_values, &xtotal_size, pitem_size, error);
386 template <
class X>
void RXA(
const char* varname,
int tid, std::vector<X> *value,
bool create,
int create_size,
MVOdbError* error)
388 std::string path =
Path(varname);
396 if (create && create_size > 0) {
397 if (num_values < 0) {
400 W(varname, tid, &v,
sizeof(X), error);
401 if (error && error->
fError)
404 }
else if (num_values != create_size) {
413 if (num_values > 0) {
414 value->resize(num_values);
415 RA(path, tid, &((*value)[0]), num_values*
sizeof(X), error);
424 WA(varname, tid, &((*value)[0]), value->size()*
sizeof(X), value->size(), error);
426 if (error && error->
fError)
429 if (create_size > 0) {
430 if (create_size != (
int)value->size()) {
436 void RIA(
const char* varname, std::vector<int> *value,
bool create,
int create_size,
MVOdbError* error)
438 RXA<int>(varname,
TID_INT, value, create, create_size, error);
441 void RFA(
const char* varname, std::vector<float> *value,
bool create,
int create_size,
MVOdbError* error)
443 RXA<float>(varname,
TID_FLOAT, value, create, create_size, error);
446 void RDA(
const char* varname, std::vector<double> *value,
bool create,
int create_size,
MVOdbError* error)
448 RXA<double>(varname,
TID_DOUBLE, value, create, create_size, error);
451 void RU16A(
const char* varname, std::vector<uint16_t> *value,
bool create,
int create_size,
MVOdbError* error)
453 RXA<uint16_t>(varname,
TID_WORD, value, create, create_size, error);
456 void RU32A(
const char* varname, std::vector<uint32_t> *value,
bool create,
int create_size,
MVOdbError* error)
458 RXA<uint32_t>(varname,
TID_DWORD, value, create, create_size, error);
461 void RBA(
const char* varname, std::vector<bool> *value,
bool create,
int create_size,
MVOdbError* error)
463 std::vector<BOOL> xvalue;
464 std::vector<BOOL> *xvalue_ptr = NULL;
467 for (std::size_t i=0; i<value->size(); i++) {
469 xvalue.push_back(
TRUE);
471 xvalue.push_back(
FALSE);
473 xvalue_ptr = &xvalue;
476 RXA<BOOL>(varname,
TID_BOOL, xvalue_ptr, create, create_size, error);
479 for (std::size_t i=0; i<xvalue.size(); i++) {
481 value->push_back(
true);
483 value->push_back(
false);
488 void RSA(
const char* varname, std::vector<std::string> *value,
bool create,
int create_size,
int create_string_length,
MVOdbError* error)
490 std::string path =
Path(varname);
498 if (create && (create_size > 0) && (create_string_length > 0)) {
499 if (num_values < 0) {
501 WS(varname,
"", create_string_length, error);
502 if (error && error->
fError)
505 }
else if ((num_values != create_size) || (item_size != create_string_length)) {
516 if (num_values > 0) {
518 int bufsize = num_values*item_size;
519 char* buf = (
char*)malloc(bufsize);
521 memset(buf, 0, bufsize);
523 for (
int i=0; i<num_values; i++) {
524 value->push_back(buf+i*item_size);
541 int string_length = 0;
542 for (
size_t i = 0; i < value->size(); i++) {
543 if (((
int)(*value)[i].length()) > string_length)
544 string_length = (*value)[i].length();
548 if (create_string_length > string_length)
549 string_length = create_string_length;
553 int bufsize = value->size()*string_length;
556 buf = (
char*)malloc(bufsize);
558 memset(buf, 0, bufsize);
560 for (
size_t i=0; i<value->size(); i++) {
561 strlcpy(buf+i*string_length, (*value)[i].c_str(), string_length);
565 WA(varname,
TID_STRING, buf, bufsize, value->size(), error);
572 if (error && error->
fError)
575 if ((create_size > 0) && (create_string_length > 0)) {
576 if ((((
int)value->size()) != create_size) || (string_length != create_string_length)) {
583 void W(
const char* varname,
int tid,
const void* v,
int size,
MVOdbError* error)
585 std::string path =
Path(varname);
587 int status = db_set_value(
fDB, 0, path.c_str(), v, size, 1, tid);
589 if (status != DB_SUCCESS) {
600 W(varname,
TID_BOOL, &vv,
sizeof(BOOL), error);
605 W(varname,
TID_INT, &v,
sizeof(
int), error);
610 W(varname,
TID_WORD, &v,
sizeof(uint16_t), error);
615 W(varname,
TID_DWORD, &v,
sizeof(uint32_t), error);
625 W(varname,
TID_FLOAT, &v,
sizeof(
float), error);
628 void WS(
const char* varname,
const char* v,
int string_length,
MVOdbError* error)
630 if (string_length > 0) {
631 char* buf = (
char*)malloc(string_length);
633 strlcpy(buf, v, string_length);
642 void WAI(
const char* varname,
int index,
int tid,
const void* v,
int size,
MVOdbError* error)
644 std::string path =
Path(varname);
656 status = db_find_key(
fDB, 0, path.c_str(), &hkey);
658 if (status != DB_SUCCESS) {
663 status = db_set_data_index(
fDB, hkey, v, size, index, tid);
665 if (status != DB_SUCCESS) {
676 WAI(varname, index,
TID_BOOL, &vv,
sizeof(BOOL), error);
681 WAI(varname, index,
TID_INT, &v,
sizeof(
int), error);
686 WAI(varname, index,
TID_WORD, &v,
sizeof(uint16_t), error);
691 WAI(varname, index,
TID_DWORD, &v,
sizeof(uint32_t), error);
701 WAI(varname, index,
TID_FLOAT, &v,
sizeof(
float), error);
706 int num_elements = 0;
707 int element_size = 0;
708 RAInfo(varname, &num_elements, &element_size, error);
709 if (error && error->
fError)
711 if (element_size <= 0)
713 char* buf = (
char*)malloc(element_size);
720 void WA(
const char* varname,
int tid,
const void* v,
int size,
int count,
MVOdbError* error)
722 std::string path =
Path(varname);
727 int status = db_create_key(
fDB, 0, path.c_str(), tid);
729 if (status != DB_SUCCESS) {
734 int status = db_set_value(
fDB, 0, path.c_str(), v, size, count, tid);
738 if (status != DB_SUCCESS) {
747 void WBA(
const char* varname,
const std::vector<bool>& v,
MVOdbError* error)
749 unsigned num = v.size();
752 for (
unsigned i=0; i<num; i++) {
756 WA(varname,
TID_BOOL, val, num*
sizeof(BOOL), num, error);
761 WA(varname,
TID_WORD, &v[0], v.size()*
sizeof(uint16_t), v.size(), error);
766 WA(varname,
TID_DWORD, &v[0], v.size()*
sizeof(uint32_t), v.size(), error);
771 WA(varname,
TID_INT, &v[0], v.size()*
sizeof(
int), v.size(), error);
774 void WFA(
const char* varname,
const std::vector<float>& v,
MVOdbError* error)
776 WA(varname,
TID_FLOAT, &v[0], v.size()*
sizeof(
float), v.size(), error);
779 void WDA(
const char* varname,
const std::vector<double>& v,
MVOdbError* error)
781 WA(varname,
TID_DOUBLE, &v[0], v.size()*
sizeof(
double), v.size(), error);
784 void WSA(
const char* varname,
const std::vector<std::string>& v,
int odb_string_size,
MVOdbError* error)
786 unsigned num = v.size();
787 unsigned length = odb_string_size;
790 for (
unsigned i=0; i<v.size(); i++) {
791 if (v[i].length() > length)
792 length = v[i].length();
797 char val[length*num];
798 memset(val, 0, length*num);
800 for (
unsigned i=0; i<num; i++)
801 strlcpy(val+length*i, v[i].c_str(), length);
808 std::string path =
Path(odbname);
813 int status = db_find_key(
fDB, 0, path.c_str(), &hKey);
815 if (status == DB_NO_KEY) {
820 if (status != DB_SUCCESS) {
825 status = db_delete_key(
fDB, hKey,
FALSE);
827 if (status != DB_SUCCESS) {
void RIA(const char *varname, std::vector< int > *value, bool create, int create_size, MVOdbError *error)
void WU16(const char *varname, uint16_t v, MVOdbError *error)
bool GetPrintError() const
void SetPrintError(bool v)
void WU16AI(const char *varname, int index, uint16_t v, MVOdbError *error)
void RD(const char *varname, double *value, bool create, MVOdbError *error)
void RF(const char *varname, float *value, bool create, MVOdbError *error)
void RA(const std::string &path, int tid, void *buf, int size, MVOdbError *error)
void WIAI(const char *varname, int index, int v, MVOdbError *error)
MidasOdb(HNDLE hDB, const char *root)
void W(const char *varname, int tid, const void *v, int size, MVOdbError *error)
void R(const char *varname, int tid, void *value, int size, bool create, MVOdbError *error)
void RIAI(const char *varname, int index, int *value, MVOdbError *error)
void RFAI(const char *varname, int index, float *value, MVOdbError *error)
void ResizeStringArray(const char *varname, int new_size, int new_string_length, MVOdbError *error)
void RSA(const char *varname, std::vector< std::string > *value, bool create, int create_size, int create_string_length, MVOdbError *error)
void RAInfo(const char *varname, int *num_elements, int *element_size, MVOdbError *error)
void GetArraySize(const char *varname, int *pnum_values, int *pitem_size, MVOdbError *error)
void WU32(const char *varname, uint32_t v, MVOdbError *error)
void RDA(const char *varname, std::vector< double > *value, bool create, int create_size, MVOdbError *error)
void RB(const char *varname, bool *value, bool create, MVOdbError *error)
void WDA(const char *varname, const std::vector< double > &v, MVOdbError *error)
void RSAI(const char *varname, int index, std::string *value, MVOdbError *error)
void WIA(const char *varname, const std::vector< int > &v, MVOdbError *error)
void RU32AI(const char *varname, int index, uint32_t *value, MVOdbError *error)
void RAI(const char *varname, int index, int tid, void *value, int size, MVOdbError *error)
std::string Path(const char *varname)
void WI(const char *varname, int v, MVOdbError *error)
void WS(const char *varname, const char *v, int string_length, MVOdbError *error)
void RI(const char *varname, int *value, bool create, MVOdbError *error)
void RU32A(const char *varname, std::vector< uint32_t > *value, bool create, int create_size, MVOdbError *error)
void WSA(const char *varname, const std::vector< std::string > &v, int odb_string_size, MVOdbError *error)
void ResizeArray(const char *varname, int new_size, MVOdbError *error)
void RDAI(const char *varname, int index, double *value, MVOdbError *error)
void WBAI(const char *varname, int index, bool v, MVOdbError *error)
void RBA(const char *varname, std::vector< bool > *value, bool create, int create_size, MVOdbError *error)
void RFA(const char *varname, std::vector< float > *value, bool create, int create_size, MVOdbError *error)
void Delete(const char *odbname, MVOdbError *error)
void WB(const char *varname, bool v, MVOdbError *error)
void WU16A(const char *varname, const std::vector< uint16_t > &v, MVOdbError *error)
void ReadKey(const char *varname, int *tid, int *num_values, int *total_size, int *item_size, MVOdbError *error)
MVOdb * Chdir(const char *subdir, bool create, MVOdbError *error)
void WDAI(const char *varname, int index, double v, MVOdbError *error)
void WBA(const char *varname, const std::vector< bool > &v, MVOdbError *error)
void ReadDir(std::vector< std::string > *varname, std::vector< int > *tid, std::vector< int > *num_values, std::vector< int > *total_size, std::vector< int > *item_size, MVOdbError *error)
void RU16A(const char *varname, std::vector< uint16_t > *value, bool create, int create_size, MVOdbError *error)
void RU16(const char *varname, uint16_t *value, bool create, MVOdbError *error)
void WU32A(const char *varname, const std::vector< uint32_t > &v, MVOdbError *error)
void WFA(const char *varname, const std::vector< float > &v, MVOdbError *error)
void WD(const char *varname, double v, MVOdbError *error)
void WSAI(const char *varname, int index, const char *v, MVOdbError *error)
void RS(const char *varname, std::string *value, bool create, int create_string_length, MVOdbError *error)
void RBAI(const char *varname, int index, bool *value, MVOdbError *error)
void WU32AI(const char *varname, int index, uint32_t v, MVOdbError *error)
void RU16AI(const char *varname, int index, uint16_t *value, MVOdbError *error)
void WF(const char *varname, float v, MVOdbError *error)
void RU32(const char *varname, uint32_t *value, bool create, MVOdbError *error)
void WA(const char *varname, int tid, const void *v, int size, int count, MVOdbError *error)
void WAI(const char *varname, int index, int tid, const void *v, int size, MVOdbError *error)
void WFAI(const char *varname, int index, float v, MVOdbError *error)
void RXA(const char *varname, int tid, std::vector< X > *value, bool create, int create_size, MVOdbError *error)
void SetMidasStatus(MVOdbError *error, bool print, const std::string &path, const char *midas_func_name, int status)
void SetError(MVOdbError *error, bool print, const std::string &path, const std::string &message)
void SetOk(MVOdbError *error)
size_t EXPRT strlcpy(char *dst, const char *src, size_t size)
MVOdb * MakeMidasOdb(int hDB, MVOdbError *error)
static std::string toString(int value)