ZenLib
|
00001 /* Copyright (c) MediaArea.net SARL. All Rights Reserved. 00002 * 00003 * Use of this source code is governed by a zlib-style license that can 00004 * be found in the License.txt file in the root of the source tree. 00005 */ 00006 00007 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00008 // 00009 // More methods for std::vector<std::vector<std::(w)string>> 00010 // 00011 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00012 00013 //--------------------------------------------------------------------------- 00014 #ifndef ZenLib_ZtringListListH 00015 #define ZenLib_ZtringListListH 00016 //--------------------------------------------------------------------------- 00017 00018 //--------------------------------------------------------------------------- 00019 #include "ZenLib/ZtringList.h" 00020 //--------------------------------------------------------------------------- 00021 00022 namespace ZenLib 00023 { 00024 00025 //*************************************************************************** 00026 /// @brief Vector of vectors of strings manipulation (based on std::vector<std::vector<std::(w)string>>) 00027 //*************************************************************************** 00028 00029 class ZtringListList : public std::vector<ZtringList> 00030 { 00031 public : 00032 //Constructors/Destructor 00033 ZtringListList (); 00034 ZtringListList (const ZtringListList &Source); 00035 ZtringListList (const Ztring &Source); 00036 ZtringListList (const Char *Source); 00037 #ifdef _UNICODE 00038 ZtringListList (const char *Source); //convert a UTF-8 string into Unicode 00039 #endif 00040 00041 //Operateurs 00042 bool operator == (const ZtringListList &Source) const; 00043 bool operator != (const ZtringListList &Source) const; 00044 ZtringListList &operator += (const ZtringListList &Source); 00045 ZtringListList &operator = (const ZtringListList &Source); 00046 00047 ZtringList &operator () (size_type Pos0); ///< Same as [], but write a empty string if Pos doesn't exist yet 00048 Ztring &operator () (size_type Pos0, size_type Pos1); 00049 /// @brief Return [Pos][Pos1], Pos=First occurency of Pos0 in [xxx][0] 00050 Ztring &operator () (const Ztring &Pos0, size_type Pos1=1) {return operator() (Pos0, 0 , Pos1);}; 00051 /// @brief Return [Pos][Pos1], Pos=First occurency of Pos0 in [xxx][Pos0_1] 00052 Ztring &operator () (const Ztring &Pos0, size_type Pos0_1, size_type Pos1); 00053 00054 //In/Out 00055 /// @brief Read all 00056 Ztring Read () const; 00057 /// @brief Read a vector of string 00058 Ztring Read (size_type Pos0) const; 00059 /// @brief Read a string 00060 const Ztring &Read (size_type Pos0, size_type Pos1) const; 00061 /// @brief Return [Pos][Pos1], Pos=First occurency of Pos0 in [xxx][0] 00062 const Ztring &Read (const Ztring &Pos0, size_type Pos1=1) const; 00063 /// @brief Return [Pos][Pos1], Pos=First occurency of Pos0 in [xxx][Pos0_1] 00064 const Ztring &Read (const Ztring &Pos0, size_type Pos0_1, size_type Pos1) const; 00065 /// @brief Return [Pos][Pos1], Pos=First occurency of Pos0 in [xxx][0], with default value 00066 const Ztring &Read (const Ztring &Pos0, const Ztring &Default, size_type Pos1=1) const; 00067 /// @brief Return [Pos][Pos1], Pos=First occurency of Pos0 in [xxx][Pos0_1], with default value 00068 const Ztring &Read (const Ztring &Pos0, const Ztring &Default, size_type Pos0_1, size_type Pos1) const; 00069 /// @brief Read all strings at position Pos1 00070 Ztring Read1 (size_type Pos1) const; 00071 00072 /// @brief Write all 00073 void Write (const Ztring &ToWrite); 00074 /// @brief Write a vector of string 00075 void Write (const ZtringList &ToWrite, size_type Pos0); 00076 /// @brief Write a vector of string 00077 void Write (const Ztring &ToWrite, size_type Pos0, size_type Pos1); 00078 /// @brief Add a vector of string 00079 void push_back (const ZtringList &ToAdd); 00080 /// @brief Add a vector of string (with separator is ZtringListList Separator) 00081 void push_back (const Ztring &ToAdd); 00082 /// @brief Add a vector of string (Char version) 00083 void push_back (const Char* ToAdd) {push_back(Ztring(ToAdd));}; 00084 /// @brief Insert a vector of string at position Pos0 00085 void Insert (const ZtringList &ToInsert, size_type Pos0) {insert(begin()+Pos0, ToInsert);}; 00086 /// @brief Insert a string at all positions Pos1 00087 void Insert1 (const Ztring &ToInsert, size_type Pos1); 00088 /// @brief Delete a vector of string at position Pos0 00089 void Delete (size_type Pos0) {erase(begin()+Pos0);}; 00090 /// @brief Delete all vectors of string, with [xxx][Pos1] == ToFind 00091 void Delete (const Ztring &ToFind, size_type Pos1=0, const Ztring &Comparator=__T("=="), ztring_t Options=Ztring_Nothing); 00092 /// @brief Delete a string at all positions Pos1 00093 void Delete1 (size_type Pos1); 00094 00095 //Edition 00096 /// @brief Swap 2 positions 00097 void Swap (size_type Pos0_A, size_type Pos0_B); 00098 /// @brief Swap 2 columns for each line 00099 void Swap1 (size_type Pos1_A, size_type Pos1_B); 00100 /// @brief Sort 00101 void Sort (size_type Pos1, ztring_t Options=Ztring_Nothing); 00102 00103 //Information 00104 /// @brief Find the first position of the string in the vector of vector, in a specific column 00105 size_type Find (const Ztring &ToFind, size_type Pos1=0, size_type Pos0Begin=0) const; 00106 /// @brief Find the first position of the string in the vector of vector, in a specific column, which is not empty 00107 size_type Find_Filled (size_type Pos1=0, size_type Pos0Begin=0) const; 00108 /// @brief Find the first position of the string in the vector of vector, in a specific column 00109 size_type Find (const Ztring &ToFind, size_type Pos1, size_type Pos0Begin, const Ztring &Comparator, ztring_t Options=Ztring_Nothing) const; 00110 /// @brief Return [xxx][Pos1Value] when founded the first position of the string in the vector of vector, in a specific column 00111 Ztring FindValue (const Ztring &ToFind, size_type Pos1Value=1, size_type Pos1=0, size_type Pos0Begin=0, const Ztring &Comparator=__T("=="), ztring_t Options=Ztring_Nothing) const; 00112 /// @brief Return a subsheet, with all lines with position of the string in the vector of vector, in a specific column 00113 ZtringListList SubSheet (const Ztring &ToFind, size_type Pos1=0, size_type Pos0Begin=0, const Ztring &Comparator=__T("=="), ztring_t Options=Ztring_Nothing) const; 00114 00115 //Configuration 00116 /// @brief Set the Separator character 00117 void Separator_Set (size_type Level, const Ztring &NewSeparator); 00118 /// @brief Set the Quote character 00119 /// During Read() or Write() method, if Separator is in the sequence, we must quote it 00120 void Quote_Set (const Ztring &NewQuote); 00121 /// @brief Set the Maximum number of element to read 00122 /// During Read() or Write() method, if there is more elements, merge them with the last element 00123 void Max_Set (size_type Level, size_type Max); 00124 00125 protected : 00126 Ztring Separator[2]; 00127 Ztring Quote; 00128 size_type Max[2]; 00129 }; 00130 00131 } //namespace 00132 #endif