Mobile API Reference  MicroStrategy 2019
Message.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : Message.h
3 // AUTHOR : vovechkin
4 // CREATION : 2004-10-26
5 // Copyright (C) MicroStrategy Incorporated 2004
6 // All Rights Reserved
7 //==============================================================================================
8 #ifndef MBase_Message_h
9 #define MBase_Message_h
10 
11 #include "Base.h"
12 
13 #include "../Defines/BasicTypes.h"
14 #include "../Defines/Asserte.h"
15 #include "ReturnString.h"
16 #include "Language.h"
17 #include "MessageDomain.h"
18 
19 namespace MBase
20 {
21  typedef Int32 MessageID;
22 
33  {
34  public:
35 
36  typedef unsigned Int32 SizeType;
37 
44  static const SizeType MIN_SIZE;
45 
47  //
48  // Construction, assignment, destruction
49  //
51 
52  Message();
53  Message(const Message& irOther);
54  Message(MessageDomain iDomain, MessageID iID, const char* ipTemplate = NULL);
55 
56  // (deep) assigment operator
57  Message& operator=(const Message& irOther);
58 
64  bool Swap(Message& irOther) throw();
65 
66  // destructor
67  ~Message() throw();
68 
70  //
71  // Chaining
72  //
74 
79  Message& WrapBy(MessageDomain iDomain, MessageID iID, const char* ipTemplate = NULL);
80 
85  const Message* GetLowerLevelMessageOrNULL() const;
86 
91  Message& PrependBy(MessageDomain iDomain, MessageID iID, const char* ipTemplate = NULL);
92 
97  Message& PrependBy(const Message& irMessage);
98 
103  const Message* GetSameLevelMessageOrNULL() const;
104 
106  //
107  // Placement construction/destruction
108  //
110 
118  {
119  public:
120 
121  PlacementPtr(
122  void* ipBuffer,
123  SizeType iBufferSizeInBytes);
124 
125  PlacementPtr(
126  void* ipBuffer,
127  SizeType iBufferSizeInBytes,
128  const Message& irOther);
129 
130  PlacementPtr(
131  void* ipBuffer,
132  SizeType iBufferSizeInBytes,
133  MessageDomain iDomain,
134  MessageID iID,
135  const char* ipTemplate = NULL);
136 
137  ~PlacementPtr() throw();
138 
139  inline Message& operator*() const throw()
140  {
141  _ASSERT(mpMessage != NULL);
142  return *mpMessage;
143  }
144 
145  inline Message* operator->() const throw()
146  {
147  _ASSERT(mpMessage != NULL);
148  return mpMessage;
149  }
150 
151  inline Message* Get() const throw()
152  {
153  _ASSERT(mpMessage != NULL);
154  return mpMessage;
155  }
156 
157  inline bool IsNull() const
158  {
159  return (mpMessage == NULL);
160  }
161 
162  private:
163 
164  // do not allow copying
165  PlacementPtr(const PlacementPtr&);
166  PlacementPtr& operator=(const PlacementPtr&);
167 
168  private:
169 
170  Message* mpMessage;
171  };
172 
180  {
181  public:
182 
184  void* ipBuffer,
185  SizeType iBufferSizeInBytes,
186  SizeType iMessageSizeInBytes);
187 
189  void* ipBuffer,
190  SizeType iBufferSizeInBytes,
191  SizeType iMessageSizeInBytes,
192  const Message& irOther);
193 
195  void* ipBuffer,
196  SizeType iBufferSizeInBytes,
197  SizeType iMessageSizeInBytes,
198  MessageDomain iDomain,
199  MessageID iID,
200  const char* ipTemplate = NULL);
201 
202  ~PlacementArrayPtr() throw();
203 
204  inline MBase::Message& operator [](unsigned int iIndex)
205  {
206  _ASSERT(mpMessage != NULL);
207  _ASSERT(iIndex < (mBufferSizeInBytes / mMessageSizeInBytes));
208 
209  return *reinterpret_cast<MBase::Message*>(mpMessage + mMessageSizeInBytes * iIndex);
210  }
211 
212  inline bool IsNull() const
213  {
214  return (mpMessage == NULL);
215  }
216 
217  private:
218 
219  // do not allow copying
221  PlacementArrayPtr& operator=(const PlacementArrayPtr&);
222 
223  private:
224 
225  unsigned char* mpMessage;
226  const SizeType mBufferSizeInBytes;
227  const SizeType mMessageSizeInBytes;
228  };
229 
231  //
232  // Value getters/setters
233  //
235 
239  bool IsEmpty() const;
240 
244  void Clear();
245 
249  MBase::MessageDomain GetDomain() const;
250 
254  MBase::MessageID GetID() const;
255 
259  void SetDomainAndID(MBase::MessageDomain iDomain, MessageID iID);
260 
264  const char* GetTemplate() const;
265  void SetTemplate(const char* ipTemplate);
266 
271  const char* GetParameter(unsigned int iIndex) const;
272 
276  Message& operator << (bool iParameter);
277  Message& operator << (int iParameter);
278  Message& operator << (unsigned int iParameter);
279  Message& operator << (long iParameter);
280  Message& operator << (unsigned long iParameter);
281  Message& operator << (const char* ipParameter); // assumed to be UTF-8 (or ASCII)
282 #ifndef NO_WCHAR_SUPPORT
283  Message& operator << (const WCHAR* ipParameter);
284 #endif
285 
286  typedef void (*Manipulator)(Message& irMessage);
287  Message& operator << (Manipulator ipManipulator);
288 
294  static void Dec(Message& irMessage);
295  static void Hex(Message& irMessage); // ex: 0x1
296  static void WideHex(Message& irMessage); // ex: 0x00000001
297  static void WideWideHex(Message& irMessage); // ex: 0x0000000000000001
298 
300  //
301  // Localization
302  //
304 
309  const char* GetLocalizedText(MBase::LanguageID iLanguageID) const;
310 
315  void SetLocalizedText(MBase::LanguageID iLanguageID, const char* ipText);
316 
320  class Localizer
321  {
322  public:
323 
324  virtual MBase::ReturnString Localize(
325  MBase::LanguageID iLanguageID,
326  MBase::MessageDomain iMessageDomain,
327  MBase::MessageID iID,
328  const char* ipTemplate,
329  const char* ipParameters[]/*,
330  ParameterType ipParameterTypes[]*/) = 0;
331  };
332 
337 // const char* GetLocalizedText(Localizer& irLocalizer, MBase::LanguageID iLanguageID);
338 
343  MBase::ReturnString Localize(Localizer& irLocalizer, MBase::LanguageID iLanguageID) const;
344 
346  //
347  // Private declarations
348  //
350 
351  private:
352 
353  // placement constructors
354  friend class PlacementPtr;
355  friend class PlacementArrayPtr;
356 
357  Message(SizeType iBufferSizeInBytes);
358  Message(SizeType iBufferSizeInBytes, const Message& irOther);
359  Message(SizeType iBufferSizeInBytes, MessageDomain iDomain, MessageID iID, const char* ipTemplate);
360 
365  void SetNumberFormat(unsigned char iRadix, unsigned char iWidth);
366  void GetNumberFormat(unsigned char& orRadix, unsigned char& orWidth) const;
367 
368  private:
369 
370  // the only data member, which determines the default Message size (as local/temp variable)
371  unsigned char mBuffer[100];
372 
373  public:
374 
376  //
377  // Compatibility with MBase::BaseException
378  //
380 
381 #ifndef NO_BASE_EXCEPTION_COMPATIBILITY
382  // for compatibility with MBase::Exception
383  const WCHAR* GetMessage() const throw();
384  void SetMessage(const WCHAR* ipMessage) throw();
385 
387  inline unsigned Int32 GetErrorCode() const throw()
388  {
389  return static_cast<unsigned Int32>(GetID());
390  }
391 #endif // NO_BASE_EXCEPTION_COMPATIBILITY
392  };
393 }
394 
395 #endif // MBase_Message_h
wchar_t WCHAR
Definition: PDCwchar.h:23
unsigned short LanguageID
Definition: Language.h:27
#define _ASSERT(x)
Definition: Asserte.h:34
Int32 MessageID
Definition: Message.h:21
Definition: ReturnString.h:36
Definition: Message.h:117
#define DLL_BASE_EXIM
Definition: Base.h:20
Definition: Message.h:320
Message * operator->() const
Definition: Message.h:145
Message & operator*() const
Definition: Message.h:139
unsigned Int32 SizeType
Definition: Message.h:36
#define Int32
Definition: BasicTypes.h:20
Definition: Message.h:32
unsigned short MessageDomain
Definition: MessageDomain.h:27
Definition: Allocator.h:47
Definition: Message.h:179
Message * Get() const
Definition: Message.h:151
static const SizeType MIN_SIZE
Definition: Message.h:44
bool IsNull() const
Definition: Message.h:157
#define NULL
Definition: Null.h:10
bool IsNull() const
Definition: Message.h:212