E. Scott Daniels | 97204c8 | 2020-06-29 15:39:57 -0400 | [diff] [blame] | 1 | // vi: ts=4 sw=4 noet: |
| 2 | /* |
| 3 | ================================================================================== |
| 4 | Copyright (c) 2020 Nokia |
| 5 | Copyright (c) 2020 AT&T Intellectual Property. |
| 6 | |
| 7 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | you may not use this file except in compliance with the License. |
| 9 | You may obtain a copy of the License at |
| 10 | |
| 11 | http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | |
| 13 | Unless required by applicable law or agreed to in writing, software |
| 14 | distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | See the License for the specific language governing permissions and |
| 17 | limitations under the License. |
| 18 | ================================================================================== |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | Mnemonic: jhash.hpp |
| 23 | Abstract: This class provides the ability to parse a json string into |
| 24 | a hashtable, and exposes various functions that can be used |
| 25 | to read the data from the hash. |
| 26 | |
| 27 | Date: 26 June 2020 |
| 28 | Author: E. Scott Daniels |
| 29 | */ |
| 30 | |
| 31 | #ifndef _JHASH_HPP |
| 32 | #define _JHASH_HPP |
| 33 | |
| 34 | |
| 35 | #include <string> |
| 36 | |
E. Scott Daniels | 6ef23e1 | 2020-07-15 08:03:22 -0400 | [diff] [blame^] | 37 | namespace xapp { |
| 38 | |
E. Scott Daniels | 97204c8 | 2020-06-29 15:39:57 -0400 | [diff] [blame] | 39 | // ------------------------------------------------------------------------ |
| 40 | |
| 41 | class Jhash { |
| 42 | private: |
| 43 | void* st; // the resulting symbol table generated by parse |
| 44 | void* master_st; // if user switches to a sub-blob; this tracks the original root st |
| 45 | |
| 46 | Jhash& operator=( const Jhash& soi ); // jhashes cannot be copied because of underlying symbol table goo |
| 47 | Jhash( const Jhash& soi ); |
| 48 | |
| 49 | public: |
| 50 | |
| 51 | Jhash( const char* jblob ); // builder |
E. Scott Daniels | 8ec1e3c | 2020-07-14 13:38:27 -0400 | [diff] [blame] | 52 | Jhash( Jhash&& soi ); // mover |
| 53 | Jhash& operator=( Jhash&& soi ); // move operator |
E. Scott Daniels | 97204c8 | 2020-06-29 15:39:57 -0400 | [diff] [blame] | 54 | ~Jhash(); // destruction |
| 55 | |
| 56 | bool Set_blob( const char* name ); // blob/root selection |
| 57 | void Unset_blob( ); |
| 58 | bool Set_blob_ele( const char* name, int eidx ); // set from an array element |
| 59 | |
| 60 | bool Parse_errors( ); |
| 61 | void Dump(); |
| 62 | |
| 63 | std::string String( const char* name ); // value fetching |
| 64 | double Value( const char* name ); |
| 65 | bool Bool( const char* name ); |
| 66 | |
| 67 | bool Exists( const char* name ); // presence checking |
| 68 | bool Is_missing( const char* name ); |
| 69 | |
| 70 | bool Is_bool( const char* name ); // type checking functions |
| 71 | bool Is_null( const char* name ); |
| 72 | bool Is_string( const char* name ); |
| 73 | bool Is_value( const char* name ); |
| 74 | |
| 75 | int Array_len( const char* name ); |
| 76 | |
| 77 | bool Is_bool_ele( const char* name, int eidx ); // type of array element checks |
| 78 | bool Is_null_ele( const char* name, int eidx ); |
| 79 | bool Is_string_ele( const char* name, int eidx ); |
| 80 | bool Is_value_ele( const char* name, int eidx ); |
| 81 | |
| 82 | bool Bool_ele( const char* name, int eidx ); // array oriented sussing functions |
| 83 | std::string String_ele( const char* name, int eidx ); |
| 84 | double Value_ele( const char* name, int eidx ); |
| 85 | }; |
| 86 | |
| 87 | |
E. Scott Daniels | 6ef23e1 | 2020-07-15 08:03:22 -0400 | [diff] [blame^] | 88 | |
| 89 | } // namespace |
E. Scott Daniels | 97204c8 | 2020-06-29 15:39:57 -0400 | [diff] [blame] | 90 | #endif |