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:revision query
|
||||
1:ability to select specification revision
|
||||
1:change password
|
||||
1:register account
|
||||
1:device management
|
||||
client:
|
||||
|
||||
@ -26,45 +26,6 @@
|
||||
namespace raii{
|
||||
|
||||
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
|
||||
class string_base : public string_expr
|
||||
@ -166,19 +127,6 @@ namespace raii{
|
||||
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
|
||||
{
|
||||
public:
|
||||
@ -196,6 +144,54 @@ namespace raii{
|
||||
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"
|
||||
|
||||
@ -177,7 +177,7 @@ namespace raii{
|
||||
string_intermediary<Alloc> ret(length());
|
||||
for(size_t i = 0;i < length();++i)
|
||||
ret[i] = 'n';
|
||||
appender<string_intermediary<Alloc>> append(ret);
|
||||
detail::appender<string_intermediary<Alloc>> append(ret);
|
||||
append(*this);
|
||||
return ret;
|
||||
}
|
||||
@ -191,20 +191,6 @@ namespace raii{
|
||||
}
|
||||
|
||||
|
||||
template<class Targ>
|
||||
appender<Targ>::appender(Targ& t): m_targ(t){}
|
||||
template<class Targ>
|
||||
template<class L, class R>
|
||||
void appender<Targ>::operator()(const string_cat_expr<L,R>& str){
|
||||
(*this)(str.left());
|
||||
(*this)(str.right());
|
||||
}
|
||||
template<class Targ>
|
||||
void appender<Targ>::operator()(const string_base& str){
|
||||
memcpy(m_targ.get()+m_pos, str.get(), 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){}
|
||||
@ -215,6 +201,22 @@ namespace raii{
|
||||
constexpr static_string::static_string(static_string&& s):
|
||||
string_base(s.m_data, s.m_length){}
|
||||
|
||||
namespace detail{
|
||||
template<class Targ>
|
||||
appender<Targ>::appender(Targ& t): m_targ(t){}
|
||||
template<class Targ>
|
||||
template<class L, class R>
|
||||
void appender<Targ>::operator()(const string_cat_expr<L,R>& str){
|
||||
(*this)(str.left());
|
||||
(*this)(str.right());
|
||||
}
|
||||
template<class Targ>
|
||||
void appender<Targ>::operator()(const string_base& str){
|
||||
memcpy(m_targ.get()+m_pos, str.get(), str.length());
|
||||
m_pos += str.length();
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace raii
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user