Skip to content

Commit 9534cd1

Browse files
author
ranga.code
committed
templatified to reduce num lines.
1 parent cdf98bb commit 9534cd1

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/yavl.cpp

+26-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@ namespace YAVL {
1818
{
1919
return "string";
2020
}
21+
22+
template <>
23+
std::string ctype2str<long long>()
24+
{
25+
return "long long";
26+
}
27+
28+
template <>
29+
std::string ctype2str<unsigned int>()
30+
{
31+
return "unsigned int";
32+
}
33+
34+
template <>
35+
std::string ctype2str<int>()
36+
{
37+
return "int";
38+
}
39+
2140
}
2241

2342
ostream& operator << (ostream& os, const Path& path)
@@ -129,6 +148,12 @@ bool Validator::validate_leaf(const YAML::Node &gr, const YAML::Node &doc)
129148
attempt_to_convert<string>(doc, ok);
130149
} else if (type == "uint64") {
131150
attempt_to_convert<unsigned long long>(doc, ok);
151+
} else if (type == "int64") {
152+
attempt_to_convert<long long>(doc, ok);
153+
} else if (type == "int") {
154+
attempt_to_convert<int>(doc, ok);
155+
} else if (type == "uint") {
156+
attempt_to_convert<unsigned int>(doc, ok);
132157
} else if (type == "enum") {
133158
ok = false;
134159
string docValue = doc;
@@ -139,7 +164,7 @@ bool Validator::validate_leaf(const YAML::Node &gr, const YAML::Node &doc)
139164
}
140165
}
141166
if (!ok) {
142-
string reason = "enum string " + docValue + " is not allowed.";
167+
string reason = "enum string '" + docValue + "' is not allowed.";
143168
gen_error(Exception(reason, gr_path, doc_path));
144169
}
145170
}

src/yavl.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ namespace YAVL
5757
scalar_node >> tmp;
5858
ok = true;
5959
} catch (const YAML::InvalidScalar& e) {
60-
std::string reason = "unable to convert to " + YAVL::ctype2str<T>();
60+
std::string s = scalar_node;
61+
std::string reason = "unable to convert '" + s + "' to '" + YAVL::ctype2str<T>() + "'.";
6162
gen_error(Exception(reason, gr_path, doc_path));
6263
ok = false;
6364
}

0 commit comments

Comments
 (0)