HIPO  4.3.0
High Performance Output data format for experimental physics
jsonutil.h
Go to the documentation of this file.
1 //******************************************************************************
2 //* ██╗ ██╗██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ *
3 //* ██║ ██║██║██╔══██╗██╔═══██╗ ██║ ██║ ██╔═████╗ *
4 //* ███████║██║██████╔╝██║ ██║ ███████║ ██║██╔██║ *
5 //* ██╔══██║██║██╔═══╝ ██║ ██║ ╚════██║ ████╔╝██║ *
6 //* ██║ ██║██║██║ ╚██████╔╝ ██║██╗╚██████╔╝ *
7 //* ╚═╝ ╚═╝╚═╝╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═════╝ *
8 //************************ Jefferson National Lab (2017) ***********************
9 /*
10  * Copyright (c) 2017. Jefferson Lab (JLab). All rights reserved. Permission
11  * to use, copy, modify, and distribute this software and its documentation
12  * for educational, research, and not-for-profit purposes, without fee and
13  * without a signed licensing agreement.
14  *
15  * IN NO EVENT SHALL JLAB BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL
16  * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
17  * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JLAB HAS
18  * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19  *
20  * JLAB SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE. THE HIPO DATA FORMAT SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF
23  * ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". JLAB HAS NO OBLIGATION TO
24  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25  *
26  * This software was developed under the United States Government license.
27  * For more information contact author at gavalian@jlab.org
28  * Department of Experimental Nuclear Physics, Jefferson Lab.
29  */
32 
33 /*******************************************************************************
34  * File: jsonutil.h
35  * Author: gavalian
36  *
37  * Created on April 12, 2017, 10:14 AM
38  */
39 
40 #ifndef HIPO_JSON_H
41 #define HIPO_JSON_H
42 
43 #include <map>
44 #include "json.h"
45 
46 namespace hipo {
47 
49 
51 
57 class jsonutil {
58 
59 private:
60 
61  json json_object;
62 
63 public:
64 
65  jsonutil(){};
66  virtual ~jsonutil(){};
67 
70  void set(const char *json_string){ json_object = json::parse(json_string);}
74  bool hasObject(const char *var){ return json_object.count(var)>0;}
78  float getFloat(const char *var){ return (float) json_object[var];}
79 };
80 
81 } // end of namespace
82 
83 #endif /*HIPO_TABLE_H*/
84 
Simple JSON parsing and value extraction utility.
Definition: jsonutil.h:57
virtual ~jsonutil()
Definition: jsonutil.h:66
void set(const char *json_string)
Parse a JSON string into the internal object.
Definition: jsonutil.h:70
bool hasObject(const char *var)
Check whether a key exists in the parsed JSON.
Definition: jsonutil.h:74
float getFloat(const char *var)
Get a float value by key from the parsed JSON.
Definition: jsonutil.h:78
Definition: bank.cpp:47
nlohmann::json json
Definition: jsonutil.h:48