Add support for config file parsing and watching
[ric-plt/xapp-frame-cpp.git] / src / json / jhash.cpp
index 14a0486..d81c617 100644 (file)
 #include "jwrapper.h"
 #include "jhash.hpp"
 
+
+namespace xapp {
+
+
 // ------------------------------------------------------------------------
 
 
        after which the functions provided by the class can be used to
        suss out the values.
 */
-Jhash::Jhash( const char* jbuf ) :
-       st( jw_new( jbuf ) ),
-       master_st( NULL )
+xapp::Jhash::Jhash( const char* jbuf ) :
+       master_st( NULL ),
+       st( jw_new( jbuf ) )
 { /* empty body */ }
 
-//Jhash::Jhash( Jhash&& soi );                                         // mover
-//Jhash::Jhash& operator=( Jhash&& soi );                      // move operator
+
+/*
+       Move constructor.
+*/
+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;
+}
+
+/*
+       Move Operator.
+*/
+Jhash& Jhash::operator=( Jhash&& soi ) {
+       if( this != &soi ) {                                            // cannot do self assignment
+               master_st = soi.master_st;
+               st = soi.st;
+
+               soi.st = NULL;                                          // prevent closing of RMR stuff on soi destroy
+               soi.master_st = NULL;
+       }
+
+       return *this;
+}
 
 /*
        Blow it away.
 */
-Jhash::~Jhash() {
+xapp::Jhash::~Jhash() {
        if( master_st != NULL ) {               // revert blob set if needed
                st = master_st;
        }
@@ -82,11 +110,11 @@ 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
-               master_st == st;
+               master_st = st;
        }
 
        if( (bst = jw_blob( st, name )) != NULL ) {
@@ -100,15 +128,10 @@ 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;
        }
-/*
- else {
-fprintf( stderr, "bad unset pointer%p  %p\n", master_st, st );
-}
-*/
 }
 
 // ---------------- debugging and sanity checks ---------------------------------------
@@ -119,14 +142,14 @@ fprintf( stderr, "bad unset pointer%p  %p\n", master_st, st );
        Right now we don't have much to work with other than checking for a
        nil table.
 */
-bool Jhash::Parse_errors( ) {
+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 );
 }
 
@@ -136,19 +159,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;
 }
 
@@ -156,19 +179,19 @@ bool Jhash::Is_string( const char* name ) {
        These functions return true if the indicated element in the array
        <name> 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;
 }
 
@@ -177,14 +200,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;
 }
 
@@ -196,9 +219,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;
 }
 
@@ -206,7 +230,7 @@ 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;
 
@@ -222,7 +246,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 );
 }
 
@@ -231,7 +255,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 );
 }
 
@@ -239,7 +263,7 @@ int Jhash::Array_len( const char* name ) {
 /*
        Sets the blob in the array <name>[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 ) {
@@ -256,7 +280,7 @@ bool Jhash::Set_blob_ele( const char* name, int eidx ) {
 /*
        Return the string at index eidx in the array <name>.
 */
-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;
 
@@ -270,14 +294,17 @@ std::string Jhash::String_ele( const char* name, int eidx ) {
 /*
        Return the value at index eidx in the array <name>.
 */
-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 <name>.
 */
-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