Cupt
common.hpp
Go to the documentation of this file.
00001 /**************************************************************************
00002 *   Copyright (C) 2010 by Eugene V. Lyubimkin                             *
00003 *                                                                         *
00004 *   This program is free software; you can redistribute it and/or modify  *
00005 *   it under the terms of the GNU General Public License                  *
00006 *   (version 3 or above) as published by the Free Software Foundation.    *
00007 *                                                                         *
00008 *   This program is distributed in the hope that it will be useful,       *
00009 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00010 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00011 *   GNU General Public License for more details.                          *
00012 *                                                                         *
00013 *   You should have received a copy of the GNU GPL                        *
00014 *   along with this program; if not, write to the                         *
00015 *   Free Software Foundation, Inc.,                                       *
00016 *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA               *
00017 **************************************************************************/
00018 #ifndef CUPT_COMMON_SEEN
00019 #define CUPT_COMMON_SEEN
00020 
00022 #define CUPT_API __attribute__ ((visibility("default")))
00023 #define CUPT_LOCAL __attribute__ ((visibility("hidden")))
00024 
00025 
00028 #include <string>
00029 #include <vector>
00030 #include <memory>
00031 #include <stdexcept>
00032 
00034 namespace cupt {
00035 
00036 CUPT_API extern const char* const libraryVersion; 
00037 
00038 using std::vector;
00039 using std::string;
00040 
00042 
00045 class CUPT_API Exception: public std::runtime_error
00046 {
00047  public:
00049 
00054     Exception(const char* message)
00055         : std::runtime_error(message)
00056     {}
00058 
00061     Exception(const string& message)
00062         : std::runtime_error(message)
00063     {}
00064 };
00065 
00066 using std::pair;
00067 
00068 using std::shared_ptr;
00069 using std::static_pointer_cast;
00070 using std::dynamic_pointer_cast;
00071 
00073 
00077 CUPT_API extern int messageFd;
00078 
00079 // TODO/API break/: remove fatal, warn, debug, simulate, sf
00081 void CUPT_API fatal(const char* format, ...);
00083 void CUPT_API warn(const char* format, ...);
00085 void CUPT_API debug(const char* format, ...);
00087 void CUPT_API simulate(const char* format, ...);
00088 
00090 CUPT_API string sf(const string& format, ...);
00091 CUPT_API string join(const string& joiner, const vector< string >& parts);
00092 CUPT_API string humanReadableSizeString(uint64_t bytes);
00094 
00095 // TODO/API break/: should return const char*
00097 
00101 string CUPT_API __(const char* message);
00102 
00104 
00121 void CUPT_API consumePackageName(string::const_iterator begin, string::const_iterator end,
00122         string::const_iterator& resultEnd);
00123 
00125 
00130 bool CUPT_API checkPackageName(const string& packageName, bool throwOnError = true);
00131 
00133 
00136 bool CUPT_API checkVersionString(const string& versionString, bool throwOnError = true);
00137 
00139 
00148 int CUPT_API compareVersionStrings(const string& left, const string& right);
00149 
00150 } // namespace
00151 
00152 #include <cupt/format2.hpp>
00153 
00154 #endif
00155