Skip to content

Commit

Permalink
constantify
Browse files Browse the repository at this point in the history
  • Loading branch information
pantor committed Aug 8, 2020
1 parent 73c04e6 commit 4182c5d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
6 changes: 3 additions & 3 deletions include/inja/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ struct SourceLocation {
};

struct InjaError : public std::runtime_error {
std::string type;
std::string message;
const std::string type;
const std::string message;

SourceLocation location;
const SourceLocation location;

explicit InjaError(const std::string &type, const std::string &message)
: std::runtime_error("[inja.exception." + type + "] " + message), type(type), message(message), location({0, 0}) {}
Expand Down
10 changes: 5 additions & 5 deletions include/inja/function_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ class FunctionStorage {
None,
};

const int VARIADIC {-1};

struct FunctionData {
Operation operation;

CallbackFunction callback;
const Operation operation;
const CallbackFunction callback;
};

private:
const int VARIADIC {-1};

std::map<std::pair<std::string, int>, FunctionData> function_storage = {
{std::make_pair("at", 2), FunctionData { Operation::At }},
{std::make_pair("default", 2), FunctionData { Operation::Default }},
Expand Down
20 changes: 10 additions & 10 deletions include/inja/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class BlockNode : public AstNode {

class TextNode : public AstNode {
public:
size_t length;
const size_t length;

explicit TextNode(size_t pos, size_t length): AstNode(pos), length(length) { }

Expand All @@ -96,7 +96,7 @@ class ExpressionNode : public AstNode {

class LiteralNode : public ExpressionNode {
public:
nlohmann::json value;
const nlohmann::json value;

explicit LiteralNode(const nlohmann::json& value, size_t pos) : ExpressionNode(pos), value(value) { }

Expand All @@ -107,8 +107,8 @@ class LiteralNode : public ExpressionNode {

class JsonNode : public ExpressionNode {
public:
std::string name;
json::json_pointer ptr;
const std::string name;
const json::json_pointer ptr;

static std::string convert_dot_to_json_ptr(nonstd::string_view ptr_name) {
std::string result;
Expand Down Expand Up @@ -261,7 +261,7 @@ class ForStatementNode : public StatementNode {

class ForArrayStatementNode : public ForStatementNode {
public:
std::string value;
const std::string value;

explicit ForArrayStatementNode(const std::string& value, BlockNode *const parent, size_t pos) : ForStatementNode(parent, pos), value(value) { }

Expand All @@ -272,8 +272,8 @@ class ForArrayStatementNode : public ForStatementNode {

class ForObjectStatementNode : public ForStatementNode {
public:
std::string key;
std::string value;
const std::string key;
const std::string value;

explicit ForObjectStatementNode(const std::string& key, const std::string& value, BlockNode *const parent, size_t pos) : ForStatementNode(parent, pos), key(key), value(value) { }

Expand All @@ -289,7 +289,7 @@ class IfStatementNode : public StatementNode {
BlockNode false_statement;
BlockNode *const parent;

bool is_nested;
const bool is_nested;
bool has_false_statement {false};

explicit IfStatementNode(BlockNode *const parent, size_t pos) : StatementNode(pos), parent(parent), is_nested(false) { }
Expand All @@ -302,7 +302,7 @@ class IfStatementNode : public StatementNode {

class IncludeStatementNode : public StatementNode {
public:
std::string file;
const std::string file;

explicit IncludeStatementNode(const std::string& file, size_t pos) : StatementNode(pos), file(file) { }

Expand All @@ -313,7 +313,7 @@ class IncludeStatementNode : public StatementNode {

class SetStatementNode : public StatementNode {
public:
std::string key;
const std::string key;
ExpressionListNode expression;

explicit SetStatementNode(const std::string& key, size_t pos) : StatementNode(pos), key(key) { }
Expand Down
36 changes: 18 additions & 18 deletions single_include/inja/inja.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1582,14 +1582,14 @@ class FunctionStorage {
None,
};

const int VARIADIC {-1};

struct FunctionData {
Operation operation;

CallbackFunction callback;
const Operation operation;
const CallbackFunction callback;
};

private:
const int VARIADIC {-1};

std::map<std::pair<std::string, int>, FunctionData> function_storage = {
{std::make_pair("at", 2), FunctionData { Operation::At }},
{std::make_pair("default", 2), FunctionData { Operation::Default }},
Expand Down Expand Up @@ -1681,10 +1681,10 @@ struct SourceLocation {
};

struct InjaError : public std::runtime_error {
std::string type;
std::string message;
const std::string type;
const std::string message;

SourceLocation location;
const SourceLocation location;

explicit InjaError(const std::string &type, const std::string &message)
: std::runtime_error("[inja.exception." + type + "] " + message), type(type), message(message), location({0, 0}) {}
Expand Down Expand Up @@ -2356,7 +2356,7 @@ class BlockNode : public AstNode {

class TextNode : public AstNode {
public:
size_t length;
const size_t length;

explicit TextNode(size_t pos, size_t length): AstNode(pos), length(length) { }

Expand All @@ -2376,7 +2376,7 @@ class ExpressionNode : public AstNode {

class LiteralNode : public ExpressionNode {
public:
nlohmann::json value;
const nlohmann::json value;

explicit LiteralNode(const nlohmann::json& value, size_t pos) : ExpressionNode(pos), value(value) { }

Expand All @@ -2387,8 +2387,8 @@ class LiteralNode : public ExpressionNode {

class JsonNode : public ExpressionNode {
public:
std::string name;
json::json_pointer ptr;
const std::string name;
const json::json_pointer ptr;

static std::string convert_dot_to_json_ptr(nonstd::string_view ptr_name) {
std::string result;
Expand Down Expand Up @@ -2541,7 +2541,7 @@ class ForStatementNode : public StatementNode {

class ForArrayStatementNode : public ForStatementNode {
public:
std::string value;
const std::string value;

explicit ForArrayStatementNode(const std::string& value, BlockNode *const parent, size_t pos) : ForStatementNode(parent, pos), value(value) { }

Expand All @@ -2552,8 +2552,8 @@ class ForArrayStatementNode : public ForStatementNode {

class ForObjectStatementNode : public ForStatementNode {
public:
std::string key;
std::string value;
const std::string key;
const std::string value;

explicit ForObjectStatementNode(const std::string& key, const std::string& value, BlockNode *const parent, size_t pos) : ForStatementNode(parent, pos), key(key), value(value) { }

Expand All @@ -2569,7 +2569,7 @@ class IfStatementNode : public StatementNode {
BlockNode false_statement;
BlockNode *const parent;

bool is_nested;
const bool is_nested;
bool has_false_statement {false};

explicit IfStatementNode(BlockNode *const parent, size_t pos) : StatementNode(pos), parent(parent), is_nested(false) { }
Expand All @@ -2582,7 +2582,7 @@ class IfStatementNode : public StatementNode {

class IncludeStatementNode : public StatementNode {
public:
std::string file;
const std::string file;

explicit IncludeStatementNode(const std::string& file, size_t pos) : StatementNode(pos), file(file) { }

Expand All @@ -2593,7 +2593,7 @@ class IncludeStatementNode : public StatementNode {

class SetStatementNode : public StatementNode {
public:
std::string key;
const std::string key;
ExpressionListNode expression;

explicit SetStatementNode(const std::string& key, size_t pos) : StatementNode(pos), key(key) { }
Expand Down

0 comments on commit 4182c5d

Please sign in to comment.