IOutputStream.cc 2.28 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
// (C) Copyright 2016 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk,  Inc.,  and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of  this information  by  anyone  other  than  authorized
// employees of Autodesk, Inc.  is granted  only under a written
// non-disclosure agreement,  expressly  prescribing  the  scope
// and manner of such use.

#include "Base/Security/Mandatory.hh"
#include "IOutputStream.hh"
#include "Base/Code/CodeLink.hh"
#include "Base/Utils/ThrowError.hh"

#include <boost/filesystem.hpp>
#include <string>

namespace Base {

IOutputStream& operator<<(IOutputStream& _ds, const int _i)
{
  return _ds.print(_i);
}

IOutputStream& operator<<(IOutputStream& _ds, const double _d)
{
  return _ds.print(_d);
}

IOutputStream& operator<<(IOutputStream& _ds, const char* const _s)
{
  return _ds.print(_s);
}

IOutputStream& operator<<(IOutputStream& _ds, const char _c)
{
  return _ds.print(_c);
}

IOutputStream& operator<<(IOutputStream& _ds, const size_t _i)
{
  return _ds.print(_i);
}

IOutputStream& operator<<(IOutputStream& _ds, const unsigned int _i)
{
  return _ds.print(size_t(_i));
}

IOutputStream& operator<<(IOutputStream& _ds, const float _f)
{
  return _ds.print((double)_f);
}

IOutputStream& operator<<(IOutputStream& _ds, const std::string& _s)
{
  return _ds.print(_s.c_str());
}

IOutputStream& operator<<(IOutputStream& _ds, const Command& _co)
{
  return _ds.print(_co);
}

IOutputStream& operator<<(IOutputStream& _ds, const boost::filesystem::path& _path)
{
  return _ds << '\"' << _path.string().c_str() << '\"';
}

IOutputStream& operator<<(IOutputStream& _os, const CodeLink& _lnk)
{
#ifdef WIN32
  const char path_sep = '\\';
#else//!WIN32
  const char path_sep = '/';
#endif//WIN32
  
  auto flnm_pntr = strrchr(_lnk.file, path_sep); 
  if (flnm_pntr == nullptr) 
    flnm_pntr = _lnk.file;
  else
    ++flnm_pntr;

  return _os << "@ [" << _lnk.fnct << "() in " 
    << flnm_pntr << ":" << _lnk.line << "]";
}

}//namespace Base

#ifdef DEB_ON
namespace Debug {

Base::IOutputStream& operator<<(Base::IOutputStream& _ds, 
  const ThrowInfo& _thrw_info)
{
  return _ds << "thrown in " << _thrw_info.modl << " " << _thrw_info.lnk;
}

}//namespace Debug
#endif//DEB_ON