~mwinter4/maus/ckov-update

« back to all changes in this revision

Viewing changes to src/common_cpp/JsonCppProcessors/Common/ReferenceResolverJsonToCpp.hh

  • Committer: Chris Rogers
  • Date: 2013-03-19 14:21:55 UTC
  • mfrom: (659.1.63 release-candidate)
  • Revision ID: chris.rogers@stfc.ac.uk-20130319142155-65vwtifralro5ukv
Tags: MAUS-v0.5.1
MAUS-v0.5.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <string>
23
23
#include <vector>
24
24
 
 
25
#include "TRef.h"
 
26
#include "TRefArray.h"
 
27
 
25
28
#include "json/value.h"
26
29
 
27
30
namespace MAUS {
88
91
    ParentType* _ref_cpp_parent;
89
92
};
90
93
 
 
94
/** @class TRefResolver
 
95
 *
 
96
 *  Converts a Json pointer to a C++ pointer
 
97
 *
 
98
 *  @tparam ParentType type of object that holds the pointer
 
99
 */
 
100
template <class ParentType>
 
101
class TRefResolver : public Resolver {
 
102
  public:
 
103
    /** SetMethod function pointer for setting the C++ pointer during
 
104
     *  dereference operation
 
105
     */
 
106
    typedef void (ParentType::*SetMethod)(TRef value);
 
107
 
 
108
    /** Constructor
 
109
     *
 
110
     *  @param ref_json_address path to the json pointer-by-value (i.e. actual
 
111
     *  data in the json tree. This is stored in the "$ref" field of the json
 
112
     *  pointer-by-reference
 
113
     *  @param ref_cpp_set_func SetMethod that is used to set the C++ pointer
 
114
     *  @param ref_cpp_parent C++ object that will store the C++ pointer.
 
115
     */
 
116
    TRefResolver(std::string ref_json_address,
 
117
                 SetMethod ref_cpp_set_func,
 
118
                 ParentType* ref_cpp_parent);
 
119
 
 
120
    /** Destructor does nothing */
 
121
    ~TRefResolver() {}
 
122
 
 
123
    /** Resolve this reference
 
124
     *
 
125
     *  Lookup the json address on the RefManager; call SetMethod to allocate
 
126
     *  the resultant C++ pointer to the parent object.
 
127
     *
 
128
     *  Note that as we store the addresses of C++ objects, deep copy of the C++
 
129
     *  data is not allowed during processing of the data tree until after we
 
130
     *  have called ResolveReferences (otherwise reference resolution will fail)
 
131
     */
 
132
    void ResolveReferences();
 
133
 
 
134
  private:
 
135
    SetMethod _cpp_setter;
 
136
    std::string _ref_json_address;
 
137
    ParentType* _ref_cpp_parent;
 
138
};
 
139
 
91
140
/** @class VectorResolver
92
141
 *
93
142
 *  Converts a Json pointer to a C++ pointer in an array (std::vector)
128
177
    size_t _index;
129
178
};
130
179
 
 
180
/** @class TRefArrayResolver
 
181
 *
 
182
 *  Converts a Json pointer to a C++ pointer stored in a TRefArray
 
183
 *
 
184
 *  @tparam ChildType type of object pointed to;
 
185
 */
 
186
class TRefArrayResolver : public Resolver {
 
187
 public:
 
188
  /** Constructor
 
189
   *
 
190
   *  @param ref_json_address Address of json object
 
191
   *  @param tref_array The TRefArray holding child data
 
192
   *  @param vector_index Location in the vector holding child data
 
193
   */
 
194
  TRefArrayResolver(std::string ref_json_address,
 
195
                    TRefArray* tref_array,
 
196
                    size_t vector_index);
 
197
 
 
198
  /** Destructor - does nothing */
 
199
  ~TRefArrayResolver() {}
 
200
 
 
201
  /** Resolve this reference
 
202
   *
 
203
   *  Lookup the json address on the RefManager; call vector subscript
 
204
   *  operator to allocate the resultant C++ pointer to the parent object.
 
205
   *
 
206
   *  Note that as we store the addresses of C++ objects, deep copy of the C++
 
207
   *  data is not allowed during processing of the data tree until after we
 
208
   *  have called ResolveReferences (otherwise reference resolution will fail)
 
209
   */
 
210
  void ResolveReferences();
 
211
 
 
212
 private:
 
213
  std::string _ref_json_address;
 
214
  TRefArray* _tref_array;
 
215
  size_t _index;
 
216
};
 
217
 
131
218
class RefManager {
132
219
  public:
133
220
    /** Get the static instance of the RefManager