#pragma once #include #include #include #include #include #include #if !defined(NDEBUG) #include #endif #ifndef SWIG /* Forward declare the basic_json class */ namespace nlohmann { template struct adl_serializer; template class ObjectType, template class ArrayType, class StringType, class BooleanType, class NumberIntegerType, class NumberUnsignedType, class NumberFloatType, template class AllocatorType, template class JSONSerializer> class basic_json; using json = basic_json; } #endif namespace upm { inline std::string __func_or_memberfunc(const std::string& cxx_function) { size_t colons = cxx_function.find("::"); size_t begin = cxx_function.substr(0, colons).rfind(" ") + 1; size_t end = cxx_function.rfind(")") - begin + 1; return cxx_function.substr(begin, end); } #define __PRETTY_FUNCTIONS__ __func_or_memberfunc(__PRETTY_FUNCTION__) #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) #if !defined(NDEBUG) #define DEBUG_MSG(msg) do { std::cout << __FILENAME__ << ":" << __LINE__ \ << " [" << __PRETTY_FUNCTIONS__ << "] " << msg << std::endl; } while (0) #else #define DEBUG_MSG(msg) do {} while (0) #endif class iUpmObject; /** * Function pointer typedef for child-to-parent proxy call */ typedef std::string (*t_getJson)(iUpmObject*); class iUpmObject { public: iUpmObject(); virtual ~iUpmObject(); virtual std::string Description(); virtual std::string JsonDefinition(); virtual std::string Name(); virtual void initFromJsonLibDesc(std::string path_to_json_file); #ifndef SWIG nlohmann::json& LibraryJson(); #endif std::string DataDirectory() const; std::string DerivedClassName() const; std::string LibraryAbsolutePath() const; std::string LibraryBaseName() const; std::string LibraryJsonFilename() const; std::string LibraryJsonRaw() const; std::string LibraryVersion() const; protected: void AddValueSerializer(iUpmObject* instance, t_getJson method); void AddJsonDeserializer(iUpmObject* instance, t_getJson method); /** * Used by child classes for child-to-parent proxy call */ std::map _child_value_serializers; /** * Used by child classes for child-to-parent proxy call */ std::map _child_json_deserializers; ///* //friend std::ostream& operator<<(std::ostream& os, const iUpmObject& o) //{ // return os << " \"name\" : \"" << o.Name() << "\"," << std::endl // << " \"description\" : \"" << o.Description() << "\""; //} //friend std::ostream& operator<<(std::ostream& os, const iUpmObject* o) //{ return os << *o; } //*/ private: nlohmann::json *_json = NULL; std::string _Description; std::string _LibraryJsonFilename; std::string _LibraryJsonRaw; }; }