-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added NOMINMAX to remove windows namespace pollution.
- Loading branch information
Showing
4 changed files
with
50 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
#pragma once | ||
|
||
#include <google/protobuf/util/json_util.h> | ||
|
||
#include <filesystem> | ||
#include <fstream> | ||
#include <string> | ||
|
||
namespace frame::proto | ||
{ | ||
|
||
#pragma once | ||
|
||
#include <google/protobuf/util/json_util.h> | ||
|
||
#include <filesystem> | ||
#include <fstream> | ||
#include <string> | ||
|
||
namespace frame::proto | ||
{ | ||
|
||
template <typename T> | ||
T LoadProtoFromJson(const std::string& json) | ||
{ | ||
T proto{}; | ||
google::protobuf::util::JsonParseOptions options{}; | ||
options.ignore_unknown_fields = false; | ||
auto status = | ||
google::protobuf::util::JsonStringToMessage(json, &proto, options); | ||
if (!status.ok()) | ||
{ | ||
throw std::runtime_error( | ||
"Couldn't parse json status error: " + | ||
status.ToString()); | ||
} | ||
return proto; | ||
} | ||
|
||
template <typename T> | ||
T LoadProtoFromJsonFile(const std::filesystem::path& filename) | ||
{ | ||
// Empty case (no such file return an empty structure). | ||
if (filename.empty()) | ||
return T{}; | ||
// Try to open it. | ||
std::ifstream ifs(filename.string(), std::ios::in); | ||
if (!ifs.is_open()) | ||
{ | ||
throw std::runtime_error("Couldn't open file: " + filename.string()); | ||
} | ||
std::string contents(std::istreambuf_iterator<char>(ifs), {}); | ||
return LoadProtoFromJson<T>(contents); | ||
} | ||
|
||
} // End namespace frame::proto. | ||
T LoadProtoFromJson(const std::string& json) | ||
{ | ||
T proto{}; | ||
google::protobuf::util::JsonParseOptions options{}; | ||
options.ignore_unknown_fields = false; | ||
auto status = | ||
google::protobuf::util::JsonStringToMessage(json, &proto, options); | ||
if (!status.ok()) | ||
{ | ||
throw std::runtime_error( | ||
"Couldn't parse json status error: " + | ||
status.ToString()); | ||
} | ||
return proto; | ||
} | ||
|
||
template <typename T> | ||
T LoadProtoFromJsonFile(const std::filesystem::path& filename) | ||
{ | ||
// Empty case (no such file return an empty structure). | ||
if (filename.empty()) | ||
return T{}; | ||
// Try to open it. | ||
std::ifstream ifs(filename.string(), std::ios::in); | ||
if (!ifs.is_open()) | ||
{ | ||
throw std::runtime_error("Couldn't open file: " + filename.string()); | ||
} | ||
std::string contents(std::istreambuf_iterator<char>(ifs), {}); | ||
return LoadProtoFromJson<T>(contents); | ||
} | ||
|
||
} // End namespace frame::proto. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#pragma once | ||
|
||
|
||
#define NOMINMAX | ||
#include <GL/glew.h> | ||
#include <SDL2/SDL.h> | ||
#if defined(_WIN32) || defined(_WIN64) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#pragma once | ||
|
||
|
||
#define NOMINMAX | ||
#include <GL/glew.h> | ||
#include <SDL2/SDL.h> | ||
#if defined(_WIN32) || defined(_WIN64) | ||
|