00001 // ZenLib::ZtringList - More methods for vector<std::(w)string> 00002 // Copyright (C) 2002-2009 Jerome Martinez, Zen@MediaArea.net 00003 // 00004 // This software is provided 'as-is', without any express or implied 00005 // warranty. In no event will the authors be held liable for any damages 00006 // arising from the use of this software. 00007 // 00008 // Permission is granted to anyone to use this software for any purpose, 00009 // including commercial applications, and to alter it and redistribute it 00010 // freely, subject to the following restrictions: 00011 // 00012 // 1. The origin of this software must not be misrepresented; you must not 00013 // claim that you wrote the original software. If you use this software 00014 // in a product, an acknowledgment in the product documentation would be 00015 // appreciated but is not required. 00016 // 2. Altered source versions must be plainly marked as such, and must not be 00017 // misrepresented as being the original software. 00018 // 3. This notice may not be removed or altered from any source distribution. 00019 // 00020 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00021 // 00022 // More methods for std::vector<std::(w)string> 00023 // 00024 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00025 00026 //--------------------------------------------------------------------------- 00027 #ifndef ZenLib_ZtringListH 00028 #define ZenLib_ZtringListH 00029 //--------------------------------------------------------------------------- 00030 00031 //--------------------------------------------------------------------------- 00032 #include "ZenLib/Ztring.h" 00033 #include <vector> 00034 //--------------------------------------------------------------------------- 00035 00036 namespace ZenLib 00037 { 00038 00039 //*************************************************************************** 00040 /// @brief Vector of strings manipulation (based on std::vector<std::(w)string>) 00041 //*************************************************************************** 00042 00043 class ZtringList : public std::vector<Ztring> 00044 { 00045 public : 00046 //Constructors/destructor 00047 ZtringList (); 00048 ZtringList (const ZtringList &Source); 00049 ZtringList (const Ztring &Source); 00050 ZtringList (const Char *Source); 00051 #ifdef _UNICODE 00052 ZtringList (const char *Source); //convert a UTF-8 string into Unicode 00053 #endif 00054 00055 //Operators 00056 bool operator == (const ZtringList &Source) const; 00057 bool operator != (const ZtringList &Source) const; 00058 ZtringList &operator += (const ZtringList &Source); 00059 ZtringList &operator = (const ZtringList &Source); 00060 00061 Ztring &operator () (size_type Pos); ///< Same as [], but write a empty string if Pos doesn't exist yet 00062 00063 //In/out 00064 Ztring Read () const; /// Read all 00065 const Ztring &Read (size_type Pos) const; /// Read a string 00066 void Write (const Ztring &ToWrite); /// Write all 00067 void Write (const Ztring &ToWrite, size_type Pos); /// Write a string 00068 /// @brief Insert a string at position Pos0 00069 void Insert (const Ztring &ToInsert, size_type Pos0) {insert(begin()+Pos0, ToInsert);}; 00070 /// @brief Delete a string at position Pos0 00071 void Delete (size_type Pos0) {erase(begin()+Pos0);}; 00072 00073 //Edition 00074 /// @brief Swap 2 positions 00075 void Swap (size_type Pos0_A, size_type Pos0_B); 00076 /// @brief Sort 00077 void Sort (ztring_t Options=Ztring_Nothing); 00078 00079 //Information 00080 /// @brief Find the position of the string in the vector 00081 size_type Find (const Ztring &ToFind, size_type PosBegin=0, const Ztring &Comparator=_T("=="), ztring_t Options=Ztring_Nothing) const; 00082 /// @brief Return the length of the longest string in the list. 00083 size_type MaxStringLength_Get (); 00084 00085 //Configuration 00086 /// @brief Set the Separator character 00087 void Separator_Set (size_type Level, const Ztring &NewSeparator); 00088 /// @brief Set the Quote character 00089 /// During Read() or Write() method, if Separator is in the sequence, we must quote it 00090 void Quote_Set (const Ztring &NewQuote); 00091 /// @brief Set the Maximum number of element to read 00092 /// During Read() or Write() method, if there is more elements, merge them with the last element 00093 void Max_Set (size_type Level, size_type Max_New); 00094 00095 protected : 00096 Ztring Separator[1]; 00097 Ztring Quote; 00098 size_type Max[1]; 00099 }; 00100 00101 } //namespace 00102 #endif 00103