| AAX SDK 2.6.1 Avid Audio Extensions Development Kit

- Welcome
- Manual
- Classes
- Files
- Lists
- Support

- File List
- File Members

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
43 class AAX_CString : public AAX_IString
44{
45 public:
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
58 AAX_CString();
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
73 AAX_DEFAULT_MOVE_CTOR(AAX_CString);
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);
102 AAX_CString& Append(const AAX_CString& str);
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);
139 AAX_CString& operator+=(const AAX_CString& str);
140 AAX_CString& operator+=(const std::string& str);
141 AAX_CString& operator+=(const char* str);
142
143 protected:
144 std::string mString;
145};
146
147// Non-member operators
148 inline AAX_CString operator+(AAX_CString lhs, const AAX_CString& rhs)
149{
150 lhs += rhs;
151 return lhs;
152}
153 inline AAX_CString operator+(AAX_CString lhs, const char* rhs)
154{
155 lhs += rhs;
156 return lhs;
157}
158 inline 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
172 class AAX_CStringAbbreviations
173{
174 public:
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
209 private:
210 AAX_CString mPrimary;
211 std::map<uint32_t, AAX_CString> mAbbreviations;
212};
213
214#endif //AAX_CSTRING_H
operator+
AAX_CString operator+(AAX_CString lhs, const AAX_CString &rhs)
Definition: AAX_CString.h:148
AAX.h
Various utility definitions for AAX.
AAX_DEFAULT_MOVE_CTOR
#define AAX_DEFAULT_MOVE_CTOR(X)
default keyword macro for a class move constructor
Definition: AAX.h:157
AAX_OVERRIDE
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:151
AAX_IString.h
An AAX string interface.
AAX_CString
A generic AAX string class with similar functionality to std::string
Definition: AAX_CString.h:44
AAX_CString::ToInteger
bool ToInteger(int32_t *oValue) const
AAX_CString::operator+=
AAX_CString & operator+=(const AAX_CString &str)
AAX_CString::CString
const char * CString() const
AAX_CString::Insert
AAX_CString & Insert(uint32_t pos, const AAX_CString &str)
AAX_CString::Length
uint32_t Length() const AAX_OVERRIDE
AAX_CString::SubString
void SubString(uint32_t pos, uint32_t n, AAX_IString *outputStr) const
AAX_CString::operator+=
AAX_CString & operator+=(const char *str)
AAX_CString::operator[]
char & operator[](uint32_t index)
AAX_CString::operator+=
AAX_CString & operator+=(const std::string &str)
AAX_CString::Empty
bool Empty() const
AAX_CString::mString
std::string mString
Definition: AAX_CString.h:144
AAX_CString::operator==
bool operator==(const AAX_CString &other) const
AAX_CString::operator<
bool operator<(const AAX_CString &other) const
AAX_CString::operator!=
bool operator!=(const char *otherStr) const
AAX_CString::ToDouble
bool ToDouble(double *oValue) const
AAX_CString::operator==
bool operator==(const char *otherStr) const
AAX_CString::Equals
bool Equals(const AAX_CString &other) const
Definition: AAX_CString.h:124
AAX_CString::Clear
void Clear()
AAX_CString::Erase
AAX_CString & Erase(uint32_t pos, uint32_t n)
AAX_CString::Get
const char * Get() const AAX_OVERRIDE
AAX_CString::InsertHex
AAX_CString & InsertHex(uint32_t pos, int32_t number, int32_t width)
AAX_CString::StdString
std::string & StdString()
AAX_CString::kMaxStringLength
static const uint32_t kMaxStringLength
Definition: AAX_CString.h:47
AAX_CString::Replace
AAX_CString & Replace(uint32_t pos, uint32_t n, const AAX_CString &str)
AAX_CString::FindFirst
uint32_t FindFirst(const AAX_CString &findStr) const
AAX_CString::FindLast
uint32_t FindLast(const AAX_CString &findStr) const
AAX_CString::Equals
bool Equals(const char *other) const
Definition: AAX_CString.h:125
AAX_CString::Append
AAX_CString & Append(const AAX_CString &str)
AAX_CString::operator!=
bool operator!=(const AAX_CString &other) const
AAX_CString::operator==
bool operator==(const std::string &otherStr) const
AAX_CString::operator!=
bool operator!=(const std::string &otherStr) const
AAX_CString::operator[]
const char & operator[](uint32_t index) const
AAX_CString::operator>
bool operator>(const AAX_CString &other) const
AAX_CString::AppendHex
AAX_CString & AppendHex(int32_t number, int32_t width)
AAX_CString::InsertNumber
AAX_CString & InsertNumber(uint32_t pos, double number, int32_t precision)
AAX_CString::Equals
bool Equals(const std::string &other) const
Definition: AAX_CString.h:126
AAX_CString::MaxLength
uint32_t MaxLength() const AAX_OVERRIDE
AAX_CString::AppendNumber
AAX_CString & AppendNumber(double number, int32_t precision)
AAX_CString::kInvalidIndex
static const uint32_t kInvalidIndex
Definition: AAX_CString.h:46
AAX_CString::Set
void Set(const char *iString) AAX_OVERRIDE
AAX_CStringAbbreviations
Helper class to store a collection of name abbreviations.
Definition: AAX_CString.h:173
AAX_CStringAbbreviations::AAX_CStringAbbreviations
AAX_CStringAbbreviations(const AAX_CString &inPrimary)
Definition: AAX_CString.h:175
AAX_CStringAbbreviations::Clear
void Clear()
Definition: AAX_CString.h:207
AAX_CStringAbbreviations::Add
void Add(const AAX_CString &inAbbreviation)
Definition: AAX_CString.h:184
AAX_CStringAbbreviations::Primary
const AAX_CString & Primary() const
Definition: AAX_CString.h:182
AAX_CStringAbbreviations::Get
const AAX_CString & Get(int32_t inNumCharacters) const
Definition: AAX_CString.h:190
AAX_CStringAbbreviations::SetPrimary
void SetPrimary(const AAX_CString &inPrimary)
Definition: AAX_CString.h:181
AAX_IString
A simple string container that can be passed across a binary boundary. This class,...
Definition: AAX_IString.h:38