9 static const char rcsid[] __attribute__((used)) =
"$Id: Nullable.cpp 1653 2016-02-28 19:54:59Z sella $";
12 #include "../util/CommonMacro.h"
14 using namespace sella::variant;
16 Nullable::Nullable() throw () :
20 Nullable::Nullable(std::shared_ptr<void> &value)
throw () :
24 Nullable::Nullable(std::shared_ptr<void> &&value) throw () :
25 value(std::move(value))
28 Nullable::~Nullable() throw () { }
30 void Nullable::shrink_to_fit() throw () {
33 bool Nullable::isNull()
const throw () {
34 return (this->value == NULL);
37 std::vector<std::string> Nullable::tokenize(
const std::string &value,
const boost::regex &pattern)
const throw (TypeCastException) {
38 std::vector<std::string> tokens;
41 if (UNLIKELY(!boost::regex_match(value, match, pattern))) {
42 if (value.at(0) ==
'[') {
43 THROW(TypeCastException,
"unable to tokenize vector '%s'", value.c_str());
44 }
else if (value.at(0) ==
'{') {
45 THROW(TypeCastException,
"unable to tokenize object '%s'", value.c_str());
47 THROW(TypeCastException,
"unable to tokenize '%s'", value.c_str());
51 const std::string &data = match[1].str();
53 auto begin = data.begin();
58 for (
auto it = data.begin(), end = data.end(); it != end; ++it) {
70 tokens.push_back(std::string(begin, it + 1));
81 case ' ':
case '\t':
case '\r':
case '\n':
case '\f':
84 tokens.push_back(std::string(begin, it));
90 case '[':
case ']':
case '{':
case '}':
case ',':
case ':':
93 tokens.push_back(std::string(begin, it));
95 tokens.push_back(std::string(1, *it));
101 if (!str && end == std::next(it)) {
102 tokens.push_back(std::string(begin, end));