ZenLib
ZtringList.h
Go to the documentation of this file.
1 // ZenLib::ZtringList - More methods for 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::(w)string>
23 //
24 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
25 
26 //---------------------------------------------------------------------------
27 #ifndef ZenLib_ZtringListH
28 #define ZenLib_ZtringListH
29 //---------------------------------------------------------------------------
30 
31 //---------------------------------------------------------------------------
32 #include "ZenLib/Ztring.h"
33 #include <vector>
34 //---------------------------------------------------------------------------
35 
36 namespace ZenLib
37 {
38 
39 //***************************************************************************
40 /// @brief Vector of strings manipulation (based on std::vector<std::(w)string>)
41 //***************************************************************************
42 
43 class ZtringList : public std::vector<Ztring>
44 {
45 public :
46  //Constructors/destructor
47  ZtringList ();
48  ZtringList (const ZtringList &Source);
49  ZtringList (const Ztring &Source);
50  ZtringList (const Char *Source);
51  #ifdef _UNICODE
52  ZtringList (const char *Source); //convert a UTF-8 string into Unicode
53  #endif
54 
55  //Operators
56  bool operator == (const ZtringList &Source) const;
57  bool operator != (const ZtringList &Source) const;
58  ZtringList &operator += (const ZtringList &Source);
59  ZtringList &operator = (const ZtringList &Source);
60 
61  Ztring &operator () (size_type Pos); ///< Same as [], but write a empty string if Pos doesn't exist yet
62 
63  //In/out
64  Ztring Read () const; /// Read all
65  const Ztring &Read (size_type Pos) const; /// Read a string
66  void Write (const Ztring &ToWrite); /// Write all
67  void Write (const Ztring &ToWrite, size_type Pos); /// Write a string
68  /// @brief Insert a string at position Pos0
69  void Insert (const Ztring &ToInsert, size_type Pos0) {insert(begin()+Pos0, ToInsert);};
70  /// @brief Delete a string at position Pos0
71  void Delete (size_type Pos0) {erase(begin()+Pos0);};
72 
73  //Edition
74  /// @brief Swap 2 positions
75  void Swap (size_type Pos0_A, size_type Pos0_B);
76  /// @brief Sort
77  void Sort (ztring_t Options=Ztring_Nothing);
78 
79  //Information
80  /// @brief Find the position of the string in the vector
81  size_type Find (const Ztring &ToFind, size_type PosBegin=0, const Ztring &Comparator=__T("=="), ztring_t Options=Ztring_Nothing) const;
82  /// @brief Return the length of the longest string in the list.
83  size_type MaxStringLength_Get ();
84 
85  //Configuration
86  /// @brief Set the Separator character
87  void Separator_Set (size_type Level, const Ztring &NewSeparator);
88  /// @brief Set the Quote character
89  /// During Read() or Write() method, if Separator is in the sequence, we must quote it
90  void Quote_Set (const Ztring &NewQuote);
91  /// @brief Set the Maximum number of element to read
92  /// During Read() or Write() method, if there is more elements, merge them with the last element
93  void Max_Set (size_type Level, size_type Max_New);
94 
95 protected :
98  size_type Max[1];
99 };
100 
101 } //namespace
102 #endif
103