Also use Objects as part of an operation but as a result don't generate Any operation...
[ACE_TAO.git] / ACE / ace / Time_Policy.h
blob29ffa7d4ab65efc225e8166ba81a51b77b9368cd
1 #ifndef ACE_TIME_POLICY_H
2 #define ACE_TIME_POLICY_H
3 // -*- C++ -*-
4 /**
5 * @file Time_Policy.h
7 * @author Carlos O'Ryan <coryan@atdesk.com>
8 * @author Martin Corino <mcorino@remedy.nl>
9 */
10 #include /**/ "ace/pre.h"
12 #include /**/ "ace/config-all.h"
14 #include /**/ "ace/Time_Value_T.h"
16 #if !defined (ACE_LACKS_PRAGMA_ONCE)
17 # pragma once
18 #endif /* ACE_LACKS_PRAGMA_ONCE */
20 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
22 /**
23 * @class ACE_System_Time_Policy
25 * @brief Implement the system time policy for ACE.
27 * The most common time policy is to simply use
28 * ACE_OS::gettimeofday(), this class implements that policy, i.e., it
29 * simply calls that function.
31 class ACE_Export ACE_System_Time_Policy
33 public:
34 /// Return the current time according to this policy
35 ACE_Time_Value_T<ACE_System_Time_Policy> operator() () const;
37 /// Noop. Just here to satisfy backwards compatibility demands.
38 void set_gettimeofday (ACE_Time_Value (*gettimeofday)(void));
41 /**
42 * @class ACE_HR_Time_Policy
44 * @brief Implement a time policy based on the ACE Highres timer.
46 class ACE_Export ACE_HR_Time_Policy
48 public:
49 /// Return the current time according to this policy
50 ACE_Time_Value_T<ACE_HR_Time_Policy> operator() () const;
52 /// Noop. Just here to satisfy backwards compatibility demands.
53 void set_gettimeofday (ACE_Time_Value (*gettimeofday)(void));
56 /**
57 * @class ACE_FPointer_Timer_Policy
59 * @brief Implement a time policy based on a function pointer.
61 * This time policy allows dynamic changes to the source of time by
62 * using a function pointer.
64 class ACE_Export ACE_FPointer_Time_Policy
66 public:
67 /**
68 * @brief Default constructor uses ACE_OS::gettimeofday()
70 * ACE_T requires a default constructor that leaves the
71 * policy in a functional state. Therefore, a null pointer would
72 * not be desirable, in other words, we need a non-trivial default
73 * constructor.
75 ACE_FPointer_Time_Policy();
77 /**
78 * @typedef FPtr
80 * Short-hand for the right type of pointer to function.
82 typedef ACE_Time_Value (*FPtr)();
84 /**
85 * @brief Constructor from a pointer to function.
87 * Construct from a pointer to function.
89 ACE_FPointer_Time_Policy(FPtr f);
91 /// Return the current time according to this policy
92 ACE_Time_Value_T<ACE_FPointer_Time_Policy> operator()() const;
94 /// Satisfy backwards compatibility demands.
95 void set_gettimeofday (ACE_Time_Value (*gettimeofday)(void));
96 private:
97 FPtr function_;
100 class ACE_Dynamic_Time_Policy_Base; // forward decl
103 * @class ACE_Delegating_Time_Policy
105 * @brief Implement a time policy that delegates to a dynamic
106 * time policy.
108 class ACE_Export ACE_Delegating_Time_Policy
110 public:
111 ACE_Delegating_Time_Policy (ACE_Dynamic_Time_Policy_Base const * delegate = 0);
113 /// Return the current time according to this policy
114 ACE_Time_Value_T<ACE_Delegating_Time_Policy> operator()() const;
116 /// Set delegate
117 void set_delegate (ACE_Dynamic_Time_Policy_Base const * delegate);
119 #if defined (ACE_HAS_CPP11)
120 ACE_Delegating_Time_Policy (const ACE_Delegating_Time_Policy&) = default;
121 ACE_Delegating_Time_Policy (ACE_Delegating_Time_Policy&&) = default;
122 ACE_Delegating_Time_Policy& operator = (ACE_Delegating_Time_Policy const &) = default;
123 ACE_Delegating_Time_Policy &operator = (ACE_Delegating_Time_Policy&&) = default;
124 #endif /* ACE_HAS_CPP11 */
126 /// Noop. Just here to satisfy backwards compatibility demands.
127 void set_gettimeofday (ACE_Time_Value (*gettimeofday)(void));
128 private:
129 ACE_Dynamic_Time_Policy_Base const * delegate_;
133 * @class ACE_Dynamic_Time_Policy_base
135 * @brief Abstract base class for dynamically loaded and/or shared
136 * time policies.
138 class ACE_Export ACE_Dynamic_Time_Policy_Base
140 public:
141 virtual ~ACE_Dynamic_Time_Policy_Base ();
143 /// Return the current time according to this policy
144 ACE_Time_Value_T<ACE_Delegating_Time_Policy> operator()() const;
146 /// Noop. Just here to satisfy backwards compatibility demands.
147 void set_gettimeofday (ACE_Time_Value (*gettimeofday)(void));
148 protected:
149 /// Return the current time according to policy implementation.
150 virtual ACE_Time_Value_T<ACE_Delegating_Time_Policy> gettimeofday () const = 0;
153 /// Temporarily, for backwards compatibility reasons, this will
154 /// be the default time policy. In time to be replaced by
155 /// ACE_System_Time_Policy.
156 typedef ACE_FPointer_Time_Policy ACE_Default_Time_Policy;
158 #if defined ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION_EXPORT
159 template class ACE_Export ACE_Time_Value_T<ACE_System_Time_Policy>;
160 template class ACE_Export ACE_Time_Value_T<ACE_HR_Time_Policy>;
161 template class ACE_Export ACE_Time_Value_T<ACE_FPointer_Time_Policy>;
162 template class ACE_Export ACE_Time_Value_T<ACE_Delegating_Time_Policy>;
163 #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION_EXPORT */
165 ACE_END_VERSIONED_NAMESPACE_DECL
167 #if defined (__ACE_INLINE__)
168 #include "ace/Time_Policy.inl"
169 #endif /* __ACE_INLINE__ */
171 #include /**/ "ace/post.h"
172 #endif /* ACE_TIME_POLICY_H */