AAX SDK 2.8.0
Avid Audio Extensions Development Kit
Loading...
Searching...
No Matches
AAX_CString.h
Go to the documentation of this file.
1/*================================================================================================*/
2/*
3 *
4 * Copyright 2013-2015, 2017, 2021, 2023-2024 Avid Technology, Inc.
5 * All rights reserved.
6 *
7 * This file is part of the Avid AAX SDK.
8 *
9 * The AAX SDK is subject to commercial or open-source licensing.
10 *
11 * By using the AAX SDK, you agree to the terms of both the Avid AAX SDK License
12 * Agreement and Avid Privacy Policy.
13 *
14 * AAX SDK License: https://developer.avid.com/aax
15 * Privacy Policy: https://www.avid.com/legal/privacy-policy-statement
16 *
17 * Or: You may also use this code under the terms of the GPL v3 (see
18 * www.gnu.org/licenses).
19 *
20 * THE AAX SDK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 * EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 * DISCLAIMED.
23 *
24 */
25
32/*================================================================================================*/
33
34#pragma once
35
36#ifndef AAX_CSTRING_H
37#define AAX_CSTRING_H
38
39
40#include "AAX_IString.h"
41#include "AAX.h"
42
43#include <string>
44#include <map>
45
46
48#if 0
49#pragma mark -
50#endif
52
57{
58public:
59 static const uint32_t kInvalidIndex = static_cast<uint32_t>(-1);
60 static const uint32_t kMaxStringLength = static_cast<uint32_t>(-2);
61
62 // AAX_IString Virtual Overrides
63 uint32_t Length() const AAX_OVERRIDE;
64 uint32_t MaxLength() const AAX_OVERRIDE;
65 const char * Get () const AAX_OVERRIDE;
66 void Set ( const char * iString ) AAX_OVERRIDE;
67 AAX_IString & operator=(const AAX_IString & iOther) AAX_OVERRIDE;
68 AAX_IString & operator=(const char * iString) AAX_OVERRIDE;
69
72
74 AAX_CString(const char* str);
75
77 explicit AAX_CString(const std::string& str);
78
80 AAX_CString(const AAX_CString& other);
81
83 AAX_CString(const AAX_IString& other);
84
87
88
90 std::string& StdString();
91
93 const std::string& StdString() const;
94
96 AAX_CString& operator=(const AAX_CString& other);
97
99 AAX_CString & operator=(const std::string& other);
100
102 AAX_CString & operator=(AAX_CString&& other);
103
105 friend std::ostream& operator<< (std::ostream& os, const AAX_CString& str);
106
108 friend std::istream& operator>> (std::istream& os, AAX_CString& str);
109
110
111 // String Formatting Functions
112 void Clear();
113 bool Empty() const;
114 AAX_CString& Erase(uint32_t pos, uint32_t n);
116 AAX_CString& Append(const char* str);
117 AAX_CString& AppendNumber(double number, int32_t precision);
118 AAX_CString& AppendNumber(int32_t number);
119 AAX_CString& AppendHex(int32_t number, int32_t width);
120 AAX_CString& Insert(uint32_t pos, const AAX_CString& str);
121 AAX_CString& Insert(uint32_t pos, const char* str);
122 AAX_CString& InsertNumber(uint32_t pos, double number, int32_t precision);
123 AAX_CString& InsertNumber(uint32_t pos, int32_t number);
124 AAX_CString& InsertHex(uint32_t pos, int32_t number, int32_t width);
125 AAX_CString& Replace(uint32_t pos, uint32_t n, const AAX_CString& str);
126 AAX_CString& Replace(uint32_t pos, uint32_t n, const char* str);
127 uint32_t FindFirst(const AAX_CString& findStr) const;
128 uint32_t FindFirst(const char* findStr) const;
129 uint32_t FindFirst(char findChar) const;
130 uint32_t FindLast(const AAX_CString& findStr) const;
131 uint32_t FindLast(const char* findStr) const;
132 uint32_t FindLast(char findChar) const;
133 const char* CString() const;
134 bool ToDouble(double* oValue) const;
135 bool ToInteger(int32_t* oValue) const;
136 void SubString(uint32_t pos, uint32_t n, AAX_IString* outputStr) const;
137 bool Equals(const AAX_CString& other) const { return operator==(other); }
138 bool Equals(const char* other) const { return operator==(other); }
139 bool Equals(const std::string& other) const { return operator==(other); } //beware of STL variations between binaries.
140
141 // Operator Overrides
142 bool operator==(const AAX_CString& other) const;
143 bool operator==(const char* otherStr) const;
144 bool operator==(const std::string& otherStr) const; //beware of STL variations between binaries.
145 bool operator!=(const AAX_CString& other) const;
146 bool operator!=(const char* otherStr) const;
147 bool operator!=(const std::string& otherStr) const; //beware of STL variations between binaries.
148 bool operator<(const AAX_CString& other) const;
149 bool operator>(const AAX_CString& other) const;
150 const char& operator[](uint32_t index) const;
151 char& operator[](uint32_t index);
153 AAX_CString& operator+=(const std::string& str);
154 AAX_CString& operator+=(const char* str);
155
156protected:
157 std::string mString;
158};
159
160// Non-member operators
162{
163 lhs += rhs;
164 return lhs;
165}
166inline AAX_CString operator+(AAX_CString lhs, const char* rhs)
167{
168 lhs += rhs;
169 return lhs;
170}
171inline AAX_CString operator+(const char* lhs, const AAX_CString& rhs)
172{
173 return AAX_CString(lhs) + rhs;
174}
175
176
178#if 0
179#pragma mark -
180#endif
182
186{
187public:
188 explicit AAX_CStringAbbreviations(const AAX_CString& inPrimary)
189 : mPrimary(inPrimary)
190 , mAbbreviations()
191 {
192 }
193
194 void SetPrimary(const AAX_CString& inPrimary) { mPrimary = inPrimary; }
195 const AAX_CString& Primary() const { return mPrimary; }
196
197 void Add(const AAX_CString& inAbbreviation)
198 {
199 uint32_t stringLength = inAbbreviation.Length();
200 mAbbreviations[stringLength] = inAbbreviation; //Does a string copy into the map.
201 }
202
203 const AAX_CString& Get(int32_t inNumCharacters) const
204 {
205 //More characters than the primary string or no specific shortened names.
206 if ((inNumCharacters >= int32_t(mPrimary.Length())) || (mAbbreviations.empty()) || (0 > inNumCharacters))
207 return mPrimary;
208
209 std::map<uint32_t, AAX_CString>::const_iterator iter = mAbbreviations.upper_bound(static_cast<uint32_t>(inNumCharacters));
210
211 //If the iterator is already pointing to shortest string, return that.
212 if (iter == mAbbreviations.begin())
213 return iter->second;
214
215 //lower_bound() will return the iterator that is larger than the desired value, so decrement the iterator.
216 --iter;
217 return iter->second;
218 }
219
220 void Clear() { mAbbreviations.clear(); }
221
222private:
223 AAX_CString mPrimary;
224 std::map<uint32_t, AAX_CString> mAbbreviations;
225};
226
227#endif //AAX_CSTRING_H
AAX_CString operator+(AAX_CString lhs, const AAX_CString &rhs)
Definition: AAX_CString.h:161
Various utility definitions for AAX.
#define AAX_DEFAULT_MOVE_CTOR(X)
default keyword macro for a class move constructor
Definition: AAX.h:170
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:164
An AAX string interface.
A generic AAX string class with similar functionality to std::string
Definition: AAX_CString.h:57
bool ToInteger(int32_t *oValue) const
AAX_CString & operator+=(const AAX_CString &str)
const char * CString() const
AAX_CString & Insert(uint32_t pos, const AAX_CString &str)
uint32_t Length() const AAX_OVERRIDE
void SubString(uint32_t pos, uint32_t n, AAX_IString *outputStr) const
AAX_CString & operator+=(const char *str)
char & operator[](uint32_t index)
AAX_CString & operator+=(const std::string &str)
bool Empty() const
std::string mString
Definition: AAX_CString.h:157
bool operator==(const AAX_CString &other) const
bool operator<(const AAX_CString &other) const
bool operator!=(const char *otherStr) const
bool ToDouble(double *oValue) const
bool operator==(const char *otherStr) const
bool Equals(const AAX_CString &other) const
Definition: AAX_CString.h:137
void Clear()
AAX_CString & Erase(uint32_t pos, uint32_t n)
const char * Get() const AAX_OVERRIDE
AAX_CString & InsertHex(uint32_t pos, int32_t number, int32_t width)
std::string & StdString()
static const uint32_t kMaxStringLength
Definition: AAX_CString.h:60
AAX_CString & Replace(uint32_t pos, uint32_t n, const AAX_CString &str)
uint32_t FindFirst(const AAX_CString &findStr) const
uint32_t FindLast(const AAX_CString &findStr) const
bool Equals(const char *other) const
Definition: AAX_CString.h:138
AAX_CString & Append(const AAX_CString &str)
bool operator!=(const AAX_CString &other) const
bool operator==(const std::string &otherStr) const
bool operator!=(const std::string &otherStr) const
const char & operator[](uint32_t index) const
bool operator>(const AAX_CString &other) const
AAX_CString & AppendHex(int32_t number, int32_t width)
AAX_CString & InsertNumber(uint32_t pos, double number, int32_t precision)
bool Equals(const std::string &other) const
Definition: AAX_CString.h:139
uint32_t MaxLength() const AAX_OVERRIDE
AAX_CString & AppendNumber(double number, int32_t precision)
static const uint32_t kInvalidIndex
Definition: AAX_CString.h:59
void Set(const char *iString) AAX_OVERRIDE
Helper class to store a collection of name abbreviations.
Definition: AAX_CString.h:186
AAX_CStringAbbreviations(const AAX_CString &inPrimary)
Definition: AAX_CString.h:188
void Clear()
Definition: AAX_CString.h:220
void Add(const AAX_CString &inAbbreviation)
Definition: AAX_CString.h:197
const AAX_CString & Primary() const
Definition: AAX_CString.h:195
const AAX_CString & Get(int32_t inNumCharacters) const
Definition: AAX_CString.h:203
void SetPrimary(const AAX_CString &inPrimary)
Definition: AAX_CString.h:194
A simple string container that can be passed across a binary boundary. This class,...
Definition: AAX_IString.h:51