ZenLib
ZtringListList.h
Go to the documentation of this file.
1 // ZenLib::ZtringListList - More methods for std::vector<std::vector<std::(w)string>>
2 // Copyright (C) 2002-2011 MediaArea.net SARL, Info@MediaArea.net
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 //
8 // Permission is granted to anyone to use this software for any purpose,
9 // including commercial applications, and to alter it and redistribute it
10 // freely, subject to the following restrictions:
11 //
12 // 1. The origin of this software must not be misrepresented; you must not
13 // claim that you wrote the original software. If you use this software
14 // in a product, an acknowledgment in the product documentation would be
15 // appreciated but is not required.
16 // 2. Altered source versions must be plainly marked as such, and must not be
17 // misrepresented as being the original software.
18 // 3. This notice may not be removed or altered from any source distribution.
19 //
20 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 //
22 // More methods for std::vector<std::vector<std::(w)string>>
23 //
24 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
25 
26 //---------------------------------------------------------------------------
27 #ifndef ZenLib_ZtringListListH
28 #define ZenLib_ZtringListListH
29 //---------------------------------------------------------------------------
30 
31 //---------------------------------------------------------------------------
32 #include "ZenLib/ZtringList.h"
33 //---------------------------------------------------------------------------
34 
35 namespace ZenLib
36 {
37 
38 //***************************************************************************
39 /// @brief Vector of vectors of strings manipulation (based on std::vector<std::vector<std::(w)string>>)
40 //***************************************************************************
41 
42 class ZtringListList : public std::vector<ZtringList>
43 {
44 public :
45  //Constructors/Destructor
46  ZtringListList ();
47  ZtringListList (const ZtringListList &Source);
48  ZtringListList (const Ztring &Source);
49  ZtringListList (const Char *Source);
50  #ifdef _UNICODE
51  ZtringListList (const char *Source); //convert a UTF-8 string into Unicode
52  #endif
53 
54  //Operateurs
55  bool operator == (const ZtringListList &Source) const;
56  bool operator != (const ZtringListList &Source) const;
59 
60  ZtringList &operator () (size_type Pos0); ///< Same as [], but write a empty string if Pos doesn't exist yet
61  Ztring &operator () (size_type Pos0, size_type Pos1);
62  /// @brief Return [Pos][Pos1], Pos=First occurency of Pos0 in [xxx][0]
63  Ztring &operator () (const Ztring &Pos0, size_type Pos1=1) {return operator() (Pos0, 0 , Pos1);};
64  /// @brief Return [Pos][Pos1], Pos=First occurency of Pos0 in [xxx][Pos0_1]
65  Ztring &operator () (const Ztring &Pos0, size_type Pos0_1, size_type Pos1);
66 
67  //In/Out
68  /// @brief Read all
69  Ztring Read () const;
70  /// @brief Read a vector of string
71  Ztring Read (size_type Pos0) const;
72  /// @brief Read a string
73  const Ztring &Read (size_type Pos0, size_type Pos1) const;
74  /// @brief Return [Pos][Pos1], Pos=First occurency of Pos0 in [xxx][0]
75  const Ztring &Read (const Ztring &Pos0, size_type Pos1=1) const;
76  /// @brief Return [Pos][Pos1], Pos=First occurency of Pos0 in [xxx][Pos0_1]
77  const Ztring &Read (const Ztring &Pos0, size_type Pos0_1, size_type Pos1) const;
78  /// @brief Return [Pos][Pos1], Pos=First occurency of Pos0 in [xxx][0], with default value
79  const Ztring &Read (const Ztring &Pos0, const Ztring &Default, size_type Pos1=1) const;
80  /// @brief Return [Pos][Pos1], Pos=First occurency of Pos0 in [xxx][Pos0_1], with default value
81  const Ztring &Read (const Ztring &Pos0, const Ztring &Default, size_type Pos0_1, size_type Pos1) const;
82  /// @brief Read all strings at position Pos1
83  Ztring Read1 (size_type Pos1) const;
84 
85  /// @brief Write all
86  void Write (const Ztring &ToWrite);
87  /// @brief Write a vector of string
88  void Write (const ZtringList &ToWrite, size_type Pos0);
89  /// @brief Write a vector of string
90  void Write (const Ztring &ToWrite, size_type Pos0, size_type Pos1);
91  /// @brief Add a vector of string
92  void push_back (const ZtringList &ToAdd);
93  /// @brief Add a vector of string (with separator is ZtringListList Separator)
94  void push_back (const Ztring &ToAdd);
95  /// @brief Add a vector of string (Char version)
96  void push_back (const Char* ToAdd) {push_back(Ztring(ToAdd));};
97  /// @brief Insert a vector of string at position Pos0
98  void Insert (const ZtringList &ToInsert, size_type Pos0) {insert(begin()+Pos0, ToInsert);};
99  /// @brief Insert a string at all positions Pos1
100  void Insert1 (const Ztring &ToInsert, size_type Pos1);
101  /// @brief Delete a vector of string at position Pos0
102  void Delete (size_type Pos0) {erase(begin()+Pos0);};
103  /// @brief Delete all vectors of string, with [xxx][Pos1] == ToFind
104  void Delete (const Ztring &ToFind, size_type Pos1=0, const Ztring &Comparator=__T("=="), ztring_t Options=Ztring_Nothing);
105  /// @brief Delete a string at all positions Pos1
106  void Delete1 (size_type Pos1);
107 
108  //Edition
109  /// @brief Swap 2 positions
110  void Swap (size_type Pos0_A, size_type Pos0_B);
111  /// @brief Swap 2 columns for each line
112  void Swap1 (size_type Pos1_A, size_type Pos1_B);
113  /// @brief Sort
114  void Sort (size_type Pos1, ztring_t Options=Ztring_Nothing);
115 
116  //Information
117  /// @brief Find the first position of the string in the vector of vector, in a specific column
118  size_type Find (const Ztring &ToFind, size_type Pos1=0, size_type Pos0Begin=0) const;
119  /// @brief Find the first position of the string in the vector of vector, in a specific column, which is not empty
120  size_type Find_Filled (size_type Pos1=0, size_type Pos0Begin=0) const;
121  /// @brief Find the first position of the string in the vector of vector, in a specific column
122  size_type Find (const Ztring &ToFind, size_type Pos1, size_type Pos0Begin, const Ztring &Comparator, ztring_t Options=Ztring_Nothing) const;
123  /// @brief Return [xxx][Pos1Value] when founded the first position of the string in the vector of vector, in a specific column
124  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;
125  /// @brief Return a subsheet, with all lines with position of the string in the vector of vector, in a specific column
126  ZtringListList SubSheet (const Ztring &ToFind, size_type Pos1=0, size_type Pos0Begin=0, const Ztring &Comparator=__T("=="), ztring_t Options=Ztring_Nothing) const;
127 
128  //Configuration
129  /// @brief Set the Separator character
130  void Separator_Set (size_type Level, const Ztring &NewSeparator);
131  /// @brief Set the Quote character
132  /// During Read() or Write() method, if Separator is in the sequence, we must quote it
133  void Quote_Set (const Ztring &NewQuote);
134  /// @brief Set the Maximum number of element to read
135  /// During Read() or Write() method, if there is more elements, merge them with the last element
136  void Max_Set (size_type Level, size_type Max);
137 
138 protected :
141  size_type Max[2];
142 };
143 
144 } //namespace
145 #endif
146