/* This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus
*
* MAUS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MAUS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MAUS. If not, see .
*/
#ifndef _SRC_COMMON_CPP_JSONCPPPROCESSORS_OBJECTPROCESSORNS_POINTERTREFITEM_HH_
#define _SRC_COMMON_CPP_JSONCPPPROCESSORS_OBJECTPROCESSORNS_POINTERTREFITEM_HH_
#include
#include "TRef.h"
#include "src/common_cpp/JsonCppProcessors/ProcessorBase.hh"
#include "src/common_cpp/Utils/JsonWrapper.hh"
#include "src/common_cpp/JsonCppProcessors/Common/ReferenceResolverCppToJson.hh"
#include "src/common_cpp/JsonCppProcessors/Common/ReferenceResolverJsonToCpp.hh"
namespace MAUS {
namespace ObjectProcessorNS {
/** @class PointerTRefItem pointer reference branch for a Cpp object
*
* Probably don't want to use this class, instead use Register...Branch methods
* directly on ObjectProcessor
*
* @tparam ParentType type of the parent object
* @tparam ChildType type of the child object referenced by the branch. Should
* use the actual type even if the target is a pointer
*
* References the location of a PointerValueItem type branch.
*/
template
class PointerTRefItem : public BaseItem {
public:
typedef void (ParentType::*SetMethod)(TObject* _tobj);
typedef TObject* (ParentType::*GetMethod)() const;
/** Constructor
*
* @param branch_name name used by json to reference the branch
* @param GetMethod callback that will return a pointer to the child data,
* where memory is still owned by the ObjectProcessor
* @param SetMethod callback that will set a pointer to the child data,
* where memory is given to the ObjectProcessor
* @param is_required if the branch doesnt exist in json, is null in json
* or is NULL in C++, throw Squeal if is_required is set to true when
* Set...Child methods are called
*/
PointerTRefItem(std::string branch_name,
GetMethod getter,
SetMethod setter,
bool is_required);
/** SetCppChild using data from parent_json
*
* @param parent_json json object whose child branch is used to make C++
* representation
* @param parent_cpp C++ object where C++ data is put
*
* Performs some error checking then adds a reference to the RefManager. If
* RefManager has not been birthed then does nothing. Actual pointer
* allocation is done after the entire tree has been parsed by
* RefManager::SetReferences()
*/
void _SetCppChild(const Json::Value& parent_json, ParentType& parent_cpp);
/** SetJsonChild fills the branch with a Null json value and stores the
* branch location and pointer in the reference manager for filling later.
*
* @param parent_cpp C++ object from whence C++ data is got
* @param parent_json json object whose child branch is set using C++
* representation
*
* Performs some error checking then adds a reference to the RefManager. If
* RefManager has not been birthed then does nothing. Actual pointer
* allocation is done after the entire tree has been parsed by
* RefManager::SetReferences()
*/
void _SetJsonChild(const ParentType& parent_cpp, Json::Value& parent_json);
/** Get the branch name */
std::string GetBranchName() const {return _branch;}
private:
std::string _branch;
SetMethod _setter;
GetMethod _getter;
bool _required;
};
} // namespace ObjectProcessorNS
} // namespace MAUS
#include "src/common_cpp/JsonCppProcessors/Common/ObjectProcessorNS/PointerTRefItem-inl.hh"
#endif