Skip to content

Commit

Permalink
Added NOMINMAX to remove windows namespace pollution.
Browse files Browse the repository at this point in the history
  • Loading branch information
anirul committed Nov 3, 2024
1 parent 145b7fc commit 670ccad
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 47 deletions.
88 changes: 44 additions & 44 deletions include/frame/json/parse_json.h
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.
3 changes: 2 additions & 1 deletion src/frame/opengl/sdl_opengl_none.h
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)
Expand Down
3 changes: 2 additions & 1 deletion src/frame/opengl/sdl_opengl_window.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "frame/opengl/sdl_opengl_window.h"

// Needed under windows to get the PPI.
#if defined(_WIN32) || defined(_WIN64)
#if defined(_WIN32) || defined(_WIN64)
#define NOMIXMAX
#include <shellscalingapi.h>
#include <shtypes.h>
#pragma comment(lib, "Shcore.lib")
Expand Down
3 changes: 2 additions & 1 deletion src/frame/opengl/sdl_opengl_window.h
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)
Expand Down

0 comments on commit 670ccad

Please sign in to comment.