AAX SDK 2.6.1
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 Avid Technology, Inc.
5 * All rights reserved.
6 *
7 * CONFIDENTIAL: this document contains confidential information of Avid. Do
8 * not disclose to any third party. Use of the information contained in this
9 * document is subject to an Avid SDK license.
10 *
11 */
12
19/*================================================================================================*/
20
21#pragma once
22
23#ifndef AAX_CSTRING_H
24#define AAX_CSTRING_H
25
26
27#include "AAX_IString.h"
28#include "AAX.h"
29
30#include <string>
31#include <map>
32
33
35#if 0
36#pragma mark -
37#endif
39
44{
45public:
46 static const uint32_t kInvalidIndex = static_cast<uint32_t>(-1);
47 static const uint32_t kMaxStringLength = static_cast<uint32_t>(-2);
48
49 // AAX_IString Virtual Overrides
50 uint32_t Length() const AAX_OVERRIDE;
51 uint32_t MaxLength() const AAX_OVERRIDE;
52 const char * Get () const AAX_OVERRIDE;
53 void Set ( const char * iString ) AAX_OVERRIDE;
54 AAX_IString & operator=(const AAX_IString & iOther) AAX_OVERRIDE;
55 AAX_IString & operator=(const char * iString) AAX_OVERRIDE;
56
59
61 AAX_CString(const char* str);
62
64 explicit AAX_CString(const std::string& str);
65
67 AAX_CString(const AAX_CString& other);
68
70 AAX_CString(const AAX_IString& other);
71
74
75
77 std::string& StdString();
78
80 const std::string& StdString() const;
81
83 AAX_CString& operator=(const AAX_CString& other);
84
86 AAX_CString & operator=(const std::string& other);
87
89 AAX_CString & operator=(AAX_CString&& other);
90
92 friend std::ostream& operator<< (std::ostream& os, const AAX_CString& str);
93
95 friend std::istream& operator>> (std::istream& os, AAX_CString& str);
96
97
98 // String Formatting Functions
99 void Clear();
100 bool Empty() const;
101 AAX_CString& Erase(uint32_t pos, uint32_t n);
103 AAX_CString& Append(const char* str);
104 AAX_CString& AppendNumber(double number, int32_t precision);
105 AAX_CString& AppendNumber(int32_t number);
106 AAX_CString& AppendHex(int32_t number, int32_t width);
107 AAX_CString& Insert(uint32_t pos, const AAX_CString& str);
108 AAX_CString& Insert(uint32_t pos, const char* str);
109 AAX_CString& InsertNumber(uint32_t pos, double number, int32_t precision);
110 AAX_CString& InsertNumber(uint32_t pos, int32_t number);
111 AAX_CString& InsertHex(uint32_t pos, int32_t number, int32_t width);
112 AAX_CString& Replace(uint32_t pos, uint32_t n, const AAX_CString& str);
113 AAX_CString& Replace(uint32_t pos, uint32_t n, const char* str);
114 uint32_t FindFirst(const AAX_CString& findStr) const;
115 uint32_t FindFirst(const char* findStr) const;
116 uint32_t FindFirst(char findChar) const;
117 uint32_t FindLast(const AAX_CString& findStr) const;
118 uint32_t FindLast(const char* findStr) const;
119 uint32_t FindLast(char findChar) const;
120 const char* CString() const;
121 bool ToDouble(double* oValue) const;
122 bool ToInteger(int32_t* oValue) const;
123 void SubString(uint32_t pos, uint32_t n, AAX_IString* outputStr) const;
124 bool Equals(const AAX_CString& other) const { return operator==(other); }
125 bool Equals(const char* other) const { return operator==(other); }
126 bool Equals(const std::string& other) const { return operator==(other); } //beware of STL variations between binaries.
127
128 // Operator Overrides
129 bool operator==(const AAX_CString& other) const;
130 bool operator==(const char* otherStr) const;
131 bool operator==(const std::string& otherStr) const; //beware of STL variations between binaries.
132 bool operator!=(const AAX_CString& other) const;
133 bool operator!=(const char* otherStr) const;
134 bool operator!=(const std::string& otherStr) const; //beware of STL variations between binaries.
135 bool operator<(const AAX_CString& other) const;
136 bool operator>(const AAX_CString& other) const;
137 const char& operator[](uint32_t index) const;
138 char& operator[](uint32_t index);
140 AAX_CString& operator+=(const std::string& str);
141 AAX_CString& operator+=(const char* str);
142
143protected:
144 std::string mString;
145};
146
147// Non-member operators
149{
150 lhs += rhs;
151 return lhs;
152}
153inline AAX_CString operator+(AAX_CString lhs, const char* rhs)
154{
155 lhs += rhs;
156 return lhs;
157}
158inline AAX_CString operator+(const char* lhs, const AAX_CString& rhs)
159{
160 return AAX_CString(lhs) + rhs;
161}
162
163
165#if 0
166#pragma mark -
167#endif
169
173{
174public:
175 explicit AAX_CStringAbbreviations(const AAX_CString& inPrimary)
176 : mPrimary(inPrimary)
177 , mAbbreviations()
178 {
179 }
180
181 void SetPrimary(const AAX_CString& inPrimary) { mPrimary = inPrimary; }
182 const AAX_CString& Primary() const { return mPrimary; }
183
184 void Add(const AAX_CString& inAbbreviation)
185 {
186 uint32_t stringLength = inAbbreviation.Length();
187 mAbbreviations[stringLength] = inAbbreviation; //Does a string copy into the map.
188 }
189
190 const AAX_CString& Get(int32_t inNumCharacters) const
191 {
192 //More characters than the primary string or no specific shortened names.
193 if ((inNumCharacters >= int32_t(mPrimary.Length())) || (mAbbreviations.empty()) || (0 > inNumCharacters))
194 return mPrimary;
195
196 std::map<uint32_t, AAX_CString>::const_iterator iter = mAbbreviations.upper_bound(static_cast<uint32_t>(inNumCharacters));
197
198 //If the iterator is already pointing to shortest string, return that.
199 if (iter == mAbbreviations.begin())
200 return iter->second;
201
202 //lower_bound() will return the iterator that is larger than the desired value, so decrement the iterator.
203 --iter;
204 return iter->second;
205 }
206
207 void Clear() { mAbbreviations.clear(); }
208
209private:
210 AAX_CString mPrimary;
211 std::map<uint32_t, AAX_CString> mAbbreviations;
212};
213
214#endif //AAX_CSTRING_H
AAX_CString operator+(AAX_CString lhs, const AAX_CString &rhs)
Definition: AAX_CString.h:148
Various utility definitions for AAX.
#define AAX_DEFAULT_MOVE_CTOR(X)
default keyword macro for a class move constructor
Definition: AAX.h:157
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:151
An AAX string interface.
A generic AAX string class with similar functionality to std::string
Definition: AAX_CString.h:44
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:144
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:124
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:47
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:125
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:126
uint32_t MaxLength() const AAX_OVERRIDE
AAX_CString & AppendNumber(double number, int32_t precision)
static const uint32_t kInvalidIndex
Definition: AAX_CString.h:46
void Set(const char *iString) AAX_OVERRIDE
Helper class to store a collection of name abbreviations.
Definition: AAX_CString.h:173
AAX_CStringAbbreviations(const AAX_CString &inPrimary)
Definition: AAX_CString.h:175
void Clear()
Definition: AAX_CString.h:207
void Add(const AAX_CString &inAbbreviation)
Definition: AAX_CString.h:184
const AAX_CString & Primary() const
Definition: AAX_CString.h:182
const AAX_CString & Get(int32_t inNumCharacters) const
Definition: AAX_CString.h:190
void SetPrimary(const AAX_CString &inPrimary)
Definition: AAX_CString.h:181
A simple string container that can be passed across a binary boundary. This class,...
Definition: AAX_IString.h:38