string file work
This commit is contained in:
parent
913a9f6430
commit
0051760884
1
doc/TODO
1
doc/TODO
@ -10,7 +10,6 @@ matrix:
|
|||||||
2:capability query
|
2:capability query
|
||||||
2:revision query
|
2:revision query
|
||||||
1:ability to select specification revision
|
1:ability to select specification revision
|
||||||
1:change password
|
|
||||||
1:register account
|
1:register account
|
||||||
1:device management
|
1:device management
|
||||||
client:
|
client:
|
||||||
|
|||||||
@ -26,45 +26,6 @@
|
|||||||
namespace raii{
|
namespace raii{
|
||||||
|
|
||||||
class string_expr{};
|
class string_expr{};
|
||||||
class string_base;
|
|
||||||
|
|
||||||
namespace detail{
|
|
||||||
std::true_type is_string_helper(string_expr);
|
|
||||||
std::false_type is_string_helper(...);
|
|
||||||
template<class T>
|
|
||||||
struct is_string{
|
|
||||||
static constexpr bool value = std::is_same<std::true_type,decltype(is_string_helper(std::declval<T>()))>::value;
|
|
||||||
};
|
|
||||||
std::true_type is_string_base(string_base*);
|
|
||||||
std::false_type is_string_base(...);
|
|
||||||
template<class T>
|
|
||||||
struct is_concrete_string{
|
|
||||||
static constexpr bool value = std::is_same<std::true_type,decltype(is_string_base(std::declval<typename std::decay<T>::type*>()))>::value;
|
|
||||||
};
|
|
||||||
template<class... Args>
|
|
||||||
std::true_type is_tuple_helper(std::tuple<Args...>);
|
|
||||||
std::false_type is_tuple_helper(...);
|
|
||||||
template<class T>
|
|
||||||
struct is_tuple{
|
|
||||||
static constexpr bool value = std::is_same<std::true_type,decltype(is_tuple_helper(std::declval<T>()))>::value;
|
|
||||||
};
|
|
||||||
|
|
||||||
//check for member function 'length'
|
|
||||||
template<class T>
|
|
||||||
struct has_len{
|
|
||||||
template<class U, class V>
|
|
||||||
struct check;
|
|
||||||
|
|
||||||
template<class U>
|
|
||||||
static std::true_type test(check<U,decltype(&U::length)>*);
|
|
||||||
template<class U>
|
|
||||||
static std::false_type test(...);
|
|
||||||
|
|
||||||
static constexpr bool value = std::is_same<std::true_type,decltype(test<T>(0))>::value;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Base of all RAII strings. Its use is allowing passing of raii strings to functions without knowing the exact type
|
//Base of all RAII strings. Its use is allowing passing of raii strings to functions without knowing the exact type
|
||||||
class string_base : public string_expr
|
class string_base : public string_expr
|
||||||
@ -166,19 +127,6 @@ namespace raii{
|
|||||||
constexpr const Right& right(void)const;
|
constexpr const Right& right(void)const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class Targ>
|
|
||||||
struct appender
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
Targ& m_targ;
|
|
||||||
size_t m_pos = 0;
|
|
||||||
public:
|
|
||||||
appender(Targ& t);
|
|
||||||
template<class L, class R>
|
|
||||||
void operator()(const string_cat_expr<L,R>& str);
|
|
||||||
void operator()(const string_base& str);
|
|
||||||
};
|
|
||||||
|
|
||||||
class static_string : public string_base
|
class static_string : public string_base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -196,6 +144,54 @@ namespace raii{
|
|||||||
static_string& operator=(static_string&&) = delete;
|
static_string& operator=(static_string&&) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
namespace detail{
|
||||||
|
std::true_type is_string_helper(string_expr);
|
||||||
|
std::false_type is_string_helper(...);
|
||||||
|
template<class T>
|
||||||
|
struct is_string{
|
||||||
|
static constexpr bool value = std::is_same<std::true_type,decltype(is_string_helper(std::declval<T>()))>::value;
|
||||||
|
};
|
||||||
|
std::true_type is_string_base(string_base*);
|
||||||
|
std::false_type is_string_base(...);
|
||||||
|
template<class T>
|
||||||
|
struct is_concrete_string{
|
||||||
|
static constexpr bool value = std::is_same<std::true_type,decltype(is_string_base(std::declval<typename std::decay<T>::type*>()))>::value;
|
||||||
|
};
|
||||||
|
template<class... Args>
|
||||||
|
std::true_type is_tuple_helper(std::tuple<Args...>);
|
||||||
|
std::false_type is_tuple_helper(...);
|
||||||
|
template<class T>
|
||||||
|
struct is_tuple{
|
||||||
|
static constexpr bool value = std::is_same<std::true_type,decltype(is_tuple_helper(std::declval<T>()))>::value;
|
||||||
|
};
|
||||||
|
|
||||||
|
//check for member function 'length'
|
||||||
|
template<class T>
|
||||||
|
struct has_len{
|
||||||
|
template<class U, class V>
|
||||||
|
struct check;
|
||||||
|
|
||||||
|
template<class U>
|
||||||
|
static std::true_type test(check<U,decltype(&U::length)>*);
|
||||||
|
template<class U>
|
||||||
|
static std::false_type test(...);
|
||||||
|
|
||||||
|
static constexpr bool value = std::is_same<std::true_type,decltype(test<T>(0))>::value;
|
||||||
|
};
|
||||||
|
template<class Targ>
|
||||||
|
struct appender
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Targ& m_targ;
|
||||||
|
size_t m_pos = 0;
|
||||||
|
public:
|
||||||
|
appender(Targ& t);
|
||||||
|
template<class L, class R>
|
||||||
|
void operator()(const string_cat_expr<L,R>& str);
|
||||||
|
void operator()(const string_base& str);
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "raii/string_base.tpp"
|
#include "raii/string_base.tpp"
|
||||||
|
|||||||
@ -177,7 +177,7 @@ namespace raii{
|
|||||||
string_intermediary<Alloc> ret(length());
|
string_intermediary<Alloc> ret(length());
|
||||||
for(size_t i = 0;i < length();++i)
|
for(size_t i = 0;i < length();++i)
|
||||||
ret[i] = 'n';
|
ret[i] = 'n';
|
||||||
appender<string_intermediary<Alloc>> append(ret);
|
detail::appender<string_intermediary<Alloc>> append(ret);
|
||||||
append(*this);
|
append(*this);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -191,6 +191,17 @@ namespace raii{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<size_t N>
|
||||||
|
constexpr static_string::static_string(const char(&str)[N]):
|
||||||
|
string_base(const_cast<char*>(str), N){}
|
||||||
|
constexpr static_string::static_string(const char* str, size_t len):
|
||||||
|
string_base(const_cast<char*>(str), len){}
|
||||||
|
constexpr static_string::static_string(const static_string& s):
|
||||||
|
string_base(s.m_data, s.m_length){}
|
||||||
|
constexpr static_string::static_string(static_string&& s):
|
||||||
|
string_base(s.m_data, s.m_length){}
|
||||||
|
|
||||||
|
namespace detail{
|
||||||
template<class Targ>
|
template<class Targ>
|
||||||
appender<Targ>::appender(Targ& t): m_targ(t){}
|
appender<Targ>::appender(Targ& t): m_targ(t){}
|
||||||
template<class Targ>
|
template<class Targ>
|
||||||
@ -204,16 +215,7 @@ namespace raii{
|
|||||||
memcpy(m_targ.get()+m_pos, str.get(), str.length());
|
memcpy(m_targ.get()+m_pos, str.get(), str.length());
|
||||||
m_pos += str.length();
|
m_pos += str.length();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
template<size_t N>
|
|
||||||
constexpr static_string::static_string(const char(&str)[N]):
|
|
||||||
string_base(const_cast<char*>(str), N){}
|
|
||||||
constexpr static_string::static_string(const char* str, size_t len):
|
|
||||||
string_base(const_cast<char*>(str), len){}
|
|
||||||
constexpr static_string::static_string(const static_string& s):
|
|
||||||
string_base(s.m_data, s.m_length){}
|
|
||||||
constexpr static_string::static_string(static_string&& s):
|
|
||||||
string_base(s.m_data, s.m_length){}
|
|
||||||
|
|
||||||
} //namespace raii
|
} //namespace raii
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user