PISM, A Parallel Ice Sheet Model  stable v2.1.1 committed by Constantine Khrulev on 2024-12-04 13:36:58 -0900
ConfigJSON.hh
Go to the documentation of this file.
1 /* Copyright (C) 2014, 2016, 2017, 2018 PISM Authors
2  *
3  * This file is part of PISM.
4  *
5  * PISM is free software; you can redistribute it and/or modify it under the
6  * terms of the GNU General Public License as published by the Free Software
7  * Foundation; either version 3 of the License, or (at your option) any later
8  * version.
9  *
10  * PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with PISM; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #ifndef _CONFIGJSON_H_
21 #define _CONFIGJSON_H_
22 
23 #include <jansson.h>
24 
25 #include "pism/util/Config.hh"
26 
27 namespace pism {
28 
29 /*! @brief The JSON-based Config implementation.
30  *
31  */
32 class ConfigJSON : public Config {
33 public:
34  ConfigJSON(units::System::Ptr unit_system);
35  virtual ~ConfigJSON();
36 
37  void init_from_file(const std::string &filename);
38  void init_from_string(const std::string &string);
39  std::string dump() const;
40 
41 private:
42  virtual void read_impl(const File &nc);
43  virtual void write_impl(const File &nc) const;
44 
45  virtual bool is_set_impl(const std::string &name) const;
46 
47  virtual Doubles all_doubles_impl() const;
48  virtual double get_number_impl(const std::string &name) const;
49  virtual std::vector<double> get_numbers_impl(const std::string &name) const;
50 
51  virtual void set_number_impl(const std::string &name, double value);
52  virtual void set_numbers_impl(const std::string &name,
53  const std::vector<double> &values);
54 
55  virtual Strings all_strings_impl() const;
56  virtual std::string get_string_impl(const std::string &name) const;
57  virtual void set_string_impl(const std::string &name, const std::string &value);
58 
59  virtual Flags all_flags_impl() const;
60 
61  virtual bool get_flag_impl(const std::string& name) const;
62  virtual void set_flag_impl(const std::string& name, bool value);
63 private:
64  json_t *m_data;
65 };
66 
67 } // end of namespace pism
68 
69 #endif /* _CONFIGJSON_H_ */
virtual Flags all_flags_impl() const
Definition: ConfigJSON.cc:299
virtual std::string get_string_impl(const std::string &name) const
Definition: ConfigJSON.cc:338
virtual std::vector< double > get_numbers_impl(const std::string &name) const
Definition: ConfigJSON.cc:327
virtual double get_number_impl(const std::string &name) const
Definition: ConfigJSON.cc:323
virtual Doubles all_doubles_impl() const
Definition: ConfigJSON.cc:278
virtual void set_number_impl(const std::string &name, double value)
Definition: ConfigJSON.cc:306
virtual void read_impl(const File &nc)
Definition: ConfigJSON.cc:346
void init_from_file(const std::string &filename)
Definition: ConfigJSON.cc:229
std::string dump() const
Definition: ConfigJSON.cc:266
json_t * m_data
Definition: ConfigJSON.hh:64
virtual void set_flag_impl(const std::string &name, bool value)
Definition: ConfigJSON.cc:315
void init_from_string(const std::string &string)
Definition: ConfigJSON.cc:248
virtual void set_string_impl(const std::string &name, const std::string &value)
Definition: ConfigJSON.cc:319
virtual ~ConfigJSON()
Definition: ConfigJSON.cc:223
virtual bool is_set_impl(const std::string &name) const
Definition: ConfigJSON.cc:355
virtual void set_numbers_impl(const std::string &name, const std::vector< double > &values)
Definition: ConfigJSON.cc:310
ConfigJSON(units::System::Ptr unit_system)
Definition: ConfigJSON.cc:217
virtual void write_impl(const File &nc) const
Definition: ConfigJSON.cc:351
virtual Strings all_strings_impl() const
Definition: ConfigJSON.cc:293
virtual bool get_flag_impl(const std::string &name) const
Definition: ConfigJSON.cc:342
The JSON-based Config implementation.
Definition: ConfigJSON.hh:32
std::map< std::string, std::string > Strings
std::map< std::string, std::vector< double > > Doubles
std::map< std::string, bool > Flags
std::string filename() const
Returns the name of the file used to initialize the database.
A class for storing and accessing PISM configuration flags and parameters.
High-level PISM I/O class.
Definition: File.hh:56
std::shared_ptr< System > Ptr
Definition: Units.hh:47