Software and Services, Portable Libraries  2019.Mar.01
A library for managing digital certificates
Error.hpp
Go to the documentation of this file.
1 //
2 // BEGIN_COPYRIGHT
3 //
4 // Copyright (C) 2010-2018 DOUGLAS MARK ROYER, All Rights Reserved.
5 //
6 // NOTICE:
7 //
8 // THIS SOURCE CODE BELONGS TO DOUGLAS MARK ROYER.
9 // THIS CODE IS PROPERTY OF THE COPYRIGHT HOLDER AND IS NOT TO
10 // BE DIVULGED OR USED BY PARTIES WHO HAVE NOT RECEIVED WRITTEN
11 // AUTHORIZATION FROM THE OWNER.
12 //
13 // THIS SOFTWARE AND MANUAL ARE BOTH PROTECTED BY UNITED STATES
14 // COPYRIGHT LAW (TITLE 17 UNITED STATES CODE). UNAUTHORIZED REPRODUCTION
15 // AND/OR SALE MAY RESULT IN IMPRISONMENT OF UP TO ONE YEAR AND FINES
16 // OF UP TO $100,000 (17 USC 506). COPYRIGHT INFRINGERS MAY ALSO
17 // BE SUBJECT TO CIVIL LIABILITY.
18 //
19 // THIS NOTICE AND THE ABOVE COPYRIGHT NOTICE MUST REMAIN IN ALL
20 // COPIES AND ANY DERIVED WORK.
21 //
22 // ALL OF THIS CODE IS ORIGINAL WORK BY THE COPYRIGHT HOLDER.
23 //
24 // THIS DOCUMENT AND THE INFORMATION CONTAINED HEREIN IS
25 // PROVIDED ON AN "AS IS" BASIS AND THE OWNER
26 // DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT
27 // NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
28 // HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
29 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
30 // PURPOSE.
31 //
32 // END_COPYRIGHT
33 //
34 
51 #ifndef SOFTWARE_AND_SERVICES_LIBRARY_COMMON_ERROR_HPP_
52 #define SOFTWARE_AND_SERVICES_LIBRARY_COMMON_ERROR_HPP_
53 
54 #ifdef WIN32
55 #pragma warning (disable : 4251)
56 #endif
57 
58 #ifdef BUILDING_SAS_COMMON_LIBRARY
59 #include "osver.h"
60 #include "instance.hpp"
61 #include "TreeSearch.hpp"
62 #include "DateTime.hpp"
63 #else
64 #include <SaS/Common/osver.h>
65 #include <SaS/Common/instance.hpp>
66 #include <SaS/Common/TreeSearch.hpp>
67 #include <SaS/Common/DateTime.hpp>
68 #include <SaS/Common/strsearch.hpp>
69 #endif
70 
71 #ifndef EXPORT_COMMON
72 #ifdef BUILDING_SAS_COMMON_LIBRARY
73 #define EXPORT_COMMON EXPORT_OUT
74 #else
75 #define EXPORT_COMMON EXPORT_IN
76 #endif
77 #endif
78 
79 #include <stdlib.h>
80 
82 
83 namespace SoftwareAndServices
84 {
85  namespace Library
86  {
87  namespace Common
88  {
89 
95  class EXPORT_COMMON Error
96  : public virtual Tree_t<Error>,
97  public virtual instance<Error>
98  {
99 
100  public:
101 
107  Error(const char * Guid);
108 
112  virtual ~Error();
113 
128  static const Error * GetError(unsigned int MsgNum,
129  const char * DefaultMsg,
130  const char * Locale = nullptr);
131 
145  const char * GetMsg(unsigned int MsgNum,
146  const char * DefaultMsg,
147  const char * Locale = nullptr);
148 
161  int GetErrno(unsigned int MsgNum,
162  const char * DefaultMsg,
163  const char * Locale = nullptr);
164 
181  static const Error * GetError(const char * Guid,
182  unsigned int MsgNum,
183  const char * DefaultMsg,
184  const char * Locale = nullptr);
185 
201  const char * GetMsg(const char * Guid,
202  unsigned int MsgNum,
203  const char * DefaultMsg,
204  const char * Locale = nullptr);
205 
221  static int GetErrno(void * Guid,
222  unsigned int MsgNum,
223  const char * DefaultMsg,
224  const char * Locale = nullptr);
225 
226 
232  int GetErrno() const;
233 
245  void SetMsg(const char * Guid,
246  unsigned int MsgNum,
247  const char * Msg,
248  const char * Locale);
249 
259  void SetMsg(const char * Guid,
260  unsigned int MsgNum,
261  const char * Msg);
262 
270  void SetPosition(int Line,
271  int CharOffset = -1);
272 
276  int GetLineNumber() const; // or -1
277 
282  int GetCharOffset() const; // or -1
283 
287  const char * GetGuid();
288 
292  void SetGuid(const char * newGuid);
293 
297  const char * GetProductGuid();
298 
302  void SetProductGuid(const char * Guid);
303 
307  const char * GetCombinedGuid();
308 
312  const char * GetMsg() const;
313 
317  const char * GetLocale() const;
318 
323  enum LocalErrno {
324  ACCESS_DENIED = 1045,
325  UNKNOWN_HOST = 2005
326  };
327 
340  Tree_t<Error> * Find(Tree_t<Error> * Rootp,
341  const Tree_t<Error> * ToFind,
342  TreeCompare_fn_t Cmp);
343 
356  bool Insert(Tree_t<Error> ** Rootp,
357  const Tree_t<Error> * ToInsert,
358  TreeCompare_fn_t Cmp);
359 
372  bool Remove(Tree_t<Error> ** Rootp,
373  const Tree_t<Error> * ToRemove,
374  TreeCompare_fn_t Cmp);
375 
384  void Walk(const Tree_t<Error> * Root,
385  TreeAction_fn_t Walk);
386 
390  const DateTime * GetDateTime() const;
391 
392  protected:
393 
397  const char * _Guid;
398 
403  mutable const char * _ProductGuid;
404 
408  mutable const char * _CombinedGuid;
409 
413  const char * _Msg;
414 
418  const char * _Locale;
419 
423  int _Errno;
429 
434 
440  };
441  }
442  }
443 }
444 
445 extern "C" {
446  int errnoCompare(Tree_t<Error> * one,
447  Tree_t<Error> * two);
448 
449 }
450 
451 
452 #endif //SOFTWARE_AND_SERVICES_LIBRARY_COMMON_ERROR_HPP_
const char * _ProductGuid
The current product GUID.
Definition: Error.hpp:403
int _CharOffset
For line oriented message, the character offset in the line.
Definition: Error.hpp:439
const char * _Locale
The locale for the message.
Definition: Error.hpp:418
const char * _CombinedGuid
Combined GUID - calculated.
Definition: Error.hpp:408
LocalErrno
Status of error message.
Definition: Error.hpp:323
const char * _Msg
The message - per locale tree.
Definition: Error.hpp:413
int _LineNumber
For line oriented message, the line number.
Definition: Error.hpp:433
Instance counting and tracking.
Definition: instance.hpp:90
const char * _Guid
The current application GUID.
Definition: Error.hpp:397
Copyright Douglas Mark Royer DouglasRoyer@gmail.com.
Definition: Base.hpp:98
Base class for instance counting objects.
Date and Time routines.
int _Errno
The errono - our errno, not the systems.
Definition: Error.hpp:423
A DateTime class used by many other objects.
Definition: DateTime.hpp:105
"<SaS/Common/psver.h>" Definitions specific to various OS&#39;s and OS versions.
A generic error message class.
Definition: Error.hpp:95