7 #ifndef _STRINGLIST_CLASS_HEADER_
8 #define _STRINGLIST_CLASS_HEADER_
19 template<
class storageT>
32 typedef typename tStringList::iterator
iterator;
47 return m_lstList.begin();
52 return m_lstList.end();
57 return m_lstList.cbegin();
62 return m_lstList.cend();
67 return m_lstList.cbegin();
72 return m_lstList.cend();
77 return m_lstList.rbegin();
82 return m_lstList.rend();
87 return m_lstList.crbegin();
92 return m_lstList.crend();
145 nStartPos = nPos + 1;
146 nPosComma = strList.Find(
",", nStartPos);
147 nPosSemicolon = strList.Find(
";", nStartPos);
151 nPosComma < nPosSemicolon ? nPos = nPosComma : nPos = nPosSemicolon;
155 nPos = nPosSemicolon;
166 lstList.
m_lstList.emplace_back(strList.Mid(nStartPos, nPos - nStartPos));
170 lstList.
m_lstList.emplace_back(storageT(
""));
172 nPos += nTokenLen - 1;
176 if (nStartPos < strList.GetLength())
178 lstList.
m_lstList.emplace_back(strList.Mid(nStartPos));
180 else if (strList.EndsWith(
",") || strList.EndsWith(
";"))
182 lstList.
m_lstList.emplace_back(storageT(
""));
193 for (
const auto& itElem : lstStrings)
261 if (m_lstList.size() > 0)
279 m_lstList.push_back(strString);
295 auto oIt = lstString.
cbegin();
297 oIt != lstString.
cend();
319 if (InvalidPos != Find(strString))
341 tInt nAddedCount = 0;
342 for (
auto it = lstString.
begin();
343 it != lstString.
end();
376 if (nIdx < m_lstList.size())
378 m_lstList.insert(m_lstList.begin() + nIdx, strString);
399 if (nIdx < m_lstList.size())
401 m_lstList.erase(m_lstList.begin() + nIdx);
422 if (0 > strFirst.CompareNoCase(strSecond))
446 std::sort(m_lstList.begin(), m_lstList.end());
450 std::sort(m_lstList.begin(), m_lstList.end(), fnSortLexically);
462 return m_lstList.size();
475 const storageT&
Get(
tSize nIdx,
const storageT& strDefault =
"")
const
477 if (nIdx < GetItemCount())
479 const storageT& strRet = m_lstList[nIdx];
498 if (InvalidPos == nIdx)
500 return ERR_INVALID_ARG;
502 else if (nIdx < GetItemCount())
504 m_lstList[nIdx] = strValue;
508 m_lstList.push_back(strValue);
527 return std::distance(cbegin(), it);
543 tSize nMatchType = 0;
545 tSize nLen = strPattern.GetLength();
547 if (!strPattern.IsEmpty())
549 const tChar* ptr = strPattern.GetPtr();
557 if (*(ptr + strPattern.GetLength() - 1) ==
'*')
566 return Find(strPattern);
569 storageT strSubStr = strPattern.Mid(nStart, nLen);
573 typename tStringList::const_iterator l_poI;
574 for (l_poI = m_lstList.begin(); l_poI != m_lstList.end(); ++l_poI)
579 strItem = (*l_poI).Right(nLen);
580 if (strItem.IsEqual(strSubStr))
585 else if (nMatchType == 2)
588 strItem = (*l_poI).Left(nLen);
589 if (strItem.IsEqual(strSubStr))
594 else if (nMatchType == 3)
597 strItem = (*l_poI).Mid(nStart, nLen);
624 typename tStringList::const_iterator l_poI;
625 for (l_poI = m_lstList.begin(); l_poI != m_lstList.end(); ++l_poI)
627 if (strString.CompareNoCase(*l_poI) == 0)
647 storageT
Join(
const storageT& strSeparator)
const
649 storageT l_strString;
652 typename tStringList::const_iterator l_poI;
653 for (l_poI = m_lstList.begin(); l_poI != m_lstList.end(); ++l_poI)
657 l_strString.Append(strSeparator);
664 l_strString.Append(*l_poI);
680 return m_lstList.empty();
696 return m_lstList[nIdx];
702 return m_lstList[nIdx];
707 if (oList.GetItemCount() == GetItemCount())
709 _myType::const_iterator itRHS = oList.cbegin();
710 for (_myType::const_iterator itLHS = cbegin(); itLHS != cend();)
712 if (*itRHS != *itLHS)
728 using cStringList = string_list_base<cString>;
char tChar
The tChar defines the type for platform character set (platform and compiler dependent type).
void tVoid
The tVoid is always the definition for the void (non-type).
int tInt
type definition for signed integer value (platform and compiler dependent type).
bool tBool
The tBool defines the type for the Values tTrue and tFalse (platform and compiler dependent).
size_t tSize
type definition for a array size values, map size values etc.
constexpr tSize g_npos
npos size declaration
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
#define RETURN_ERROR(code)
Return specific error code, which requires the calling function's return type to be tResult.
#define IS_OK(s)
Check if result is OK.
A common result class usable as return value throughout.
static const tSize InvalidPos
used to identicate out of range, invalidpos or default length
string_list_base(const _myType &lstList)
Constructor that duplicates an existing string list.
tSize Match(const storageT &strPattern) const
Returns the index of the string matching a pattern.
tResult Append(const _myType &lstString)
This function appends the given list of strings to the list.
tSize Find(const storageT &strString) const
This function returns the position of a string inside the list.
storageT & operator[](tSize nIdx)
This function retrieves a string value from the list.
const_iterator begin() const
Return const_iterator to beginning.
tResult Append(const storageT &strString)
This function appends one string to the list.
const_iterator cbegin() const
Return iterator to beginning.
tVoid Copy(const _myType &lstList)
This function copies the content of an existing string list to this cStringList object.
tVoid Sort(tBool bIgnoreCase=tFalse)
This function arranges the list elements.
tSize FindNoCase(const storageT &strString) const
This function returns the position of a string inside the list.
tResult Delete(tSize nIdx)
This function removes one item from the list.
tStringList::const_iterator const_iterator
short typedefinition for cString lists iterators
string_list_base(const storageT &strList)
Constructor that creates string list from comma or semicolon-delimited string.
tResult Insert(tSize nIdx, const storageT &strString)
This function inserts a string to the list at a specified position.
storageT Join(const storageT &strSeparator) const
This function concatenates all list elements to one single cString object.
reverse_iterator rend()
Return reverse iterator to reverse end.
std::vector< storageT > tStringList
list of containing cStrings
const storageT & Get(tSize nIdx, const storageT &strDefault="") const
This function retrieves a string value from the list.
tResult Add(const storageT &strString)
This function appends one string to the list only if the strString is not yet part of the list.
tStringList::reverse_iterator reverse_iterator
short typedefinition for cString lists reverse iterators
const storageT & operator[](tSize nIdx) const
This function retrieves a string value from the list.
const_reverse_iterator crbegin() const
Return reverse const_iterator to reverse beginning.
tStringList::iterator iterator
short typedefinition for cString lists iterators
const_iterator cend() const
Return iterator to end.
tResult Set(tSize nIdx, const storageT &strValue)
This function stores a string value into the list.
string_list_base(_myType &&lstList)
Constructor that duplicates an existing string list.
tVoid Clear()
This function cleans up the list and frees all allocated memory blocks.
static tBool fnSortLexically(const storageT &strFirst, const storageT &strSecond)
Checks if two strings are sorted lexically.
tStringList m_lstList
Internally used string list.
tSize GetItemCount() const
This function returns the number of items the list contains.
string_list_base()
Constructor that initializes an empty cStringList object.
tBool IsEmpty() const
This function checks if the string object is empty.
string_list_base & operator=(const _myType &lstList)
The cStringList assignment (=) operator reinitializes existing string lists with an existing object.
const_reverse_iterator crend() const
Return reverse const_iterator to reverse end.
virtual ~string_list_base()
Destructor.
string_list_base & operator=(_myType &&lstList)
The cStringList assignment (=) operator reinitializes existing string lists with an existing object.
tStringList::const_reverse_iterator const_reverse_iterator
short typedefinition for cString lists reverse iterators
iterator end()
Return iterator to end.
const_iterator end() const
Return const_iterator to end.
reverse_iterator rbegin()
Return reverse iterator to reverse beginning.
iterator begin()
Return iterator to beginning.
tResult Add(const _myType &lstString)
This function appends strings of the given list to the list only if the string is not yet part of the...
string_list_base< storageT > _myType
definition of my type
#define tFalse
Value for tBool.
#define tTrue
Value for tBool.
ADTF A_UTIL Namespace - Within adtf this is used as adtf::util or adtf_util.
tBool operator==(const cMultiArrayIndex &o_A, const cMultiArrayIndex &o_B)
Comparison operator.