AAX SDK  2.4.1
Avid Audio Extensions Development Kit
AAX_CString.h
Go to the documentation of this file.
1 /*================================================================================================*/
2 /*
3  *
4  * Copyright 2013-2015, 2017, 2021 by Avid Technology, Inc.
5  * All rights reserved.
6  *
7  * CONFIDENTIAL: This document contains confidential information. Do not
8  * read or examine this document unless you are an Avid Technology employee
9  * or have signed a non-disclosure agreement with Avid Technology which protects
10  * the confidentiality of this document. DO NOT DISCLOSE ANY INFORMATION
11  * CONTAINED IN THIS DOCUMENT TO ANY THIRD-PARTY WITHOUT THE PRIOR WRITTEN CONSENT
12  * OF Avid Technology, INC.
13  *
14  */
15 
22 /*================================================================================================*/
23 
24 
25 #ifndef AAX_CSTRING_H
26 #define AAX_CSTRING_H
27 
28 
29 #include "AAX_IString.h"
30 #include "AAX.h"
31 
32 #include <string>
33 #include <map>
34 
35 
37 #if 0
38 #pragma mark -
39 #endif
41 
45 class AAX_CString : public AAX_IString
46 {
47 public:
48  static const uint32_t kInvalidIndex = static_cast<uint32_t>(-1);
49  static const uint32_t kMaxStringLength = static_cast<uint32_t>(-2);
50 
51  // AAX_IString Virtual Overrides
52  uint32_t Length() const AAX_OVERRIDE;
53  uint32_t MaxLength() const AAX_OVERRIDE;
54  const char * Get () const AAX_OVERRIDE;
55  void Set ( const char * iString ) AAX_OVERRIDE;
56  AAX_IString & operator=(const AAX_IString & iOther) AAX_OVERRIDE;
57  AAX_IString & operator=(const char * iString) AAX_OVERRIDE;
58 
61 
63  AAX_CString(const char* str);
64 
66  explicit AAX_CString(const std::string& str);
67 
69  AAX_CString(const AAX_CString& other);
70 
72  AAX_CString(const AAX_IString& other);
73 
76 
77 
79  std::string& StdString();
80 
82  const std::string& StdString() const;
83 
85  AAX_CString& operator=(const AAX_CString& other);
86 
88  AAX_CString & operator=(const std::string& other);
89 
91  AAX_CString & operator=(AAX_CString&& other);
92 
94  friend std::ostream& operator<< (std::ostream& os, const AAX_CString& str);
95 
97  friend std::istream& operator>> (std::istream& os, AAX_CString& str);
98 
99 
100  // String Formatting Functions
101  void Clear();
102  bool Empty() const;
103  AAX_CString& Erase(uint32_t pos, uint32_t n);
105  AAX_CString& Append(const char* str);
106  AAX_CString& AppendNumber(double number, int32_t precision);
107  AAX_CString& AppendNumber(int32_t number);
108  AAX_CString& AppendHex(int32_t number, int32_t width);
109  AAX_CString& Insert(uint32_t pos, const AAX_CString& str);
110  AAX_CString& Insert(uint32_t pos, const char* str);
111  AAX_CString& InsertNumber(uint32_t pos, double number, int32_t precision);
112  AAX_CString& InsertNumber(uint32_t pos, int32_t number);
113  AAX_CString& InsertHex(uint32_t pos, int32_t number, int32_t width);
114  AAX_CString& Replace(uint32_t pos, uint32_t n, const AAX_CString& str);
115  AAX_CString& Replace(uint32_t pos, uint32_t n, const char* str);
116  uint32_t FindFirst(const AAX_CString& findStr) const;
117  uint32_t FindFirst(const char* findStr) const;
118  uint32_t FindFirst(char findChar) const;
119  uint32_t FindLast(const AAX_CString& findStr) const;
120  uint32_t FindLast(const char* findStr) const;
121  uint32_t FindLast(char findChar) const;
122  const char* CString() const;
123  bool ToDouble(double* oValue) const;
124  bool ToInteger(int32_t* oValue) const;
125  void SubString(uint32_t pos, uint32_t n, AAX_IString* outputStr) const;
126  bool Equals(const AAX_CString& other) const { return operator==(other); }
127  bool Equals(const char* other) const { return operator==(other); }
128  bool Equals(const std::string& other) const { return operator==(other); } //beware of STL variations between binaries.
129 
130  // Operator Overrides
131  bool operator==(const AAX_CString& other) const;
132  bool operator==(const char* otherStr) const;
133  bool operator==(const std::string& otherStr) const; //beware of STL variations between binaries.
134  bool operator!=(const AAX_CString& other) const;
135  bool operator!=(const char* otherStr) const;
136  bool operator!=(const std::string& otherStr) const; //beware of STL variations between binaries.
137  bool operator<(const AAX_CString& other) const;
138  bool operator>(const AAX_CString& other) const;
139  const char& operator[](uint32_t index) const;
140  char& operator[](uint32_t index);
142  AAX_CString& operator+=(const std::string& str);
143  AAX_CString& operator+=(const char* str);
144 
145 protected:
146  std::string mString;
147 };
148 
149 // Non-member operators
151 {
152  lhs += rhs;
153  return lhs;
154 }
155 inline AAX_CString operator+(AAX_CString lhs, const char* rhs)
156 {
157  lhs += rhs;
158  return lhs;
159 }
160 inline AAX_CString operator+(const char* lhs, const AAX_CString& rhs)
161 {
162  return AAX_CString(lhs) + rhs;
163 }
164 
165 
167 #if 0
168 #pragma mark -
169 #endif
171 
175 {
176 public:
177  explicit AAX_CStringAbbreviations(const AAX_CString& inPrimary)
178  : mPrimary(inPrimary)
179  , mAbbreviations()
180  {
181  }
182 
183  void SetPrimary(const AAX_CString& inPrimary) { mPrimary = inPrimary; }
184  const AAX_CString& Primary() const { return mPrimary; }
185 
186  void Add(const AAX_CString& inAbbreviation)
187  {
188  uint32_t stringLength = inAbbreviation.Length();
189  mAbbreviations[stringLength] = inAbbreviation; //Does a string copy into the map.
190  }
191 
192  const AAX_CString& Get(int32_t inNumCharacters) const
193  {
194  //More characters than the primary string or no specific shortened names.
195  if ((inNumCharacters >= int32_t(mPrimary.Length())) || (mAbbreviations.empty()) || (0 > inNumCharacters))
196  return mPrimary;
197 
198  std::map<uint32_t, AAX_CString>::const_iterator iter = mAbbreviations.upper_bound(static_cast<uint32_t>(inNumCharacters));
199 
200  //If the iterator is already pointing to shortest string, return that.
201  if (iter == mAbbreviations.begin())
202  return iter->second;
203 
204  //lower_bound() will return the iterator that is larger than the desired value, so decrement the iterator.
205  --iter;
206  return iter->second;
207  }
208 
209  void Clear() { mAbbreviations.clear(); }
210 
211 private:
212  AAX_CString mPrimary;
213  std::map<uint32_t, AAX_CString> mAbbreviations;
214 };
215 
216 #endif //AAX_CSTRING_H
Various utility definitions for AAX.
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:141
AAX_CString operator+(AAX_CString lhs, const AAX_CString &rhs)
Definition: AAX_CString.h:150
An AAX string interface.
A generic AAX string class with similar functionality to std::string
Definition: AAX_CString.h:46
const char & operator[](uint32_t index) const
bool ToInteger(int32_t *oValue) const
AAX_CString & AppendHex(int32_t number, int32_t width)
const char * CString() const
uint32_t Length() const AAX_OVERRIDE
void SubString(uint32_t pos, uint32_t n, AAX_IString *outputStr) const
AAX_CString & operator+=(const AAX_CString &str)
AAX_CString & AppendNumber(double number, int32_t precision)
bool Empty() const
AAX_CString & InsertNumber(uint32_t pos, double number, int32_t precision)
std::string & StdString()
AAX_CString & Append(const AAX_CString &str)
std::string mString
Definition: AAX_CString.h:146
AAX_CString & Replace(uint32_t pos, uint32_t n, const AAX_CString &str)
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
AAX_CString & operator+=(const std::string &str)
AAX_CString & Erase(uint32_t pos, uint32_t n)
bool Equals(const AAX_CString &other) const
Definition: AAX_CString.h:126
void Clear()
AAX_CString & InsertHex(uint32_t pos, int32_t number, int32_t width)
const char * Get() const AAX_OVERRIDE
static const uint32_t kMaxStringLength
Definition: AAX_CString.h:49
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:127
char & operator[](uint32_t index)
AAX_CString & Insert(uint32_t pos, 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
bool operator>(const AAX_CString &other) const
AAX_DEFAULT_MOVE_CTOR(AAX_CString)
AAX_CString & operator+=(const char *str)
bool Equals(const std::string &other) const
Definition: AAX_CString.h:128
uint32_t MaxLength() const AAX_OVERRIDE
static const uint32_t kInvalidIndex
Definition: AAX_CString.h:48
void Set(const char *iString) AAX_OVERRIDE
Helper class to store a collection of name abbreviations.
Definition: AAX_CString.h:175
AAX_CStringAbbreviations(const AAX_CString &inPrimary)
Definition: AAX_CString.h:177
void Clear()
Definition: AAX_CString.h:209
void Add(const AAX_CString &inAbbreviation)
Definition: AAX_CString.h:186
const AAX_CString & Primary() const
Definition: AAX_CString.h:184
void SetPrimary(const AAX_CString &inPrimary)
Definition: AAX_CString.h:183
const AAX_CString & Get(int32_t inNumCharacters) const
Definition: AAX_CString.h:192
A simple string container that can be passed across a binary boundary. This class,...
Definition: AAX_IString.h:41