Cupt
common.hpp
Go to the documentation of this file.
1 /**************************************************************************
2 * Copyright (C) 2010 by Eugene V. Lyubimkin *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License *
6 * (version 3 or above) as published by the Free Software Foundation. *
7 * *
8 * This program is distributed in the hope that it will be useful, *
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11 * GNU General Public License for more details. *
12 * *
13 * You should have received a copy of the GNU GPL *
14 * along with this program; if not, write to the *
15 * Free Software Foundation, Inc., *
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA *
17 **************************************************************************/
18 #ifndef CUPT_COMMON_SEEN
19 #define CUPT_COMMON_SEEN
20 
22 #define CUPT_API __attribute__ ((visibility("default")))
23 #define CUPT_LOCAL __attribute__ ((visibility("hidden")))
24 
28 #include <string>
29 #include <vector>
30 #include <memory>
31 #include <stdexcept>
32 
34 namespace cupt {
35 
36 CUPT_API extern const char* const libraryVersion;
37 
38 using std::vector;
39 using std::string;
40 
42 
45 class CUPT_API Exception: public std::runtime_error
46 {
47  public:
49 
54  Exception(const char* message)
55  : std::runtime_error(message)
56  {}
58 
61  Exception(const string& message)
62  : std::runtime_error(message)
63  {}
64 };
65 
66 using std::pair;
67 
68 using std::shared_ptr;
69 using std::static_pointer_cast;
70 using std::dynamic_pointer_cast;
71 
73 
77 CUPT_API extern int messageFd;
78 
79 // TODO/API break/: remove fatal, warn, debug, simulate, sf
81 void CUPT_API fatal(const char* format, ...);
83 void CUPT_API warn(const char* format, ...);
85 void CUPT_API debug(const char* format, ...);
87 void CUPT_API simulate(const char* format, ...);
88 
90 CUPT_API string sf(const string& format, ...);
91 CUPT_API string join(const string& joiner, const vector< string >& parts);
92 CUPT_API string humanReadableSizeString(uint64_t bytes);
94 
95 // TODO/API break/: should return const char*
97 
101 string CUPT_API __(const char* message);
102 
104 
121 void CUPT_API consumePackageName(string::const_iterator begin, string::const_iterator end,
122  string::const_iterator& resultEnd);
123 
125 
130 bool CUPT_API checkPackageName(const string& packageName, bool throwOnError = true);
131 
133 
136 bool CUPT_API checkVersionString(const string& versionString, bool throwOnError = true);
137 
139 
148 int CUPT_API compareVersionStrings(const string& left, const string& right);
149 
150 } // namespace
151 
152 #include <cupt/format2.hpp>
153 
154 #endif
155