Skip to content

Commit 01cca4f

Browse files
committed
Update throw and assert macro
1 parent 99d996e commit 01cca4f

File tree

9 files changed

+23
-24
lines changed

9 files changed

+23
-24
lines changed

extra_visitors/msgpack/src/reader.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace ariles2
6969
}
7070
catch (const std::exception &e)
7171
{
72-
CPPUT_THROW(std::string("Failed to parse the configuration file: ") + e.what());
72+
CPPUT_THROW("Failed to parse the configuration file: ", e.what());
7373
}
7474

7575
nameless_counter_ = 0;

extra_visitors/msgpack/src/reader_compact.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace ariles2
6060
}
6161
catch (const std::exception &e)
6262
{
63-
CPPUT_THROW(std::string("Failed to parse the configuration file: ") + e.what());
63+
CPPUT_THROW("Failed to parse the configuration file: ", e.what());
6464
}
6565
}
6666

extra_visitors/protobuf3/ariles2/visitors/protobuf3/reader.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace ariles2
3838
}
3939
catch (std::exception &e)
4040
{
41-
CPPUT_THROW(std::string("Copying failed: ") + e.what());
41+
CPPUT_THROW("Copying failed: ", e.what());
4242
}
4343
}
4444

@@ -57,7 +57,7 @@ namespace ariles2
5757
}
5858
catch (const std::exception &e)
5959
{
60-
CPPUT_THROW("entry: " + name + " // " + std::string(e.what()));
60+
CPPUT_THROW("entry: ", name, " // ", e.what());
6161
}
6262
}
6363
};

extra_visitors/protobuf3/ariles2/visitors/protobuf3/writer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace ariles2
3838
}
3939
catch (std::exception &e)
4040
{
41-
CPPUT_THROW(std::string("Copying failed: ") + e.what());
41+
CPPUT_THROW("Copying failed: ", e.what());
4242
}
4343
}
4444
};

include/ariles2/internal/exception.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
CPPUT_THROW_EXCEPTION(std::runtime_error, cpput::concat::simple("In ", __func__, "() // ", __VA_ARGS__))
2121

2222

23-
#define CPPUT_PERSISTENT_ASSERT(condition, message) \
23+
#define CPPUT_PERSISTENT_ASSERT(condition, ...) \
2424
if (!(condition)) \
2525
{ \
26-
CPPUT_THROW(message); \
26+
CPPUT_THROW(__VA_ARGS__); \
2727
};
2828

2929
#ifdef DNDEBUG
30-
# define CPPUT_ASSERT(condition, message)
30+
# define CPPUT_ASSERT(condition, ...)
3131
#else
32-
# define CPPUT_ASSERT(condition, message) CPPUT_PERSISTENT_ASSERT(condition, message)
32+
# define CPPUT_ASSERT(condition, ...) CPPUT_PERSISTENT_ASSERT(condition, __VA_ARGS__)
3333
#endif
3434

3535
#endif

include/ariles2/visitors/copyfrom.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace ariles2
5353
}
5454
catch (std::exception &e)
5555
{
56-
CPPUT_THROW(std::string("Copying failed: ") + e.what());
56+
CPPUT_THROW("Copying failed: ", e.what());
5757
}
5858
}
5959

@@ -72,7 +72,7 @@ namespace ariles2
7272
}
7373
catch (const std::exception &e)
7474
{
75-
CPPUT_THROW("entry: " + name + " // " + std::string(e.what()));
75+
CPPUT_THROW("entry: ", name, " // ", e.what());
7676
}
7777
}
7878
};

include/ariles2/visitors/copyto.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace ariles2
5353
}
5454
catch (std::exception &e)
5555
{
56-
CPPUT_THROW(std::string("Copying failed: ") + e.what());
56+
CPPUT_THROW("Copying failed: ", e.what());
5757
}
5858
}
5959

@@ -72,7 +72,7 @@ namespace ariles2
7272
}
7373
catch (const std::exception &e)
7474
{
75-
CPPUT_THROW("entry: " + name + " // " + std::string(e.what()));
75+
CPPUT_THROW("entry: ", name, " // ", std::string(e.what()));
7676
}
7777
}
7878
};

include/ariles2/visitors/read.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ namespace ariles2
8585
std::string file_name_default = file_name;
8686
config_ifs.open(file_name_default.c_str());
8787
}
88-
CPPUT_PERSISTENT_ASSERT(
89-
config_ifs.good(), std::string("Could not open configuration file: ") + file_name.c_str());
88+
CPPUT_PERSISTENT_ASSERT(config_ifs.good(), "Could not open configuration file: ", file_name.c_str());
9089
}
9190

9291

@@ -419,9 +418,7 @@ namespace ariles2
419418
}
420419
catch (const std::exception &e)
421420
{
422-
CPPUT_THROW(
423-
std::string("Failed to parse entry <") + convertSubtreeToString(subtree) + "> || "
424-
+ e.what());
421+
CPPUT_THROW("Failed to parse entry <", convertSubtreeToString(subtree), "> || ", e.what());
425422
}
426423

427424
this->endRoot(subtree);
@@ -430,8 +427,9 @@ namespace ariles2
430427
{
431428
CPPUT_PERSISTENT_ASSERT(
432429
param.allow_missing_entries_,
433-
std::string("Configuration file does not contain entry '") + convertSubtreeToString(subtree)
434-
+ "'.");
430+
"Configuration file does not contain entry '",
431+
convertSubtreeToString(subtree),
432+
"'.");
435433
}
436434
}
437435

@@ -455,7 +453,7 @@ namespace ariles2
455453
}
456454
catch (const std::exception &e)
457455
{
458-
CPPUT_THROW(std::string("Failed to parse entry <") + name + "> || " + e.what());
456+
CPPUT_THROW("Failed to parse entry <", name, "> || ", e.what());
459457
}
460458

461459
this->endMapEntry();
@@ -465,7 +463,9 @@ namespace ariles2
465463
{
466464
CPPUT_PERSISTENT_ASSERT(
467465
not override_missing_entries_locally and param.allow_missing_entries_,
468-
std::string("Configuration file does not contain entry '") + name + "'.");
466+
"Configuration file does not contain entry '",
467+
name,
468+
"'.");
469469
return (false);
470470
}
471471
}

include/ariles2/visitors/write.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ namespace ariles2
5656
config_ofs.open(file_name.c_str());
5757

5858
CPPUT_PERSISTENT_ASSERT(
59-
config_ofs.good(),
60-
std::string("Could not open configuration file for writing: ") + file_name.c_str());
59+
config_ofs.good(), "Could not open configuration file for writing: ", file_name.c_str());
6160
}
6261

6362

0 commit comments

Comments
 (0)