1 #ifndef UTIL___TEXT_JOINER__HPP
2 #define UTIL___TEXT_JOINER__HPP
59 template <
size_t num_prealloc,
typename TIn =
string,
60 typename TOut = basic_string<typename TIn::value_type> >
76 template<
size_t num_prealloc,
typename TIn,
typename TOut>
85 if (m_MainStorageUsage < num_prealloc) {
86 m_MainStorage[m_MainStorageUsage++] = s;
87 }
else if (m_ExtraStorage.get() !=
NULL) {
89 Warning <<
"exceeding anticipated count "
91 m_ExtraStorage->push_back(s);
93 m_ExtraStorage.reset(
new vector<TIn>(1, s));
100 template<
size_t num_prealloc,
typename TIn,
typename TOut>
105 for (
size_t i = 0;
i < m_MainStorageUsage; ++
i) {
106 size_needed += m_MainStorage[
i].size();
108 if (m_ExtraStorage.get() !=
NULL) {
109 ITERATE (
typename vector<TIn>, it, *m_ExtraStorage) {
110 size_needed += it->size();
115 result->reserve(size_needed);
116 for (
size_t i = 0;
i < m_MainStorageUsage; ++
i) {
117 result->append(m_MainStorage[
i].data(), m_MainStorage[
i].
size());
119 if (m_ExtraStorage.get() !=
NULL) {
120 ITERATE (
typename vector<TIn>, it, *m_ExtraStorage) {
121 result->append(it->data(), it->size());
CTextJoiner<> – template for efficiently collecting and joining strings.
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define ERR_POST_XX_ONCE(error_name, err_subcode, message)
Error posting only once during program execution with given error code name and given error subcode.
void Warning(CExceptionArgs_Base &args)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
NCBI_NS_STD::string::size_type SIZE_TYPE
CTextJoiner & Add(const TIn &s)
size_t m_MainStorageUsage
void Join(TOut *result) const
TIn m_MainStorage[num_prealloc]
unique_ptr< vector< TIn > > m_ExtraStorage
Definition of all error codes used in util (xutil.lib).
const struct ncbi::grid::netcache::search::fields::SIZE size