1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Added a new json constructor to read from a file.

This commit is contained in:
Frank Zago 2011-08-20 01:04:59 +00:00
parent 8054c85091
commit f6c39eed0c
2 changed files with 14 additions and 2 deletions

View File

@ -4,6 +4,7 @@
#include <assert.h>
#include <fstream>
#include <sstream>
#include <iostream>
const JsonNode JsonNode::nullNode;
@ -19,6 +20,15 @@ JsonNode::JsonNode(std::string input):
JsonParser parser(input, *this);
}
JsonNode::JsonNode(const char *filename)
{
std::ifstream file(filename);
std::string str((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
JsonParser parser(str, *this);
}
JsonNode::JsonNode(const JsonNode &copy):
type(DATA_NULL)
{

View File

@ -42,6 +42,8 @@ public:
JsonNode(JsonType Type = DATA_NULL);
//Create tree from Json-formatted input
explicit JsonNode(std::string input);
//Create tree from JSON file
JsonNode(const char *filename);
//Copy c-tor
JsonNode(const JsonNode &copy);
@ -56,7 +58,7 @@ public:
bool isNull() const;
//non-const acessors, node will change type on type mismatch
//non-const accessors, node will change type on type mismatch
bool & Bool();
int & Int();
float & Float();
@ -64,7 +66,7 @@ public:
JsonVector & Vector();
JsonMap & Struct();
//const acessors, will cause assertion failure on type mismatch
//const accessors, will cause assertion failure on type mismatch
const bool & Bool() const;
const int & Int() const;
const float & Float() const;