35 #include <json/reader.h> 36 #include <json/writer.h> 37 #include <osgDB/fstream> 75 Json::CharReaderBuilder reader;
78 LOG_D(
"Opening JSON File for Reading: " + fullFilePath);
81 LOG_D(
"Reading JSON File: " + fullFilePath);
82 osgDB::ifstream inputStream(fullFilePath.c_str(), std::ifstream::binary);
90 LOG_D(
"Parsing JSON File");
95 LOG_E(
"JSON Parsing Error: " + errs);
105 LOG_E(
"Can't open: " + fullFilePath);
129 Json::StreamWriterBuilder builder;
130 builder[
"indentation"]=
" ";
131 std::unique_ptr<Json::StreamWriter> streamWriter(builder.newStreamWriter());
134 LOG_D(
"Opening JSON File for Writing: " + fullFilePath);
135 osgDB::ofstream outputStream(fullFilePath.c_str());
138 LOG_D(
"Writing file");
139 streamWriter->write(
mRoot, &outputStream);
140 LOG_D(
"Closing file");
141 outputStream.close();
142 LOG_D(
"File Closed");
198 std::cout <<
mRoot << std::endl;
virtual bool IsArray() const
Checks if the value stored is an Array.
void Clear() override
Clears the internal JSON Root node.
virtual bool IsUInt64() const
Checks if the value stored is a 64bit Unsigned Integer.
virtual bool IsBool() const
Checks if the value stored is a Boolean.
virtual void SetInt64(const std::string &key, Int64 value)
Sets the Int64 value in the Object.
virtual bool IsInt() const
Checks if the value stored is an Integer.
virtual bool IsObject(const std::string &key) const override
Checks if the value stored at the specific key is an Object.
bool FileExists(const std::string &strFile, bool caseInsensitive=false) const
Queries if a given file exists.
virtual Value & GetJSONRoot() override
Returns a reference to the internal JSON Root node.
This is the exception class used throughout the engine.
virtual bool IsUInt() const
Checks if the value stored Unsigned Integer.
virtual bool IsFloat() const
Checks if the value stored is a float.
virtual unsigned int GetUInt() const
Returns the Unsigned Integer value.
virtual float GetFloat(const std::string &key) const override
Returns the float value stored at the given key.
virtual bool IsArray(const std::string &key) const override
Checks if the value stored at the specific key is an Array.
virtual std::string GetFileName() const
Returns the name of the current file.
virtual void SetString(const std::string &key, const std::string &value) override
Sets the String to be stored at the given key.
virtual int GetInt(const std::string &key) const override
Returns the Integer value stored at the given key.
virtual bool IsNumber(const std::string &key) const override
Checks if the value stored at the specific key is a Number.
virtual void SetDouble(const std::string &key, const double &value) override
Sets the Double value to be stored at the given key.
virtual Int64 GetInt64(const std::string &key) const override
Returns the 64bit Integer value stored at the given key.
virtual void SetUInt(const std::string &key, unsigned int value)
Sets the Unsigned Int value in the Object.
std::string mFileName
Filename of the file.
virtual void PrintJSONRoot() override
Prints out to the screen the whole JSON Root content.
virtual int GetInt() const
Returns the Integer value.
virtual void SetString(const std::string &key, const std::string &value)
Sets the String value in the Object.
virtual bool IsInt(const std::string &key) const override
Checks if the value stored at the specific key is an Integer.
virtual bool IsString() const
Checks if the value stored is a String.
virtual void Clear()
Clears the internal JSON Root node.
virtual unsigned int GetUInt(const std::string &key) const override
Returns the Unsigned Integer value stored at the given key.
virtual bool IsFalse(const std::string &key) const override
Checks if the value stored at the specific key is False.
virtual void SetFloat(const std::string &key, const float &value) override
Sets the float value to be stored at the given key.
virtual bool IsBool(const std::string &key) const override
Checks if the value stored at the specific key is a Boolean.
int64_t Int64
The fourth int 6.
virtual bool IsUInt(const std::string &key) const override
Checks if the value stored at the specific key is an Unsigned Integer.
virtual double GetDouble() const
Returns the Double value.
virtual void SetBool(const std::string &key, const bool &value) override
Sets the Boolean value to be stored at the given key.
virtual bool FileExists()
Returns true if the file name and path exist on the HD.
virtual void SetUInt64(const std::string &key, const UInt64 &value) override
Sets the 64bit Integer value to be stored at the given key.
virtual bool IsNull() const
Checks if the value stored is a NULL.
virtual void SetFilePath(std::string newPath)
Sets the path of where the file will be read from or written to.
virtual bool IsUInt64(const std::string &key) const override
Checks if the value stored at the specific key is a 64bit Integer.
virtual void SetNull(const std::string &key) const
Sets the NULL value in the Object.
virtual bool GetBool() const
Returns the Boolean value.
virtual bool GetBool(const std::string &key) const override
Returns the Boolean value stored at the given key.
void LogException(trUtil::Logging::LogLevel level=trUtil::Logging::LogLevel::LOG_ERROR) const
Logs the exception to the default logger.
virtual std::string GetFilePath() const
Returns the path of where the file is read or written to.
TR_UTIL_EXPORT std::string GetUserConfigPath()
Gets user configuration path.
virtual void SetObject(const std::string &key, Object &value) override
Sets the Array to be stored at the given key.
virtual void SetUInt64(const std::string &key, UInt64 value)
Sets the Unsigned Int64 value in the Object.
virtual void SetInt64(const std::string &key, const Int64 &value) override
Sets the 64bit Integer value to be stored at the given key.
virtual bool IsDouble() const
Checks if the value stored is a Double.
virtual const std::string GetString(const std::string &key) const override
Returns the String value stored at the given key.
virtual bool IsString(const std::string &key) const override
Checks if the value stored at the specific key is a String.
virtual void SetUInt(const std::string &key, const unsigned int &value) override
Sets the Unsigned Integer value to be stored at the given key.
virtual bool IsTrue(const std::string &key) const override
Checks if the value stored at the specific key is True.
virtual float GetFloat() const
Returns the float value stored.
virtual void SetInt(const std::string &key, const int &value) override
Sets the Integer value to be stored at the given key.
virtual UInt64 GetUInt64() const
Returns the Unsigned 64bit Integer value.
virtual void SetInt(const std::string &key, int value)
Sets the Integer value in the Object.
#define LOG_E(msg)
Log an ERROR message.
virtual void SetArray(const std::string &key, Array &value) override
Sets the Array to be stored at the given key.
static const std::string DEFAULT_JSON_FILE_NAME
The default JSON file name.
virtual bool IsInt64(const std::string &key) const override
Checks if the value stored at the specific key is a 64bit Integer.
virtual bool IsDouble(const std::string &key) const override
Checks if the value stored at the specific key is a Double.
virtual bool IsNull(const std::string &key) const override
Checks if the value stored at the specific key is a NULL.
virtual void SetObject(const std::string &key, Object &value)
Sets the Object value in the Object.
virtual bool IsFloat(const std::string &key) const override
Checks if the value stored at the specific key is a float.
static FileUtils & GetInstance()
Character separating the parts of a file path.
virtual bool ReadFromFile()
Reads from a file and parses the JSON into a Root Node.
virtual const Array GetArray() const
Returns the Array value stored.
virtual Array GetArray(const std::string &key) const override
Returns the Array value stored at the given key.
virtual void SetFloat(const std::string &key, float value)
Sets the Float value in the Object.
virtual void SetFileName(std::string fileName)
Sets a new file name.
virtual Object GetObject(const std::string &key) const override
Returns the Object value stored at the given key.
virtual void SetBool(const std::string &key, bool value)
Sets the Boolean value in the Object.
virtual bool IsInt64() const
Checks if the value stored is a 64bit Integer.
virtual double GetDouble(const std::string &key) const override
Returns the Double value stored at the given key.
std::string mFilePath
Full pathname of the file.
virtual const Object GetObject() const
Returns the Object value stored.
virtual void SetArray(const std::string &key, Array &value)
Sets the Array value in the Object.
virtual bool KeyPresent(const std::string &key) const override
Checks if the JSON Root Node has an entry with a given key present.
virtual UInt64 GetUInt64(const std::string &key) const override
Returns the 64bit Integer value stored at the given key.
virtual void SetDouble(const std::string &key, double value)
Sets the Double value in the Object.
bool HasMember(const std::string &key) const
Returns true if a member with the passed in key is present.
virtual bool WriteToFile()
Writes the Root Node to a JSON file.
virtual bool IsObject() const
Checks if the value stored is an Object.
virtual const std::string GetString() const
Returns the String value stored.
uint64_t UInt64
The fourth u int 6.
virtual void SetNull(const std::string &key) override
Sets the value stored at the specific key to NULL.
#define LOG_D(msg)
Log a DEBUG message.
virtual Int64 GetInt64() const
Returns the 64bit Integer value.
Json::Value & GetJsonValue()
Returns a reference to the internal Json::Value.
virtual bool IsNumber() const
Checks if the value stored is a Number.