/src/mozilla-central/xpcom/string/nsTDependentString.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef nsTDependentString_h |
8 | | #define nsTDependentString_h |
9 | | |
10 | | #include "nsTString.h" |
11 | | |
12 | | /** |
13 | | * nsTDependentString |
14 | | * |
15 | | * Stores a null-terminated, immutable sequence of characters. |
16 | | * |
17 | | * Subclass of nsTString that restricts string value to an immutable |
18 | | * character sequence. This class does not own its data, so the creator |
19 | | * of objects of this type must take care to ensure that a |
20 | | * nsTDependentString continues to reference valid memory for the |
21 | | * duration of its use. |
22 | | */ |
23 | | template <typename T> |
24 | | class nsTDependentString : public nsTString<T> |
25 | | { |
26 | | public: |
27 | | |
28 | | typedef nsTDependentString<T> self_type; |
29 | | typedef nsTString<T> base_string_type; |
30 | | typedef typename base_string_type::string_type string_type; |
31 | | |
32 | | typedef typename base_string_type::fallible_t fallible_t; |
33 | | |
34 | | typedef typename base_string_type::char_type char_type; |
35 | | typedef typename base_string_type::char_traits char_traits; |
36 | | typedef typename base_string_type::incompatible_char_type incompatible_char_type; |
37 | | |
38 | | typedef typename base_string_type::substring_tuple_type substring_tuple_type; |
39 | | |
40 | | typedef typename base_string_type::const_iterator const_iterator; |
41 | | typedef typename base_string_type::iterator iterator; |
42 | | |
43 | | typedef typename base_string_type::comparator_type comparator_type; |
44 | | |
45 | | typedef typename base_string_type::const_char_iterator const_char_iterator; |
46 | | |
47 | | typedef typename base_string_type::index_type index_type; |
48 | | typedef typename base_string_type::size_type size_type; |
49 | | |
50 | | // These are only for internal use within the string classes: |
51 | | typedef typename base_string_type::DataFlags DataFlags; |
52 | | typedef typename base_string_type::ClassFlags ClassFlags; |
53 | | |
54 | | public: |
55 | | |
56 | | /** |
57 | | * constructors |
58 | | */ |
59 | | |
60 | | nsTDependentString(const char_type* aStart, const char_type* aEnd); |
61 | | |
62 | | nsTDependentString(const char_type* aData, uint32_t aLength) |
63 | | : string_type(const_cast<char_type*>(aData), aLength, |
64 | | DataFlags::TERMINATED, ClassFlags(0)) |
65 | 204k | { |
66 | 204k | this->AssertValidDependentString(); |
67 | 204k | } |
68 | | |
69 | | #if defined(MOZ_USE_CHAR16_WRAPPER) |
70 | | template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>> |
71 | | nsTDependentString(char16ptr_t aData, uint32_t aLength) |
72 | | : nsTDependentString(static_cast<const char16_t*>(aData), aLength) |
73 | | { |
74 | | } |
75 | | #endif |
76 | | |
77 | | explicit |
78 | | nsTDependentString(const char_type* aData) |
79 | | : string_type(const_cast<char_type*>(aData), |
80 | | uint32_t(char_traits::length(aData)), |
81 | | DataFlags::TERMINATED, ClassFlags(0)) |
82 | 205k | { |
83 | 205k | string_type::AssertValidDependentString(); |
84 | 205k | } |
85 | | |
86 | | #if defined(MOZ_USE_CHAR16_WRAPPER) |
87 | | template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>> |
88 | | explicit |
89 | | nsTDependentString(char16ptr_t aData) |
90 | | : nsTDependentString(static_cast<const char16_t*>(aData)) |
91 | | { |
92 | | } |
93 | | #endif |
94 | | |
95 | | nsTDependentString(const string_type& aStr, uint32_t aStartPos) |
96 | | : string_type() |
97 | 0 | { |
98 | 0 | Rebind(aStr, aStartPos); |
99 | 0 | } Unexecuted instantiation: nsTDependentString<char>::nsTDependentString(nsTString<char> const&, unsigned int) Unexecuted instantiation: nsTDependentString<char16_t>::nsTDependentString(nsTString<char16_t> const&, unsigned int) |
100 | | |
101 | | // Create a nsTDependentSubstring to be bound later |
102 | | nsTDependentString() |
103 | | : string_type() |
104 | 0 | { |
105 | 0 | } Unexecuted instantiation: nsTDependentString<char>::nsTDependentString() Unexecuted instantiation: nsTDependentString<char16_t>::nsTDependentString() |
106 | | |
107 | | // auto-generated destructor OK |
108 | | |
109 | | nsTDependentString(self_type&& aStr) |
110 | | : string_type() |
111 | 0 | { |
112 | 0 | Rebind(aStr, /* aStartPos = */ 0); |
113 | 0 | aStr.SetToEmptyBuffer(); |
114 | 0 | } Unexecuted instantiation: nsTDependentString<char>::nsTDependentString(nsTDependentString<char>&&) Unexecuted instantiation: nsTDependentString<char16_t>::nsTDependentString(nsTDependentString<char16_t>&&) |
115 | | |
116 | | explicit |
117 | | nsTDependentString(const self_type& aStr) |
118 | | : string_type() |
119 | 0 | { |
120 | 0 | Rebind(aStr, /* aStartPos = */ 0); |
121 | 0 | } Unexecuted instantiation: nsTDependentString<char>::nsTDependentString(nsTDependentString<char> const&) Unexecuted instantiation: nsTDependentString<char16_t>::nsTDependentString(nsTDependentString<char16_t> const&) |
122 | | |
123 | | /** |
124 | | * allow this class to be bound to a different string... |
125 | | */ |
126 | | |
127 | | using nsTString<T>::Rebind; |
128 | | void Rebind(const char_type* aData) |
129 | 0 | { |
130 | 0 | Rebind(aData, uint32_t(char_traits::length(aData))); |
131 | 0 | } Unexecuted instantiation: nsTDependentString<char>::Rebind(char const*) Unexecuted instantiation: nsTDependentString<char16_t>::Rebind(char16_t const*) |
132 | | |
133 | | void Rebind(const char_type* aStart, const char_type* aEnd); |
134 | | void Rebind(const string_type&, uint32_t aStartPos); |
135 | | |
136 | | private: |
137 | | |
138 | | // NOT USED |
139 | | nsTDependentString(const substring_tuple_type&) = delete; |
140 | | self_type& operator=(const self_type& aStr) = delete; |
141 | | }; |
142 | | |
143 | | extern template class nsTDependentString<char>; |
144 | | extern template class nsTDependentString<char16_t>; |
145 | | |
146 | | #endif |