X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fjson%2Fjhash.cpp;h=25efc4583abd9e5488ba5a34a86feac7677d3fa2;hb=555fc14abec797f96cd4c03bf997ce3711984393;hp=ad0bd9c15354088215f23bf75544c2edd5ad8878;hpb=8ec1e3c2dec6ba4fa83fe63e4207d47b4b0f3b3f;p=ric-plt%2Fxapp-frame-cpp.git diff --git a/src/json/jhash.cpp b/src/json/jhash.cpp index ad0bd9c..25efc45 100644 --- a/src/json/jhash.cpp +++ b/src/json/jhash.cpp @@ -34,6 +34,10 @@ #include "jwrapper.h" #include "jhash.hpp" + +namespace xapp { + + // ------------------------------------------------------------------------ @@ -44,8 +48,7 @@ after which the functions provided by the class can be used to suss out the values. */ -Jhash::Jhash( const char* jbuf ) : - master_st( NULL ), +xapp::Jhash::Jhash( const char* jbuf ) : st( jw_new( jbuf ) ) { /* empty body */ } @@ -53,10 +56,10 @@ Jhash::Jhash( const char* jbuf ) : /* Move constructor. */ -Jhash::Jhash( Jhash&& soi ) { - master_st = soi.master_st; - st = soi.st; - +Jhash::Jhash( Jhash&& soi ) : + master_st( soi.master_st ), + st( soi.st ) +{ soi.st = NULL; // prevent closing of RMR stuff on soi destroy soi.master_st = NULL; } @@ -79,7 +82,7 @@ Jhash& Jhash::operator=( Jhash&& soi ) { /* Blow it away. */ -Jhash::~Jhash() { +xapp::Jhash::~Jhash() { if( master_st != NULL ) { // revert blob set if needed st = master_st; } @@ -106,7 +109,7 @@ Jhash::~Jhash() { overlays with the named root; unset needs only to be called to return to the top level. */ -bool Jhash::Set_blob( const char* name ) { +bool xapp::Jhash::Set_blob( const char* name ) { void* bst; // blob symbol table if( master_st == NULL ) { // must capture master @@ -124,7 +127,7 @@ bool Jhash::Set_blob( const char* name ) { /* Return the suss root (blob root) to the root of the symtab. */ -void Jhash::Unset_blob( ) { +void xapp::Jhash::Unset_blob( ) { if( master_st != NULL ) { st = master_st; } @@ -138,14 +141,14 @@ void Jhash::Unset_blob( ) { Right now we don't have much to work with other than checking for a nil table. */ -bool Jhash::Parse_errors( ) { +const bool xapp::Jhash::Parse_errors( ) { return st == NULL; } /* Dump the selected blob as much as we can. */ -void Jhash::Dump() { +void xapp::Jhash::Dump() { jw_dump( st ); } @@ -155,19 +158,19 @@ void Jhash::Dump() { These funcitons return true if the named object in the current blob is the indicated type */ -bool Jhash::Is_value( const char* name ) { +bool xapp::Jhash::Is_value( const char* name ) { return jw_is_value( st, name ) == 1; } -bool Jhash::Is_bool( const char* name ) { +bool xapp::Jhash::Is_bool( const char* name ) { return jw_is_bool( st, name ) == 1; } -bool Jhash::Is_null( const char* name ) { +bool xapp::Jhash::Is_null( const char* name ) { return jw_is_null( st, name ) == 1; } -bool Jhash::Is_string( const char* name ) { +bool xapp::Jhash::Is_string( const char* name ) { return jw_is_string( st, name ) == 1; } @@ -175,19 +178,19 @@ bool Jhash::Is_string( const char* name ) { These functions return true if the indicated element in the array is the indicated type. */ -bool Jhash::Is_string_ele( const char* name, int eidx ) { +bool xapp::Jhash::Is_string_ele( const char* name, int eidx ) { return jw_is_string_ele( st, name, eidx ) == 1; } -bool Jhash::Is_value_ele( const char* name, int eidx ) { +bool xapp::Jhash::Is_value_ele( const char* name, int eidx ) { return jw_is_value_ele( st, name, eidx ) == 1; } -bool Jhash::Is_bool_ele( const char* name, int eidx ) { +bool xapp::Jhash::Is_bool_ele( const char* name, int eidx ) { return jw_is_bool_ele( st, name, eidx ) == 1; } -bool Jhash::Is_null_ele( const char* name, int eidx ) { +bool xapp::Jhash::Is_null_ele( const char* name, int eidx ) { return jw_is_null_ele( st, name, eidx ) == 1; } @@ -196,14 +199,14 @@ bool Jhash::Is_null_ele( const char* name, int eidx ) { /* Returns true if the named element is in the hash. */ -bool Jhash::Exists( const char* name ) { +bool xapp::Jhash::Exists( const char* name ) { return jw_exists( st, name ) == 1; } /* Returns true if the named element is not in the hash. */ -bool Jhash::Is_missing( const char* name ) { +bool xapp::Jhash::Is_missing( const char* name ) { return jw_missing( st, name ) == 1; } @@ -215,9 +218,10 @@ bool Jhash::Is_missing( const char* name ) { Symtab saves bool values as 1 for true and doesn't provide a bool fetch function. So, fetch the value and return true if it is 1. */ -bool Jhash::Bool( const char* name ) { +bool xapp::Jhash::Bool( const char* name ) { int v; v = (int) jw_value( st, name ); + return v == 1; } @@ -225,9 +229,9 @@ bool Jhash::Bool( const char* name ) { Returns a C++ string to the named object; If the element is not in the hash an empty string is returned. */ -std::string Jhash::String( const char* name ) { +std::string xapp::Jhash::String( const char* name ) { std::string rv = ""; - char* hashv; + const char* hashv; if( (hashv = jw_string( st, name )) != NULL ) { rv = std::string( hashv ); @@ -241,7 +245,7 @@ std::string Jhash::String( const char* name ) { Returns the value assocated with the named object; If the element is not in the hash 0 is returned. */ -double Jhash::Value( const char* name ) { +double xapp::Jhash::Value( const char* name ) { return jw_value( st, name ); } @@ -250,7 +254,7 @@ double Jhash::Value( const char* name ) { /* Return the length of the named array, or -1 if it doesn't exist. */ -int Jhash::Array_len( const char* name ) { +int xapp::Jhash::Array_len( const char* name ) { return jw_array_len( st, name ); } @@ -258,7 +262,7 @@ int Jhash::Array_len( const char* name ) { /* Sets the blob in the array [eidx] to the current reference blob. */ -bool Jhash::Set_blob_ele( const char* name, int eidx ) { +bool xapp::Jhash::Set_blob_ele( const char* name, int eidx ) { void* bst; if( (bst = jw_obj_ele( st, name, eidx )) != NULL ) { @@ -275,9 +279,9 @@ bool Jhash::Set_blob_ele( const char* name, int eidx ) { /* Return the string at index eidx in the array . */ -std::string Jhash::String_ele( const char* name, int eidx ) { +std::string xapp::Jhash::String_ele( const char* name, int eidx ) { std::string rv = ""; - char* hashv; + const char* hashv; if( (hashv = jw_string_ele( st, name, eidx )) != NULL ) { rv = std::string( hashv ); @@ -289,14 +293,17 @@ std::string Jhash::String_ele( const char* name, int eidx ) { /* Return the value at index eidx in the array . */ -double Jhash::Value_ele( const char* name, int eidx ) { +double xapp::Jhash::Value_ele( const char* name, int eidx ) { return jw_value_ele( st, name, eidx ); } /* Return the bool value at index eidx in the array . */ -bool Jhash::Bool_ele( const char* name, int eidx ) { +bool xapp::Jhash::Bool_ele( const char* name, int eidx ) { return jw_bool_ele( st, name, eidx ) == 1; } + + +} // namespace