Skip to content

Commit

Permalink
Update throw and assert macro
Browse files Browse the repository at this point in the history
  • Loading branch information
asherikov committed Jun 30, 2024
1 parent 99d996e commit 84c7679
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion extra_visitors/msgpack/src/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace ariles2
}
catch (const std::exception &e)
{
CPPUT_THROW(std::string("Failed to parse the configuration file: ") + e.what());
CPPUT_THROW("Failed to parse the configuration file: ", e.what());
}

nameless_counter_ = 0;
Expand Down
2 changes: 1 addition & 1 deletion extra_visitors/msgpack/src/reader_compact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace ariles2
}
catch (const std::exception &e)
{
CPPUT_THROW(std::string("Failed to parse the configuration file: ") + e.what());
CPPUT_THROW("Failed to parse the configuration file: ", e.what());
}
}

Expand Down
4 changes: 2 additions & 2 deletions extra_visitors/protobuf3/ariles2/visitors/protobuf3/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace ariles2
}
catch (std::exception &e)
{
CPPUT_THROW(std::string("Copying failed: ") + e.what());
CPPUT_THROW("Copying failed: ", e.what());
}
}

Expand All @@ -57,7 +57,7 @@ namespace ariles2
}
catch (const std::exception &e)
{
CPPUT_THROW("entry: " + name + " // " + std::string(e.what()));
CPPUT_THROW("entry: ", name, " // ", e.what());
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace ariles2
}
catch (std::exception &e)
{
CPPUT_THROW(std::string("Copying failed: ") + e.what());
CPPUT_THROW("Copying failed: ", e.what());
}
}
};
Expand Down
8 changes: 4 additions & 4 deletions include/ariles2/internal/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
CPPUT_THROW_EXCEPTION(std::runtime_error, cpput::concat::simple("In ", __func__, "() // ", __VA_ARGS__))


#define CPPUT_PERSISTENT_ASSERT(condition, message) \
#define CPPUT_PERSISTENT_ASSERT(condition, ...) \
if (!(condition)) \
{ \
CPPUT_THROW(message); \
CPPUT_THROW(__VA_ARGS__); \
};

#ifdef DNDEBUG
# define CPPUT_ASSERT(condition, message)
# define CPPUT_ASSERT(condition, ...)
#else
# define CPPUT_ASSERT(condition, message) CPPUT_PERSISTENT_ASSERT(condition, message)
# define CPPUT_ASSERT(condition, ...) CPPUT_PERSISTENT_ASSERT(condition, __VA_ARGS__)
#endif

#endif
4 changes: 2 additions & 2 deletions include/ariles2/visitors/copyfrom.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace ariles2
}
catch (std::exception &e)
{
CPPUT_THROW(std::string("Copying failed: ") + e.what());
CPPUT_THROW("Copying failed: ", e.what());
}
}

Expand All @@ -72,7 +72,7 @@ namespace ariles2
}
catch (const std::exception &e)
{
CPPUT_THROW("entry: " + name + " // " + std::string(e.what()));
CPPUT_THROW("entry: ", name, " // ", e.what());
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions include/ariles2/visitors/copyto.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace ariles2
}
catch (std::exception &e)
{
CPPUT_THROW(std::string("Copying failed: ") + e.what());
CPPUT_THROW("Copying failed: ", e.what());
}
}

Expand All @@ -72,7 +72,7 @@ namespace ariles2
}
catch (const std::exception &e)
{
CPPUT_THROW("entry: " + name + " // " + std::string(e.what()));
CPPUT_THROW("entry: ", name, " // ", std::string(e.what()));
}
}
};
Expand Down
18 changes: 9 additions & 9 deletions include/ariles2/visitors/read.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ namespace ariles2
std::string file_name_default = file_name;
config_ifs.open(file_name_default.c_str());
}
CPPUT_PERSISTENT_ASSERT(
config_ifs.good(), std::string("Could not open configuration file: ") + file_name.c_str());
CPPUT_PERSISTENT_ASSERT(config_ifs.good(), "Could not open configuration file: ", file_name.c_str());
}


Expand Down Expand Up @@ -419,9 +418,7 @@ namespace ariles2
}
catch (const std::exception &e)
{
CPPUT_THROW(
std::string("Failed to parse entry <") + convertSubtreeToString(subtree) + "> || "
+ e.what());
CPPUT_THROW("Failed to parse entry <"), convertSubtreeToString(subtree), "> || ", e.what();
}

this->endRoot(subtree);
Expand All @@ -430,8 +427,9 @@ namespace ariles2
{
CPPUT_PERSISTENT_ASSERT(
param.allow_missing_entries_,
std::string("Configuration file does not contain entry '") + convertSubtreeToString(subtree)
+ "'.");
"Configuration file does not contain entry '",
convertSubtreeToString(subtree),
"'.");
}
}

Expand All @@ -455,7 +453,7 @@ namespace ariles2
}
catch (const std::exception &e)
{
CPPUT_THROW(std::string("Failed to parse entry <") + name + "> || " + e.what());
CPPUT_THROW("Failed to parse entry <", name, "> || ", e.what());
}

this->endMapEntry();
Expand All @@ -465,7 +463,9 @@ namespace ariles2
{
CPPUT_PERSISTENT_ASSERT(
not override_missing_entries_locally and param.allow_missing_entries_,
std::string("Configuration file does not contain entry '") + name + "'.");
"Configuration file does not contain entry '",
name,
"'.");
return (false);
}
}
Expand Down
3 changes: 1 addition & 2 deletions include/ariles2/visitors/write.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ namespace ariles2
config_ofs.open(file_name.c_str());

CPPUT_PERSISTENT_ASSERT(
config_ofs.good(),
std::string("Could not open configuration file for writing: ") + file_name.c_str());
config_ofs.good(), "Could not open configuration file for writing: ", file_name.c_str());
}


Expand Down

0 comments on commit 84c7679

Please sign in to comment.