Commit cfcdeaf6 authored by Martin Marinov's avatar Martin Marinov

Move Debug/DebFileOut.hh/cc to Utils/FileOutput.hh/cc and allow the...

Move Debug/DebFileOut.hh/cc to Utils/FileOutput.hh/cc and allow the functionality to be used outside of Debug
parent 210bb425
......@@ -3,7 +3,6 @@ set(my_headers
${CMAKE_CURRENT_SOURCE_DIR}/DebConfig.hh
${CMAKE_CURRENT_SOURCE_DIR}/DebError.hh
${CMAKE_CURRENT_SOURCE_DIR}/DebFile.hh
${CMAKE_CURRENT_SOURCE_DIR}/DebFileOut.hh
${CMAKE_CURRENT_SOURCE_DIR}/DebIndexMeshOut.hh
${CMAKE_CURRENT_SOURCE_DIR}/DebOut.hh
${CMAKE_CURRENT_SOURCE_DIR}/DebTime.hh
......@@ -15,7 +14,6 @@ set(my_sources
${CMAKE_CURRENT_SOURCE_DIR}/DebConfig.cc
${CMAKE_CURRENT_SOURCE_DIR}/DebCallStack.cc
${CMAKE_CURRENT_SOURCE_DIR}/DebFile.cc
${CMAKE_CURRENT_SOURCE_DIR}/DebFileOut.cc
${CMAKE_CURRENT_SOURCE_DIR}/DebIndexMeshOut.cc
${CMAKE_CURRENT_SOURCE_DIR}/DebStream.cc
PARENT_SCOPE
......
......@@ -4,7 +4,7 @@
#include "Base/Security/Mandatory.hh"
#include "DebIndexMeshOut.hh"
#include "DebFileOut.hh"
#include "Base/Utils/FileOutput.hh"
#ifdef DEB_ON
......@@ -18,10 +18,10 @@ bool save(Enter& deb, const char* const _flnm, const size_t _pnt_nmbr,
const CoordT* const _crds, const int _face_size, const size_t _face_nmbr,
const IndexT* const _indcs)
{
const auto mesh_flnm = make_filename("mesh", _flnm, "obj");
const auto mesh_flnm = Base::make_filename("mesh", _flnm, "obj");
try
{
save_mesh_obj(
Base::save_mesh_obj(
mesh_flnm.c_str(), _pnt_nmbr, _crds, _face_size, _face_nmbr, _indcs);
DEB_line(0, "Saved mesh as " << mesh_flnm);
return true;
......
......@@ -2,6 +2,7 @@ set(my_headers
${CMAKE_CURRENT_SOURCE_DIR}/BaseError.hh
${CMAKE_CURRENT_SOURCE_DIR}/BaseErrorInc.hh
${CMAKE_CURRENT_SOURCE_DIR}/Environment.hh
${CMAKE_CURRENT_SOURCE_DIR}/FileOutput.hh
${CMAKE_CURRENT_SOURCE_DIR}/IOutputStream.hh
${CMAKE_CURRENT_SOURCE_DIR}/OStringStream.hh
${CMAKE_CURRENT_SOURCE_DIR}/StopWatch.hh
......@@ -13,6 +14,7 @@ set(my_headers
set(my_sources
${CMAKE_CURRENT_SOURCE_DIR}/BaseError.cc
${CMAKE_CURRENT_SOURCE_DIR}/Environment.cc
${CMAKE_CURRENT_SOURCE_DIR}/FileOutput.cc
${CMAKE_CURRENT_SOURCE_DIR}/IOutputStream.cc
${CMAKE_CURRENT_SOURCE_DIR}/OStringStream.cc
${CMAKE_CURRENT_SOURCE_DIR}/StopWatch.cc
......
// (C) Copyright 2020 by Autodesk, Inc.
#include "DebFileOut.hh"
#include "FileOutput.hh"
#include <string>
#include <sstream>
#include <iomanip>
#include <iomanip>
#include <fstream>
#include <limits>
namespace Debug {
namespace Base
{
std::string make_filename(const char* _prfx, const char* _flnm,
const char* _ext, const char* _sfx)
std::string make_filename(
const char* _prfx, const char* _flnm, const char* _ext, const char* _sfx)
{
static int cnt = 0;
const char SEP = '_';
......@@ -29,7 +30,7 @@ std::string set_filename_extension(const char* _flnm, const char* _ext)
{
std::string flnm(_flnm);
const size_t dot_pos = flnm.find_last_of('.');
if (dot_pos != std::string::npos)
if (dot_pos != std::string::npos)
flnm.replace(flnm.begin() + dot_pos + 1, flnm.end(), _ext);
else
flnm += std::string(".") + _ext;
......@@ -47,7 +48,7 @@ void save_mesh_obj(const char* const _flnm, const size_t _pnt_nmbr,
const IndexT* const _indcs)
{
std::ofstream strm(set_filename_extension(_flnm, "obj")); // open
strm.imbue(std::locale("C")); // C-locale
strm.imbue(std::locale("C")); // C-locale
strm << std::setprecision(std::numeric_limits<CoordT>::max_digits10);
for (size_t i = 0, n = 3 * _pnt_nmbr; i < n; i += 3)
......@@ -76,9 +77,9 @@ void save_mesh_off(const char* const _flnm, const size_t _pnt_nmbr,
const IndexT* const _indcs)
{
std::ofstream strm(set_filename_extension(_flnm, "off")); // open
strm.imbue(std::locale("C")); // C-locale
strm << std::setprecision(std::numeric_limits<CoordT>::max_digits10);
strm << "OFF" << std::endl; // write header
strm.imbue(std::locale("C")); // C-locale
strm << std::setprecision(std::numeric_limits<CoordT>::max_digits10);
strm << "OFF" << std::endl; // write header
strm << _pnt_nmbr << ' ' << _face_nmbr << std::endl;
for (size_t i = 0, n = 3 * _pnt_nmbr; i < n; i += 3)
......@@ -98,4 +99,4 @@ SAVE_MESH(off, float, int);
SAVE_MESH(off, double, unsigned int);
SAVE_MESH(off, float, unsigned int);
} // Debug
} // namespace Base
// (C) Copyright 2020 by Autodesk, Inc.
#ifndef BASE_DEBFILEOUT_HH_INCLUDED
#define BASE_DEBFILEOUT_HH_INCLUDED
#ifdef DEB_ON
#ifndef BASE_FILE_OUTPUT_HH_INCLUDED
#define BASE_FILE_OUTPUT_HH_INCLUDED
#include <string>
#include <Base/Config/BaseDefines.hh>
#include <string>
namespace Debug
namespace Base
{
//! Make a file name composing the input arguments:
// #count#_prefix_filename[_suffix].ext
// count is a number that increase any time the function is called,
......@@ -34,8 +32,6 @@ void save_mesh_off(const char* const _flnm, const size_t _pnt_nmbr,
const CoordT* const _crds, const int _face_size, const size_t _face_nmbr,
const IndexT* const _indcs);
} // namespace Debug
#endif // DEB_ON
} // namespace Base
#endif // BASE_DEBFILEOUT_HH_INCLUDED
#endif // BASE_FILE_OUTPUT_HH_INCLUDED
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