small changes with default values

This commit is contained in:
Niels 2015-02-07 19:04:08 +01:00
parent c1c3e72c96
commit cc274f8145
2 changed files with 40 additions and 44 deletions

View file

@ -196,25 +196,25 @@ class basic_json
case (value_t::string): case (value_t::string):
{ {
m_value.string = new string_t(); m_value.string = new string_t("");
break; break;
} }
case (value_t::boolean): case (value_t::boolean):
{ {
m_value.boolean = boolean_t(); m_value.boolean = boolean_t(false);
break; break;
} }
case (value_t::number_integer): case (value_t::number_integer):
{ {
m_value.number_integer = number_integer_t(); m_value.number_integer = number_integer_t(0);
break; break;
} }
case (value_t::number_float): case (value_t::number_float):
{ {
m_value.number_float = number_float_t(); m_value.number_float = number_float_t(0.0);
break; break;
} }
} }
@ -737,7 +737,7 @@ class basic_json
/// find an element in an object /// find an element in an object
iterator find(typename object_t::key_type key) inline iterator find(typename object_t::key_type key)
{ {
auto result = end(); auto result = end();
@ -750,7 +750,7 @@ class basic_json
} }
/// find an element in an object /// find an element in an object
const_iterator find(typename object_t::key_type key) const inline const_iterator find(typename object_t::key_type key) const
{ {
auto result = cend(); auto result = cend();
@ -829,22 +829,20 @@ class basic_json
{ {
return true; return true;
} }
case (value_t::number_integer):
case (value_t::number_float):
case (value_t::boolean):
case (value_t::string):
{
return false;
}
case (value_t::array): case (value_t::array):
{ {
return m_value.array->empty(); return m_value.array->empty();
} }
case (value_t::object): case (value_t::object):
{ {
return m_value.object->empty(); return m_value.object->empty();
} }
} }
// all other types are nonempty
return false;
} }
/// returns the number of elements /// returns the number of elements
@ -856,22 +854,20 @@ class basic_json
{ {
return 0; return 0;
} }
case (value_t::number_integer):
case (value_t::number_float):
case (value_t::boolean):
case (value_t::string):
{
return 1;
}
case (value_t::array): case (value_t::array):
{ {
return m_value.array->size(); return m_value.array->size();
} }
case (value_t::object): case (value_t::object):
{ {
return m_value.object->size(); return m_value.object->size();
} }
} }
// all other types have size 1
return 1;
} }
/// returns the maximum possible number of elements /// returns the maximum possible number of elements
@ -883,22 +879,20 @@ class basic_json
{ {
return 0; return 0;
} }
case (value_t::number_integer):
case (value_t::number_float):
case (value_t::boolean):
case (value_t::string):
{
return 1;
}
case (value_t::array): case (value_t::array):
{ {
return m_value.array->max_size(); return m_value.array->max_size();
} }
case (value_t::object): case (value_t::object):
{ {
return m_value.object->max_size(); return m_value.object->max_size();
} }
} }
// all other types have max_size 1
return 1;
} }
@ -917,17 +911,17 @@ class basic_json
} }
case (value_t::number_integer): case (value_t::number_integer):
{ {
m_value.number_integer = {}; m_value.number_integer = 0;
break; break;
} }
case (value_t::number_float): case (value_t::number_float):
{ {
m_value.number_float = {}; m_value.number_float = 0.0;
break; break;
} }
case (value_t::boolean): case (value_t::boolean):
{ {
m_value.boolean = {}; m_value.boolean = false;
break; break;
} }
case (value_t::string): case (value_t::string):
@ -2554,13 +2548,14 @@ class basic_json
case (token_type::value_number): case (token_type::value_number):
{ {
// The pointer current_re2c points to the beginning of the parsed // The pointer current_re2c points to the beginning of the
// number. We pass this pointer to std::strtod which sets endptr // parsed number. We pass this pointer to std::strtod which
// to the first character past the converted number. If this pointer // sets endptr to the first character past the converted
// is not the same as buffer_re2c, then either more or less // number. If this pointer is not the same as buffer_re2c,
// characters have been used during the comparison. This can happen // then either more or less characters have been used
// for inputs like "01" which will be treated like number 0 followed // during the comparison. This can happen for inputs like
// by number 1. // "01" which will be treated like number 0 followed by
// number 1.
// conversion // conversion
char* endptr; char* endptr;

View file

@ -2548,13 +2548,14 @@ class basic_json
case (token_type::value_number): case (token_type::value_number):
{ {
// The pointer current_re2c points to the beginning of the parsed // The pointer current_re2c points to the beginning of the
// number. We pass this pointer to std::strtod which sets endptr // parsed number. We pass this pointer to std::strtod which
// to the first character past the converted number. If this pointer // sets endptr to the first character past the converted
// is not the same as buffer_re2c, then either more or less // number. If this pointer is not the same as buffer_re2c,
// characters have been used during the comparison. This can happen // then either more or less characters have been used
// for inputs like "01" which will be treated like number 0 followed // during the comparison. This can happen for inputs like
// by number 1. // "01" which will be treated like number 0 followed by
// number 1.
// conversion // conversion
char* endptr; char* endptr;