RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
ParamHandler.h
1/***********************************************************************
2 * The rDock program was developed from 1998 - 2006 by the software team
3 * at RiboTargets (subsequently Vernalis (R&D) Ltd).
4 * In 2006, the software was licensed to the University of York for
5 * maintenance and distribution.
6 * In 2012, Vernalis and the University of York agreed to release the
7 * program as Open Source software.
8 * This version is licensed under GNU-LGPL version 3.0 with support from
9 * the University of Barcelona.
10 * http://rdock.sourceforge.net/
11 ***********************************************************************/
12
13// Base implementation class for managing a collection of named parameters
14// Any class requiring parameter handling can derive from ParamHandler
15// Parameters are stored as Variants (double, string or stringlist)
16// Only derived classes can add and delete parameters from the collection
17
18#ifndef _RBTPARAMHANDLER_H_
19#define _RBTPARAMHANDLER_H_
20
21#include "rxdock/Config.h"
22#include "rxdock/Variant.h"
23
24#include <nlohmann/json.hpp>
25
26using json = nlohmann::json;
27
28namespace rxdock {
29
31public:
33 // Constructors/destructors
34 virtual ~ParamHandler(); // Default destructor
35
36 friend void to_json(json &j, const ParamHandler &paramHandler);
37 friend void from_json(const json &j, ParamHandler &paramHandler);
38
40 // Public methods
42 // Get number of stored parameters
43 unsigned int GetNumParameters() const;
44 // Get a named parameter, throws error if name not found
45 Variant GetParameter(const std::string &strName) const;
46 // Check if named parameter is present
47 bool isParameterValid(const std::string &strName) const;
48 // Get list of all parameter names
49 std::vector<std::string> GetParameterNames() const;
50 // Get list of all parameter
51 StringVariantMap GetParameters() const;
52
53 // Set named parameter to new value, throws error if name not found
54 RBTDLL_EXPORT void SetParameter(const std::string &strName,
55 const Variant &vValue);
56
57 // Virtual function for dumping parameters to an output stream
58 // Called by operator <<
59 virtual void Print(std::ostream &s) const;
60
61protected:
63 // Protected methods
65 ParamHandler(); // Default constructor
66
67 // Only derived classes can mess with the parameter list
68 void AddParameter(const std::string &strName, const Variant &vValue);
69 void DeleteParameter(const std::string &strName);
70 void ClearParameters();
71 // DM 25 Oct 2000 - ParameterUpdated is invoked whenever SetParameter is
72 // called to allow derived classes to manage a data member which tracks the
73 // param value Useful for performance purposes as there is quite an overhead
74 // in finding a string in a map, then converting from a Variant to the native
75 // datatype Base class version does nothing
76 virtual void ParameterUpdated(const std::string &strName) {}
77
78private:
80 // Private methods
82
83 ParamHandler(const ParamHandler &); // Copy constructor disabled by default
85 operator=(const ParamHandler &); // Copy assignment disabled by default
86
87protected:
89 // Protected data
91
92private:
94 // Private data
96 StringVariantMap m_parameters;
97};
98
99void to_json(json &j, const ParamHandler &paramHandler);
100void from_json(const json &j, ParamHandler &paramHandler);
101
103// Non-member functions
104
105// Insertion operator (primarily for debugging)
106RBTDLL_EXPORT std::ostream &operator<<(std::ostream &s, const ParamHandler &ph);
107
108} // namespace rxdock
109
110#endif //_RBTPARAMHANDLER_H_
Definition ParamHandler.h:30
Definition Variant.h:30