Software and Services, Portable Libraries  2019.Mar.01
A library for managing digital certificates
instance.hpp
Go to the documentation of this file.
1 //
2 // BEGIN_SOFTWARE_AND_SERVICES_COPYRIGHT
3 //
4 // Copyright (C) 2010-2014,2016 Software and Services LLC,
5 // All Rights Reserved.
6 //
7 // NOTICE:
8 //
9 // THIS SOURCE CODE BELONGS TO Software and Services LLC.
10 // THIS CODE IS PROPERTY OF THE COPYRIGHT HOLDER AND IS NOT TO
11 // BE DIVULGED OR USED BY PARTIES WHO HAVE NOT RECEIVED WRITTEN
12 // AUTHORIZATION FROM THE OWNER.
13 //
14 // THIS SOFTWARE AND MANUAL ARE BOTH PROTECTED BY UNITED STATES
15 // COPYRIGHT LAW (TITLE 17 UNITED STATES CODE). UNAUTHORIZED REPRODUCTION
16 // AND/OR SALE MAY RESULT IN IMPRISONMENT OF UP TO ONE YEAR AND FINES
17 // OF UP TO $100,000 (17 USC 506). COPYRIGHT INFRINGERS MAY ALSO
18 // BE SUBJECT TO CIVIL LIABILITY.
19 //
20 // THIS NOTICE AND THE ABOVE COPYRIGHT NOTICE MUST REMAIN IN ALL
21 // COPIES AND ANY DERIVED WORK.
22 //
23 // ALL OF THIS CODE IS ORIGINAL WORK BY THE COPYRIGHT HOLDER.
24 //
25 // THIS DOCUMENT AND THE INFORMATION CONTAINED HEREIN IS
26 // PROVIDED ON AN "AS IS" BASIS AND Software and Services LLC.
27 // DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT
28 // NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
29 // HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
30 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
31 // PURPOSE.
32 //
33 // END_SOFTWARE_AND_SERVICES_COPYRIGHT
34 //
35 //
36 
42 #ifndef _SOFTWARE_AND_SERVICES_LIBRARY_MATH_INSTANCE_HPP_
43 #define _SOFTWARE_AND_SERVICES_LIBRARY_MATH_INSTANCE_HPP_
44 
45 #ifdef BUILDING_SAS_COMMON_LIBRARY
46 #include "osver.h"
47 #else
48 #include <SaS/Common/osver.h>
49 #endif
50 
51 #if defined(WIN32) && !defined(USING_MINGW)
52 #pragma warning (disable : 4251)
53 #endif
54 
55 #ifdef WIN32
56 #define EXPORT_OUT __declspec(dllexport)
57 #define EXPORT_IN __declspec(dllimport)
58 
59 #else
60 #define EXPORT_OUT
61 #define EXPORT_IN
62 #endif // WIN32
63 
64 #ifndef nullptr
65 #include <stdio.h>
66 #endif
67 
68 #ifdef Linux
69 #include <stdlib.h>
70 #endif
71 #include <malloc.h>
72 #include <stdint.h>
73 
74 namespace SoftwareAndServices
75 {
76  namespace Library
77  {
78  namespace Common
79  {
83  typedef uint64_t InstanceCount_t;
84 
90  template <class T> class instance
91  {
92 
93  public:
94 
98  inline instance()
99  {
100  _instance = 1;
101  }
102 
108  virtual inline InstanceCount_t
109  incInstance() const
110  {
111  return(++_instance);
112  }
113 
117  virtual inline InstanceCount_t
118  getInstance() const
119  {
120  return(_instance);
121  }
122 
128  virtual inline InstanceCount_t
129  decInstance() const
130  {
131  return(--_instance);
132  }
133 
134  inline void operator delete(void * ToFree)
135  {
136  T * ptr = (T*)ToFree;
137 
138  if (ptr->instance<T>::decInstance() == 0
139  && ToFree != nullptr) {
140 
141  ::free(ToFree);
142  }
143  return;
144  }
145 
146  private:
147  mutable InstanceCount_t _instance;
148  };
149 
150  }
151  }
152 }
153 
154 #endif // _SOFTWARE_AND_SERVICES_LIBRARY_MATH_INSTANCE_HPP_
virtual InstanceCount_t getInstance() const
Definition: instance.hpp:118
Instance counting and tracking.
Definition: instance.hpp:90
Copyright Douglas Mark Royer DouglasRoyer@gmail.com.
Definition: Base.hpp:98
uint64_t InstanceCount_t
Many, many instances supported by the software.
Definition: instance.hpp:83
virtual InstanceCount_t decInstance() const
Decrement the instance.
Definition: instance.hpp:129
"<SaS/Common/psver.h>" Definitions specific to various OS&#39;s and OS versions.
virtual InstanceCount_t incInstance() const
Increment the instance.
Definition: instance.hpp:109