From 1d6aa957bbe0b9b6ef578ce86a6f3e376909ade3 Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Wed, 23 Mar 2016 10:39:03 +0100 Subject: [PATCH] remove some c++11 features. intermediate commit. --- Debug/DebOut.hh | 21 ++++++++++++++++++++- Debug/DebStream.cc | 28 +++++++++++++++++++++------- Utils/IOutputStream.hh | 19 +++++++++++++------ 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/Debug/DebOut.hh b/Debug/DebOut.hh index ca70e4b..cd38004 100644 --- a/Debug/DebOut.hh +++ b/Debug/DebOut.hh @@ -28,8 +28,12 @@ #include "Base/Utils/OStringStream.hh" #include +#include #include + +#if (_MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) #include +#endif namespace Debug { @@ -83,7 +87,7 @@ public: public: //! Constructor. Stream( - const char* _flnm = nullptr, //!< [in] Filename if file based. + const char* _flnm = NULL, //!< [in] Filename if file based. const uint _flags = APPEND //!< [in] bit-field type identifier ); ~Stream(); @@ -147,8 +151,23 @@ extern void error(const std::string& _err, const ::Base::CodeLink& _lnk); // ostream streamer to DEB_out a class as text without exploiting any // numeric processing or custom Stream streamers then use this macro thus // DEB_out(1, "my_class is " << DEB_os_str(my_c) ) +#if (_MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) #define DEB_os_str(AA) \ dynamic_cast((std::ostringstream() << AA )).str() +#else +namespace Debug +{ +template +std::string toString(const T& t) +{ + std::ostringstream ss; + ss << t; + return ss.str(); +} +}// namespace Debug +#define DEB_os_str(AA) \ + Debug::toString(AA) +#endif #endif // DEB_ON diff --git a/Debug/DebStream.cc b/Debug/DebStream.cc index 5f4b2d7..daa4243 100644 --- a/Debug/DebStream.cc +++ b/Debug/DebStream.cc @@ -26,6 +26,10 @@ #define sprintf_s snprintf #endif +#ifndef nullptr + #define nullptr NULL +#endif + namespace { // TODO: make this use std::string; check for html extension; case insensitive @@ -85,7 +89,15 @@ void add_to_string(const Enter* _deb, std::string& _str, if (!_with_counts) _str.append("*"); else + { +#if (_MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) _str.append(std::to_string(_deb->nmbr_)); +#else + std::stringstream ss; + ss << _deb->nmbr_; + _str.append(ss.str()); +#endif + } _str.append("]"); } @@ -112,7 +124,7 @@ public: const Enter* call(int _up = 0) const { - auto num = calls_.size(); + int num = calls_.size(); if (_up < num) return calls_[num - 1 - _up]; else @@ -228,8 +240,8 @@ public: char prev_char() const { - if (!current_.empty()) return current_.back(); - if (!output_.empty()) return output_.back(); + if (!current_.empty()) return *current_.rbegin(); + if (!output_.empty()) return *output_.rbegin(); return '\0'; } @@ -596,8 +608,9 @@ public: int permission(const char* const _flnm) { int lev = lev_; - for (const auto& fltrs : level_selc_map_) + for (std::map::const_iterator fltrs_it = level_selc_map_.begin(); fltrs_it != level_selc_map_.end(); ++fltrs_it) { + const std::pair& fltrs = *fltrs_it; if (fltrs.second.select_file(_flnm) || fltrs.second.select_function(call_stack_.call()->fnct_)) {// continue this iteration until the maximum allowed level if found @@ -615,7 +628,7 @@ public: void read_debug_config() { - const auto flnm = + const std::string flnm = System::Environment::variable("REFORM_DEB_CONFIG", "reform_deb.cfg"); std::ifstream deb_stream(flnm.c_str()); @@ -664,7 +677,7 @@ private: { std::string flnm(_flnm); const std::string root_dir("ReForm"); - auto pos = flnm.rfind(root_dir); + size_t pos = flnm.rfind(root_dir); if (pos != std::string::npos) flnm = flnm.substr(pos + root_dir.size()); return search(flnm, file_selct_strngs_); @@ -679,8 +692,9 @@ private: static bool search(const std::string& _flnm, const std::list& _sel_strings) { - for (const auto& sel : _sel_strings) + for (std::list::const_iterator sel_it = _sel_strings.begin(); sel_it != _sel_strings.end(); ++sel_it) { + const std::string& sel = *sel_it; if (_flnm.find(sel) != std::string::npos) return true; } diff --git a/Utils/IOutputStream.hh b/Utils/IOutputStream.hh index 631885f..91897c4 100644 --- a/Utils/IOutputStream.hh +++ b/Utils/IOutputStream.hh @@ -5,7 +5,9 @@ #include #include +#if (_MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) #include +#endif namespace boost { namespace filesystem { @@ -75,12 +77,16 @@ template< typename ElementT> IOutputStream& operator<<(IOutputStream& _ds, const std::vector& _vec) { _ds << "[ "; - for (const auto el : _vec) + for (typename std::vector::const_iterator el_it = _vec.begin(); el_it != _vec.end(); ++el_it) + { + const ElementT el = *el_it; _ds << el << " "; + } _ds << "]"; return _ds; } +#if (_MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) // IStream operator for std::array<> template< typename ElementT, size_t _el_nmbr> IOutputStream& operator<<(IOutputStream& _ds, @@ -92,14 +98,15 @@ IOutputStream& operator<<(IOutputStream& _ds, _ds << "]"; return _ds; } +#endif // IStream operator for fixed size arrays template IOutputStream& operator<<(IOutputStream& _ds, const ElementT(&_arr)[_el_nmbr]) { _ds << "[ "; - for (const auto el : _arr) - _ds << el << " "; + for (size_t i = 0; i < _el_nmbr; ++i) + _ds << _arr[i] << " "; _ds << "]"; return _ds; } @@ -124,9 +131,9 @@ public: #else OutputStreamAdaptT() {} - //TODO: get rid of move constructor, cannot submit C++11 code in Base for now - OutputStreamAdaptT(OutputStreamAdaptT&& _oth) : strm_(std::move(_oth.strm_)) - {} +// //TODO: get rid of move constructor, cannot submit C++11 code in Base for now +// OutputStreamAdaptT(OutputStreamAdaptT&& _oth) : strm_(std::move(_oth.strm_)) +// {} template OutputStreamAdaptT(const ArgT& _arg) : strm_(_arg) {} -- GitLab