#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 ) :
- master_st( NULL ),
+xapp::Jhash::Jhash( const char* jbuf ) :
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;
}
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 ) {
/*
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 ---------------------------------------
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 );
}
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;
}
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;
}
/*
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;
}
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;
}
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 );
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 );
}
/*
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 );
}
/*
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 ) {
/*
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;
+ const char* hashv;
if( (hashv = jw_string_ele( st, name, eidx )) != NULL ) {
rv = std::string( hashv );
/*
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