First server executable
This commit is contained in:
34
helpers.h
Normal file
34
helpers.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef HELPERS_H_
|
||||
#define HELPERS_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "json.hpp"
|
||||
|
||||
|
||||
// Reads configuration json from supplied filename
|
||||
// cfg - output json
|
||||
// filename - filepath from which to read json
|
||||
// log - ostream to log human readable errors to - can be nullptr
|
||||
// Returns - true if read and parse is successful
|
||||
bool read_config_json(nlohmann::json& cfg, const std::string& filename, std::ostream* log);
|
||||
|
||||
// Reads configuration json from supplied istream
|
||||
// cfg - output json
|
||||
// in - istream from which to read json
|
||||
// log - ostream to log human readable errors to - can be nullptr
|
||||
// Returns - true if read and parse is successful
|
||||
bool read_config_json(nlohmann::json& cfg, std::istream& in, std::ostream* log);
|
||||
|
||||
// JSON Extraction Helpers
|
||||
// out value is modified only if an extraction happened
|
||||
// Returns - whether an extraction happened
|
||||
bool json_extract(const nlohmann::json& j, const std::string& key, std::string& out);
|
||||
bool json_extract(const nlohmann::json& j, const std::string& key, int& out);
|
||||
bool json_extract(const nlohmann::json& j, const std::string& key, bool& out);
|
||||
bool json_extract(const nlohmann::json& j, const std::string& key, uint16_t& out);
|
||||
|
||||
#endif // HELPERS_H_
|
||||
Reference in New Issue
Block a user