PMDA++  0.4.4
Header-only C++ library for writing PCP PMDAs
config.hpp
Go to the documentation of this file.
1 // Copyright Paul Colby 2013 - 2015.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE.md or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 
6 /**
7  * @file
8  * @brief Sets up common PMDA++ library macros.
9  */
10 
11 #ifndef __PCP_CPP_CONFIG_HPP__
12 #define __PCP_CPP_CONFIG_HPP__
13 
14 /**
15  * @def PCP_CPP_BOOST_PO_IMPLICIT_VALUE
16  *
17  * @brief Sets a command line option's implicit value, if supported by the
18  * version of Boost.Program_Options being built against.
19  */
20 
21 /**
22  * @def PCP_CPP_BOOST_PO_VALUE_NAME
23  *
24  * @brief Sets a command line option's value name, if supported by the version
25  * of Boost.Program_Options being built against.
26  *
27  * @param name Option's value name
28  */
29 
30 // Boost headers that depend on boost/cstdint.hpp must be included before any
31 // PCP headers, because pcp/config.h sets a number of macros like ULONGLONG_MAX
32 // which fool Boost into thinking we're on an unknown, non-standard platform.
33 #ifndef PCP_CPP_NO_BOOST
34 # include <boost/date_time/posix_time/posix_time_duration.hpp>
35 # include <boost/program_options.hpp>
36 // boost::program_options::typed_value::implicit_value was added in 1.35.0.
37 # if BOOST_VERSION > 103500
38 # define PCP_CPP_BOOST_PO_IMPLICIT_VALUE(...) ->implicit_value(__VA_ARGS__)
39 # else
40 # define PCP_CPP_BOOST_PO_IMPLICIT_VALUE(...)
41 # endif
42 // boost::program_options::typed_value::value_name was added in 1.50.0.
43 # if BOOST_VERSION > 105000
44 # define PCP_CPP_BOOST_PO_VALUE_NAME(name) ->value_name(name)
45 # else
46 # define PCP_CPP_BOOST_PO_VALUE_NAME(name)
47 # endif
48 #endif
49 
50 #include <pcp/pmapi.h> // Note, the order in which these are included matters
51 #include <pcp/impl.h> // more for older versions of PCP, so don't reorder them
52 #include <pcp/pmda.h> // without testing against older versions of PCP.
53 
54 /// PMDA interface version to use; defaults to "latest".
55 #ifndef PCP_CPP_PMDA_INTERFACE_VERSION
56 #define PCP_CPP_PMDA_INTERFACE_VERSION PMDA_INTERFACE_LATEST
57 #endif
58 
59 // Custom namespace wrapper macros.
60 #ifdef PCP_CPP_NAMESPACE
61 # define PCP_CPP_BEGIN_NAMESPACE namespace PCP_CPP_NAMESPACE {
62 # define PCP_CPP_END_NAMESPACE }
63 #else
64 # define PCP_CPP_BEGIN_NAMESPACE
65 # define PCP_CPP_END_NAMESPACE
66 #endif
67 
68 PCP_CPP_BEGIN_NAMESPACE
69 
70 namespace pcp {
71 
72 /**
73  * @brief Get the PCP runtime version as a numeric value.
74  * @returns The PCP runtime version as a numeric value.
75  */
76 template<typename Type>
78 {
79  const char * const str = pmGetConfig("PCP_VERSION");
80  const char * const pos[2] = { strchr(str, '.'), strrchr(str, '.') };
81  return (pos[0] == pos[1]) ? 0 :
82  (strtoul(str, NULL, 10) << 16) +
83  (strtoul(pos[0]+1, NULL, 10) << 8) +
84  strtoul(pos[1]+1, NULL, 10);
85 }
86 
87 /**
88  * @brief Get the PCP runtime version as a string.
89  * @returns The PCP runtime version as a string.
90  */
91 template<>
92 inline char * get_pcp_runtime_version()
93 {
94  return pmGetConfig("PCP_VERSION");
95 }
96 
97 } // namespace pcp.
98 
99 PCP_CPP_END_NAMESPACE
100 
101 /**
102  * @brief Let the compiler know that a parameter is unsed.
103  *
104  * @param name The name of the unused parameter.
105  */
106 #define PCP_CPP_UNUSED(name) (void)name;
107 
108 #endif
Definition: atom.hpp:20
Type get_pcp_runtime_version()
Get the PCP runtime version as a numeric value.
Definition: config.hpp:77