> For the complete documentation index, see [llms.txt](https://sandbox-docs.verifone.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sandbox-docs.verifone.com/adk-5.0-programmers-guide/ipc_2src_2ipc_2jsobject_8h_source.md).

# jsobject.h

[Go to the documentation of this file.](/adk-5.0-programmers-guide/readme/files/dir_9ae62d232e1f8555f5337bbbbe2033a3/dir_a8642344d1890ac34080367e6f4e78c5/dir_752e238688bdca1ec54f409b1533470c/ipc_2src_2ipc_2jsobject_8h.md)

```cpp
 1 
 2 #ifndef IPC_JSOBJECT_H_150611
 3 #define IPC_JSOBJECT_H_150611
 4 
 9 #include <string>
 10 #include <map>
 11 #include <vector>
 12 #include <limits.h>
 13 
 14 #if defined _WIN32 && defined VFI_IPC_SHARED_EXPORT
 15 # define DllSpec __declspec(dllexport)
 16 #elif defined __GNUC__ && defined VFI_IPC_SHARED_EXPORT
 17 # define DllSpec __attribute__((visibility ("default")))
 18 #else
 19 # define DllSpec
 20 #endif
 21 
 22 namespace vfiipc {
 23 #if 0
 24 } // for automatic indentation
 25 #endif
 26 
 28 class DllSpec JSObject {
 29 
 30  public:
 32  enum JSType {
 33  JSTNull,
 34  JSTBool,
 35  JSTString,
 36  JSTInt,
 37  JSTFloat,
 38  JSTObject,
 39  JSTArray
 40  };
 41 
 42  protected:
 43  JSType v_type;
 44  bool v_bool;
 45  std::string v_string;
 46  double v_floatnum;
 47  long v_intnum;
 48  std::map<std::string,JSObject> v_object;
 49  std::vector<JSObject> v_array;
 50 
 51  static JSObject NullObject;
 52 
 53  int parse(const char *s);
 54  int parse(const char *s, unsigned nestinglevel);
 55 
 56  void dump(std::string &s,bool (*filter_cb)(const std::string &key)) const;
 57  void prettyDump(std::string &out, int indent) const;
 58 
 59  public:
 60 
 62  JSObject() { v_type=JSTNull; }
 63 
 65  JSType type() const { return v_type; }
 66 
 68  bool isNull() const { return v_type==JSTNull; }
 69 
 71  bool isBool() const { return v_type==JSTBool; }
 72 
 74  bool isString() const { return v_type==JSTString; }
 75 
 77  bool isNumber() const { return v_type==JSTFloat || v_type==JSTInt; }
 78 
 80  bool isObject() const { return v_type==JSTObject; }
 81 
 83  bool isArray() const { return v_type==JSTArray; }
 84 
 86  std::string getString() const;
 87 
 89  std::string getString(const char *defaultval) const { return isNull() ? defaultval : getString(); }
 90 
 95  const std::string *getStringP() const;
 96 
 101  std::string *getStringP();
 102 
 104  double getNumber() const;
 105 
 107  long getInt() const;
 108 
 110  long long getInt64() const;
 111 
 113  bool getBool() const;
 114 
 116  operator bool() const { return getBool(); }
 117 
 119  operator std::string() const { return getString(); }
 120 
 122  operator char() const { return (char)getInt(); }
 123 
 125  operator unsigned char() const { return (unsigned char)getInt(); }
 126 
 128  operator short() const { return (short)getInt(); }
 129 
 131  operator unsigned short() const { return (unsigned short)getInt();}
 132 
 134  operator int() const { return (int)getInt(); }
 135 
 137  operator unsigned() const { return (unsigned)getInt(); }
 138 
 140  operator long() const { return (long)getInt(); }
 141 
 143  operator unsigned long() const { return (unsigned long)getInt(); }
 144 
 146  operator long long() const { return (long long)getInt64(); }
 147 
 149  operator unsigned long long() const { return (unsigned long long)getInt64(); }
 150 
 152  operator float() const { return (float)getNumber(); }
 153 
 155  operator double() const { return (double)getNumber(); }
 156 
 158  void clear() { v_type=JSTNull; v_string.clear(); v_object.clear(); v_array.clear(); }
 159 
 162  JSObject &clearObject() { clear(); v_type=JSTObject; return *this; }
 163 
 165  JSObject &operator=(bool val) { v_type=JSTBool; v_bool=val; return *this; }
 166 
 168  JSObject &operator=(char *val) { v_type=JSTString; v_string=val?val:""; return *this; }
 169 
 171  JSObject &operator=(const char *val) { v_type=JSTString; v_string=val?val:""; return *this; }
 172 
 174  JSObject &operator=(const std::string &val) { v_type=JSTString; v_string=val; return *this; }
 175 
 177  JSObject &operator=(double val) { v_type=JSTFloat; v_floatnum=val; return *this; }
 178 
 180  JSObject &operator=(float val) { v_type=JSTFloat; v_floatnum=val; return *this; }
 181 
 183  JSObject &operator=(long long val) {
 184  if(val>LONG_MAX || val<LONG_MIN) {v_type=JSTFloat; v_floatnum=(double)val;}
 185  else {v_type=JSTInt; v_intnum=(long)val;}
 186  return *this;
 187  }
 188 
 190  JSObject &operator=(unsigned long long val) {
 191  if(val>LONG_MAX) {v_type=JSTFloat; v_floatnum=(double)val;}
 192  else {v_type=JSTInt; v_intnum=(long)val;}
 193  return *this;
 194  }
 195 
 197  template<typename T> JSObject &operator=(T val) { v_type=JSTInt; v_intnum=val; return *this; }
 198 
 202  bool exists(const char *elem) const;
 203 
 207  bool exists(const std::string &elem) const;
 208 
 210  void erase(const char *elem);
 211 
 213  void erase(const std::string &elem);
 214 
 219  JSObject &operator()(const char *elem);
 220 
 225  const JSObject &operator()(const char *elem) const;
 226 
 231  JSObject &operator()(const std::string &elem);
 232 
 237  const JSObject &operator()(const std::string &elem) const;
 238 
 243  JSObject &operator[](int idx);
 244 
 249  const JSObject &operator[](int idx) const;
 250 
 253  unsigned size() const { return v_type==JSTArray?(unsigned)v_array.size():0; }
 254 
 259  void resize(unsigned new_size);
 260 
 266  typedef std::map<std::string,JSObject>::iterator iterator;
 267  typedef std::map<std::string,JSObject>::const_iterator const_iterator;
 268 
 270  iterator begin() { return v_object.begin(); }
 271 
 273  iterator end() { return v_object.end(); }
 274 
 276  const_iterator begin() const { return v_object.begin(); }
 277 
 279  const_iterator end() const { return v_object.end(); }
 280 
 284  bool load(const std::string &s) { return parse(s.c_str())==(int)s.length(); }
 285 
 289  std::string dump() const;
 290 
 294  void dump(std::string &s) const;
 295 
 299  void swap(JSObject &o);
 300 
 301 
 306  std::string logdump(bool (*filter_cb)(const std::string &key)) const;
 307 
 311  void prettyDump(std::string &s) const;
 312 
 315  static const char *getVersion();
 316 };
 317 
 318 } // namespace vfiipc
 319 
 320 #undef DllSpec
 321 
 323 #endif
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sandbox-docs.verifone.com/adk-5.0-programmers-guide/ipc_2src_2ipc_2jsobject_8h_source.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
