From b22860234ff7991c851211042a9832d88ccbb958 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 31 May 2016 08:49:48 -0400 Subject: entitys can modify xml --- src/common.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/common.cpp') diff --git a/src/common.cpp b/src/common.cpp index c643174..bb1ad1e 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -174,6 +174,39 @@ const char *readFile(const char *path) return buf; } +std::string readFile(const std::string& path) +{ + std::ifstream in (path, std::ios::in); + std::string buffer; + + if (!in.is_open()) + UserError("Error reading file " + path); + + in.seekg(0, in.end); + buffer.reserve(in.tellg()); + in.seekg(0, in.beg); + in.read(&buffer[0], buffer.size()); + + in.close(); + return buffer; +} + +std::vector readFileA(const std::string& path) +{ + std::ifstream in (path, std::ios::in); + std::vector lines; + std::string line; + + if (!in.is_open()) + UserError("Error reading file " + path); + + while(std::getline(in, line)) + lines.push_back(line); + + in.close(); + return lines; +} + void UserError(std::string reason) { std::cout << "User error: " << reason << "!\n"; -- cgit v1.2.3