Browse Source

add methods to Space that take a pointer to a string along with the length

Space::Space(const char * str, size_t len)
Space::Space(const wchar_t * str, size_t len)
Space::set(const char * str, size_t len)
Space::set(const wchar_t * str, size_t len)
Space::add_to_table(const char * val, size_t len)
Space::add_to_table(const wchar_t * val, size_t len)
Space::add(const wchar_t * field, const char * val, size_t len)
Space::add(const wchar_t * field, const wchar_t * val, size_t len)
Space::add(const std::wstring & field, const char * val, size_t len)
Space::add(const std::wstring & field, const wchar_t * val, size_t len)
master
Tomasz Sowa 4 months ago
parent
commit
84e9e6f98f
  1. 108
      src/space/space.cpp
  2. 44
      src/space/space.h

108
src/space/space.cpp

@ -161,12 +161,24 @@ Space::Space(const char * str)
set(str);
}
Space::Space(const char * str, size_t len)
{
initialize();
set(str, len);
}
Space::Space(const wchar_t * str)
{
initialize();
set(str);
}
Space::Space(const wchar_t * str, size_t len)
{
initialize();
set(str, len);
}
Space::Space(const std::string & str)
{
initialize();
@ -383,6 +395,19 @@ void Space::set(const char * str)
}
}
void Space::set(const char * str, size_t len)
{
if( str == nullptr )
{
initialize_value_null_if_needed();
}
else
{
initialize_value_string_if_needed();
value.value_string.assign(str, len);
}
}
void Space::set(const wchar_t * str)
{
if( str == nullptr )
@ -396,6 +421,19 @@ void Space::set(const wchar_t * str)
}
}
void Space::set(const wchar_t * str, size_t len)
{
if( str == nullptr )
{
initialize_value_null_if_needed();
}
else
{
initialize_value_wstring_if_needed();
value.value_wstring.assign(str, len);
}
}
void Space::set(const std::string & str)
{
initialize_value_string_if_needed();
@ -504,11 +542,21 @@ Space & Space::add(const char * val)
return add_generic(val);
}
Space & Space::add_to_table(const char * val, size_t len)
{
return add_generic_len(val, len);
}
Space & Space::add(const wchar_t * val)
{
return add_generic(val);
}
Space & Space::add_to_table(const wchar_t * val, size_t len)
{
return add_generic_len(val, len);
}
Space & Space::add(const std::string & val)
{
return add_generic(val);
@ -617,11 +665,21 @@ Space & Space::add(const wchar_t * field, const char * val)
return add_generic(field, val);
}
Space & Space::add(const wchar_t * field, const char * val, size_t len)
{
return add_generic_len(field, val, len);
}
Space & Space::add(const wchar_t * field, const wchar_t * val)
{
return add_generic(field, val);
}
Space & Space::add(const wchar_t * field, const wchar_t * val, size_t len)
{
return add_generic_len(field, val, len);
}
Space & Space::add(const wchar_t * field, const std::string & val)
{
return add_generic(field, val);
@ -676,92 +734,102 @@ Space & Space::add_empty_space(const wchar_t * field)
Space & Space::add(const std::wstring & field, bool val)
{
return add_generic(field, val);
return add_generic_string(field, val);
}
Space & Space::add(const std::wstring & field, short val)
{
return add_generic(field, val);
return add_generic_string(field, val);
}
Space & Space::add(const std::wstring & field, int val)
{
return add_generic(field, val);
return add_generic_string(field, val);
}
Space & Space::add(const std::wstring & field, long val)
{
return add_generic(field, val);
return add_generic_string(field, val);
}
Space & Space::add(const std::wstring & field, long long val)
{
return add_generic(field, val);
return add_generic_string(field, val);
}
Space & Space::add(const std::wstring & field, unsigned short val)
{
return add_generic(field, val);
return add_generic_string(field, val);
}
Space & Space::add(const std::wstring & field, unsigned int val)
{
return add_generic(field, val);
return add_generic_string(field, val);
}
Space & Space::add(const std::wstring & field, unsigned long val)
{
return add_generic(field, val);
return add_generic_string(field, val);
}
Space & Space::add(const std::wstring & field, unsigned long long val)
{
return add_generic(field, val);
return add_generic_string(field, val);
}
Space & Space::add(const std::wstring & field, float val)
{
return add_generic(field, val);
return add_generic_string(field, val);
}
Space & Space::add(const std::wstring & field, double val)
{
return add_generic(field, val);
return add_generic_string(field, val);
}
Space & Space::add(const std::wstring & field, long double val)
{
return add_generic(field, val);
return add_generic_string(field, val);
}
Space & Space::add(const std::wstring & field, const char * val)
{
return add_generic(field, val);
return add_generic_string(field, val);
}
Space & Space::add(const std::wstring & field, const char * val, size_t len)
{
return add_generic_string_len(field, val, len);
}
Space & Space::add(const std::wstring & field, const wchar_t * val)
{
return add_generic(field, val);
return add_generic_string(field, val);
}
Space & Space::add(const std::wstring & field, const wchar_t * val, size_t len)
{
return add_generic_string_len(field, val, len);
}
Space & Space::add(const std::wstring & field, const std::string & val)
{
return add_generic(field, val);
return add_generic_string(field, val);
}
Space & Space::add(const std::wstring & field, const std::wstring & val)
{
return add_generic(field, val);
return add_generic_string(field, val);
}
Space & Space::add(const std::wstring & field, const Space & space)
{
return add_generic(field, space);
return add_generic_string(field, space);
}
Space & Space::add(const std::wstring & field, const Space * space)
{
return add_generic(field, space);
return add_generic_string(field, space);
}
Space & Space::add(const std::wstring & field, Space && space)
@ -771,12 +839,12 @@ Space & Space::add(const std::wstring & field, Space && space)
Space & Space::add(const std::wstring & field, const Date & date)
{
return add_generic(field, date);
return add_generic_string(field, date);
}
Space & Space::add_empty_space(const std::wstring & field)
{
return add_generic(field, static_cast<Space*>(nullptr));
return add_generic_string(field, static_cast<Space*>(nullptr));
}

44
src/space/space.h

@ -200,7 +200,9 @@ public:
Space(double val);
Space(long double val);
Space(const char * str);
Space(const char * str, size_t len);
Space(const wchar_t * str);
Space(const wchar_t * str, size_t len);
Space(const std::string & str);
Space(const std::wstring & str);
Space(const Space * space);
@ -235,7 +237,9 @@ public:
void set(double val);
void set(long double val);
void set(const char * str);
void set(const char * str, size_t len);
void set(const wchar_t * str);
void set(const wchar_t * str, size_t len);
void set(const std::string & str);
void set(const std::wstring & str);
void set(const Space & space);
@ -258,7 +262,9 @@ public:
Space & add(double val);
Space & add(long double val);
Space & add(const char * val);
Space & add_to_table(const char * val, size_t len); // the name add would collapse with add(const char * field, unsigned long val) below;
Space & add(const wchar_t * val);
Space & add_to_table(const wchar_t * val, size_t len); // the name add would collapse with add(const wchar_t * field, unsigned long val) below;
Space & add(const std::string & val);
Space & add(const std::wstring & val);
Space & add(const Space & space);
@ -283,7 +289,9 @@ public:
Space & add(const wchar_t * field, double val);
Space & add(const wchar_t * field, long double val);
Space & add(const wchar_t * field, const char * val);
Space & add(const wchar_t * field, const char * val, size_t len);
Space & add(const wchar_t * field, const wchar_t * val);
Space & add(const wchar_t * field, const wchar_t * val, size_t len);
Space & add(const wchar_t * field, const std::string & val);
Space & add(const wchar_t * field, const std::wstring & val);
Space & add(const wchar_t * field, const Space & space);
@ -306,6 +314,8 @@ public:
Space & add(const std::wstring & field, long double val);
Space & add(const std::wstring & field, const char * val);
Space & add(const std::wstring & field, const wchar_t * val);
Space & add(const std::wstring & field, const char * val, size_t len);
Space & add(const std::wstring & field, const wchar_t * val, size_t len);
Space & add(const std::wstring & field, const std::string & val);
Space & add(const std::wstring & field, const std::wstring & val);
Space & add(const std::wstring & field, const Space & space);
@ -653,6 +663,16 @@ protected:
return *value.value_table.back();
}
template<typename ArgType>
Space & add_generic_len(const ArgType & val, size_t len)
{
initialize_value_table_if_needed();
Space * new_space = new Space(val, len);
value.value_table.push_back(new_space);
return *value.value_table.back();
}
template<typename ArgType>
Space & add_generic(const wchar_t * field, const ArgType & val)
@ -672,13 +692,35 @@ protected:
return *(insert_res.first->second);
}
template<typename ArgType>
Space & add_generic_len(const wchar_t * field, const ArgType & val, size_t len)
{
initialize_value_object_if_needed();
auto insert_res = value.value_object.insert(std::make_pair(field, nullptr));
if( insert_res.second )
{
insert_res.first->second = new Space(val, len);
}
else
{
insert_res.first->second->set(val, len);
}
return *(insert_res.first->second);
}
template<typename ArgType>
Space & add_generic(const std::wstring & field, const ArgType & val)
Space & add_generic_string(const std::wstring & field, const ArgType & val)
{
return add_generic(field.c_str(), val);
}
template<typename ArgType>
Space & add_generic_string_len(const std::wstring & field, const ArgType & val, size_t len)
{
return add_generic_len(field.c_str(), val, len);
}
template<typename ArgType>
ArgType to_generic_numeric_signed_value() const

Loading…
Cancel
Save