Commit d1e3cec2 authored by Martin Marinov's avatar Martin Marinov

Merge remote-tracking branch 'VCI/master' into ReForm-master. Mostly includes...

Merge remote-tracking branch 'VCI/master' into ReForm-master. Mostly includes changes to remove C++11 features.
parents 92fbc136 2ca160d1
......@@ -6,6 +6,10 @@
#include "DebOut.hh"
#include <cstring>
#ifndef WIN32
#include <cstdio>
#endif
namespace Debug {
namespace {
......@@ -32,13 +36,13 @@ void append_function(std::string& _str, const char* const _func)
void append_entry(std::string& _str, const Enter* const _entr,
const bool _cmpct, const bool _entr_nmbr, const Enter* const _prev_entr)
{
if (_prev_entr != nullptr && // there is a previous entry and it is the same?
if (_prev_entr != NULL && // there is a previous entry and it is the same?
strcmp(_prev_entr->function(), _entr->function()) == 0)
{// ... so do nothing
return;
}
if (_prev_entr != nullptr)
if (_prev_entr != NULL)
_str.append("/");
if (_cmpct)
......@@ -47,7 +51,12 @@ void append_entry(std::string& _str, const Enter* const _entr,
_str.append(_entr->function());
if (_entr_nmbr)
_str.append('.' + std::to_string(_entr->number()));
{
_str.append(".");
std::stringstream ss;
ss << _entr->number();
_str.append(ss.str());
}
}
}//namespace
......@@ -68,7 +77,7 @@ const CallStack& CallStack::query()
//bool read(int _up, const char*& _funcname, int& _count)
//{
// const Enter* fcs = call(_up);
// if (fcs != nullptr)
// if (fcs != NULL)
// {
// _funcname = fcs->function();
// _count = fcs->number(); // Return most recent deb_enter_count
......@@ -80,7 +89,7 @@ const CallStack& CallStack::query()
void CallStack::append(std::string& _str, const bool _entr_nmbr) const
{
const Enter* prev = nullptr;
const Enter* prev = NULL;
for (size_t i = 0, n = depth(); i < n; prev = calls_[i++])
append_entry(_str, calls_[i], true, _entr_nmbr, prev);
}
......@@ -93,7 +102,11 @@ void CallStack::append_indent(std::string& _str, const int _indt,
if (_html)
{
char buffer[64];
#ifndef WIN32
sprintf(buffer, "<FONT SIZE=%i>", _indt);
#else
sprintf_s(buffer, sizeof(buffer), "<FONT SIZE=%i>", _indt);
#endif
_str.append(buffer);
}
int num = (int)calls_.size();
......
......@@ -29,10 +29,10 @@ public:
const Enter* call(const int _up = 0) const
{
size_t n = calls_.size();
if (_up < n)
if (_up < (int)n)
return calls_[n - 1 - _up];
else
return nullptr;
return NULL;
}
/*!
......
......@@ -35,7 +35,7 @@ public:
// TODO: this code below only works in ReForm, should be made to work
// for IGM, CoMISo, etc
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());
......@@ -51,8 +51,9 @@ private:
static bool search(const std::string& _flnm,
const std::list<std::string>& _sel_strings)
{
for (const auto& sel : _sel_strings)
for (std::list<std::string>::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;
}
......@@ -84,7 +85,7 @@ private:
void Config::Impl::read()
{
const auto flnm =
const std::string flnm =
System::Environment::variable("REFORM_DEB_CONFIG", "reform_deb.cfg");
std::ifstream cnfg_strm(flnm.c_str());
......@@ -95,7 +96,7 @@ void Config::Impl::read()
std::string type;
line_stream >> type;
void (FilterLevelSelector::*add_string)(const std::string&) = nullptr;
void (FilterLevelSelector::*add_string)(const std::string&) = NULL;
if (type == "all")
{}
......@@ -108,7 +109,7 @@ void Config::Impl::read()
int lvl;
line_stream >> lvl;
if (add_string == nullptr)
if (add_string == NULL)
{
dflt_lvl_ = lvl; // We have read the default level.
continue;
......
......@@ -27,9 +27,9 @@ namespace {
// TODO: make this use std::string; check for html extension; case insensitive
bool is_html_filename(const char* const str)
{
if (str == nullptr) return false;
if (str == NULL) return false;
const char* dot = strrchr(str, '.');
if (dot == nullptr) return false;
if (dot == NULL) return false;
++dot;
return (!strncmp(dot, "htm", 3)) || (!strncmp(dot, "HTM", 3)) ;
}
......@@ -109,7 +109,7 @@ public:
const char* filename() const
{
if (this && (!flnm_.empty())) return flnm_.c_str();
return nullptr;
return NULL;
}
void clear()
......@@ -122,9 +122,9 @@ public:
char prev_char() const
{
if (!bffr_.empty())
return bffr_.back();
return *bffr_.rbegin();
if (!output_.empty())
return output_.back();
return *output_.rbegin();
return '\0';
}
......@@ -190,7 +190,7 @@ public:
void print(const char* const _s, bool _fork = true)
{
if (_s != nullptr)
if (_s != NULL)
{
for (int i = 0; ; ++i)
{
......@@ -232,7 +232,7 @@ public:
void set_double_format(const char* const str)
{
if (str == nullptr)
if (str == NULL)
double_format_.clear();
else
double_format_ = str;
......@@ -421,7 +421,7 @@ public:
return true;
const char* const flnm = filename();
if (flnm == nullptr && !file_is_open())
if (flnm == NULL && !file_is_open())
return false;
if (!file_is_open())
......@@ -473,7 +473,7 @@ public:
void set_filename(const char* const _flnm)
{
flnm_ = _flnm != nullptr ? _flnm : "";
flnm_ = _flnm != NULL ? _flnm : "";
if (is_html_filename(_flnm))
flags_ = flags_ | HTML;
}
......
......@@ -28,8 +28,12 @@
#include "Base/Utils/OStringStream.hh"
#include <string>
#include <sstream>
#include <vector>
#if (_MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__))
#include <array>
#endif
namespace Debug {
......@@ -88,7 +92,7 @@ public:
//! Get the function
const char* function() const { return fnct_; }
//! Get the number of entries in this point
const int number() const { return nmbr_; }
int number() const { return nmbr_; }
//! Get the stream
Stream& 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 &&>((std::ostringstream() << AA )).str()
#else
namespace Debug
{
template <typename T>
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
......
......@@ -3,9 +3,9 @@
#ifndef BASE_CHECKSUMLOGVALUET_HH_INCLUDE
#define BASE_CHECKSUMLOGVALUET_HH_INCLUDE
#ifdef TEST_ON
#include <Base/Test/Checksum.hh>
#ifdef TEST_ON
#include <sstream>
namespace Test {
......
......@@ -2,6 +2,7 @@
#include "Base/Security/Mandatory.hh"
#include "Environment.hh"
#include <cstdlib>
namespace System {
namespace Environment {
......@@ -17,8 +18,8 @@ bool variable(const char* _vrbl_name, std::string& _vrbl)
getenv_s(&char_nmbr, &_vrbl[0], char_nmbr, _vrbl_name);
_vrbl.resize(char_nmbr - 1); // remove the trailing \0 char
#else
const char* vrbl_env = getenv("REFORM_DEB_CONFIG");
if (vrbl_env == nullptr)
const char* vrbl_env = std::getenv("REFORM_DEB_CONFIG");
if (vrbl_env == NULL)
return false;
_vrbl = vrbl_env;
#endif
......
......@@ -86,7 +86,7 @@ IOutputStream& operator<<(IOutputStream& _os, const FunctionNameFilter& _fnf)
for(;;)
{
const char* lmbd_pos = strstr(fnct, lmbd);
if (lmbd_pos == nullptr)
if (lmbd_pos == NULL)
{// print the rest of the function name
_os << fnct;
break;
......@@ -110,8 +110,8 @@ IOutputStream& operator<<(IOutputStream& _os, const CodeLink& _lnk)
const char path_sep = '/';
#endif//WIN32
auto flnm_pntr = strrchr(_lnk.file, path_sep);
if (flnm_pntr == nullptr)
const char* flnm_pntr = strrchr(_lnk.file, path_sep);
if (flnm_pntr == NULL)
flnm_pntr = _lnk.file;
else
++flnm_pntr;
......
......@@ -5,7 +5,9 @@
#include <string>
#include <vector>
#if (_MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__))
#include <array>
#endif
namespace boost {
namespace filesystem {
......@@ -75,12 +77,16 @@ template< typename ElementT>
IOutputStream& operator<<(IOutputStream& _ds, const std::vector<ElementT>& _vec)
{
_ds << "[ ";
for (const auto el : _vec)
for (typename std::vector<ElementT>::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 <typename ElementT, size_t _el_nmbr>
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 <typename ArgT>
OutputStreamAdaptT(const ArgT& _arg) : strm_(_arg) {}
......
......@@ -5,6 +5,12 @@
#include <stdarg.h>
#ifndef WIN32
#include <cstdio>
#include <cstdarg>
#include <sstream>
#endif
namespace Base {
namespace {
......@@ -14,7 +20,11 @@ int sprintf_s(char (&_bffr)[_bffr_size], const char* _frmt, ...)
{
va_list arg_ptr;
va_start(arg_ptr, _frmt);
#ifndef WIN32
int res = vsprintf(_bffr, _frmt, arg_ptr);
#else
int res = vsprintf_s(_bffr, _bffr_size, _frmt, arg_ptr);
#endif // WIN32
va_end(arg_ptr);
return res;
}
......@@ -25,7 +35,11 @@ int print(char* _bffr, const size_t _bffr_size, const char* _frmt, ...)
{
va_list arg_ptr;
va_start(arg_ptr, _frmt);
#ifndef WIN32
int res = vsprintf(_bffr, _frmt, arg_ptr);
#else
int res = vsprintf_s(_bffr, _bffr_size, _frmt, arg_ptr);
#endif
va_end(arg_ptr);
return res;
}
......@@ -38,13 +52,25 @@ IOutputStream& OStringStream::print(const char _c)
IOutputStream& OStringStream::print(const int _i)
{
#ifndef WIN32
std::stringstream ss;
ss << _i;
str.append(ss.str());
#else
str.append(std::to_string(_i));
#endif // WIN32
return *this;
}
IOutputStream& OStringStream::print(const size_t _i)
{
#ifndef WIN32
std::stringstream ss;
ss << _i;
str.append(ss.str());
#else
str.append(std::to_string(_i));
#endif // WIN32
return *this;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment