The Pedigree Project  0.1
Cord.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef KERNEL_UTILITIES_CORD_H
21 #define KERNEL_UTILITIES_CORD_H
22 
26 #include "pedigree/kernel/compiler.h"
27 #include "pedigree/kernel/processor/types.h"
28 #include "pedigree/kernel/utilities/template.h" // IWYU pragma: keep
29 #include "pedigree/kernel/utilities/Vector.h"
30 
31 class String;
32 
34 {
35  friend class CordIterator;
36  public:
38  {
39  friend class Cord;
40  public:
41  CordIterator(const Cord &owner);
42  virtual ~CordIterator();
43 
46 
47  char operator*() const;
48 
49  bool operator==(const CordIterator &other) const;
50  bool operator!=(const CordIterator &other) const;
51 
52  protected:
53  CordIterator(const Cord &owner, bool end);
54 
55  private:
56  const Cord &cord;
57  size_t segment;
58  size_t index;
59  };
60 
61  Cord();
62  Cord(const Cord &other);
63  virtual ~Cord();
64 
65  Cord &operator=(const Cord &s);
66 
67  bool operator==(const char *s) const;
68  bool operator==(const Cord &s) const;
69  bool operator==(const String &s) const;
70 
75  void reserve(size_t segments);
76 
77  void assign(const Cord &other);
78  void clear();
79 
80  size_t length() const;
81 
82  String toString() const;
83 
84  char operator[](size_t index) const;
85 
86  void append(const char *s, size_t len=0);
87  void prepend(const char *s, size_t len=0);
88 
89  CordIterator begin() const;
90  CordIterator end() const;
91 
92  private:
93  struct CordSegment
94  {
95  CordSegment() = default;
96  CordSegment(const char *s, size_t len) : ptr(s), length(len) {}
97 
98  const char *ptr = nullptr;
99  size_t length = 0;
100  };
101 
102  Vector<CordSegment> m_Segments;
103  size_t m_Length = 0;
104 };
105 
108 #endif // KERNEL_UTILITIES_CORD_H
A vector / dynamic array.
char operator[](size_t index) const
Definition: Cord.cc:89
void reserve(size_t segments)
Definition: Cord.cc:44
Definition: String.h:49
T operator++(T &x, int)
Global postincrement operator for types with overloaded preincrement operator.
Definition: template.h:41
Definition: Cord.h:33
T operator--(T &x, int)
Global postdecrement operator for types with overloaded predecrement operator.
Definition: template.h:52
bool operator==(const Iterator< originalT, Struct, FunctionPrev, FunctionNext, T1 > &x1, const Iterator< originalT, Struct, FunctionPrev, FunctionNext, T2 > &x2)
Definition: Iterator.h:326
bool operator!=(const T1 &x1, const T2 &x2)
Global != operator for types with overloaded == operator.
Definition: template.h:32