STOFFDebug.hxx
Go to the documentation of this file.
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
/* libstaroffice
* Version: MPL 2.0 / LGPLv2+
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
*
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
* in which case the provisions of the LGPLv2+ are applicable
* instead of those above.
*/
#ifndef STOFF_DEBUG
# define STOFF_DEBUG
#include <string>
#include "STOFFInputStream.hxx"
# if defined(DEBUG_WITH_FILES)
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
namespace libstoff
{
namespace Debug
{
bool dumpFile(librevenge::RVNGBinaryData &data, char const *fileName);
std::string flattenFileName(std::string const &name);
}
typedef std::stringstream DebugStream;
class DebugFile
{
public:
explicit DebugFile(STOFFInputStreamPtr ip=STOFFInputStreamPtr())
: m_fileName("")
, m_file()
, m_on(false)
, m_input(ip)
, m_actOffset(-1)
, m_notes()
, m_skipZones() { }
void setStream(STOFFInputStreamPtr &ip)
{
m_input = ip;
}
~DebugFile()
{
reset();
}
bool open(std::string const &filename);
void reset()
{
write();
m_fileName="";
m_file.close();
m_on = false;
m_notes.resize(0);
m_skipZones.resize(0);
m_actOffset = -1;
}
void write();
void addPos(long pos);
void addNote(char const *note);
void addDelimiter(long pos, char c);
void skipZone(long beginPos, long endPos)
{
if (m_on) m_skipZones.push_back(STOFFVec2<long>(beginPos, endPos));
}
protected:
void sort();
mutable std::string m_fileName;
mutable std::ofstream m_file;
mutable bool m_on;
STOFFInputStreamPtr m_input;
struct NotePos {
NotePos()
: m_pos(-1)
, m_text("")
, m_breaking(false) { }
NotePos(long p, std::string const &n, bool br=true)
: m_pos(p)
, m_text(n)
, m_breaking(br) {}
long m_pos;
std::string m_text;
bool m_breaking;
bool operator<(NotePos const &p) const
{
long diff = m_pos-p.m_pos;
if (diff) return (diff < 0) ? true : false;
if (m_breaking != p.m_breaking) return m_breaking;
return m_text < p.m_text;
}
struct NotePosLt {
bool operator()(NotePos const &s1, NotePos const &s2) const
{
return s1 < s2;
}
};
};
long m_actOffset;
std::vector<NotePos> m_notes;
std::vector<STOFFVec2<long> > m_skipZones;
};
}
# else
namespace libstoff
{
namespace Debug
{
inline bool dumpFile(librevenge::RVNGBinaryData &, char const *)
{
return true;
}
inline std::string flattenFileName(std::string const &name)
{
return name;
}
}
class DebugStream
{
public:
template <class T>
DebugStream &operator<<(T const &)
{
return *this;
}
static std::string str()
{
return std::string("");
}
static void str(std::string const &) { }
};
class DebugFile
{
public:
explicit DebugFile(STOFFInputStreamPtr) {}
DebugFile() {}
static void setStream(STOFFInputStreamPtr) { }
~DebugFile() { }
static bool open(std::string const &)
{
return true;
}
static void addPos(long) {}
static void addNote(char const *) {}
static void addDelimiter(long, char) {}
static void write() {}
static void reset() { }
static void skipZone(long, long) {}
};
}
# endif
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
STOFFInputStream.hxx
libstoff::DebugFile
Definition STOFFDebug.hxx:211
libstoff::DebugFile::addPos
static void addPos(long)
Definition STOFFDebug.hxx:223
libstoff::DebugFile::DebugFile
DebugFile()
Definition STOFFDebug.hxx:214
libstoff::DebugFile::setStream
static void setStream(STOFFInputStreamPtr)
Definition STOFFDebug.hxx:215
libstoff::DebugFile::DebugFile
DebugFile(STOFFInputStreamPtr)
Definition STOFFDebug.hxx:213
libstoff::DebugFile::write
static void write()
Definition STOFFDebug.hxx:227
libstoff::DebugFile::open
static bool open(std::string const &)
Definition STOFFDebug.hxx:218
libstoff::DebugFile::~DebugFile
~DebugFile()
Definition STOFFDebug.hxx:216
libstoff::DebugFile::addNote
static void addNote(char const *)
Definition STOFFDebug.hxx:224
libstoff::DebugFile::reset
static void reset()
Definition STOFFDebug.hxx:228
libstoff::DebugFile::skipZone
static void skipZone(long, long)
Definition STOFFDebug.hxx:230
libstoff::DebugFile::addDelimiter
static void addDelimiter(long, char)
Definition STOFFDebug.hxx:225
libstoff::DebugStream
Definition STOFFDebug.hxx:195
libstoff::DebugStream::str
static std::string str()
Definition STOFFDebug.hxx:203
libstoff::DebugStream::operator<<
DebugStream & operator<<(T const &)
Definition STOFFDebug.hxx:198
libstoff::DebugStream::str
static void str(std::string const &)
Definition STOFFDebug.hxx:207
STOFFInputStreamPtr
std::shared_ptr< STOFFInputStream > STOFFInputStreamPtr
a smart pointer of STOFFInputStream
Definition libstaroffice_internal.hxx:489
libstoff::Debug
Definition STOFFDebug.hxx:182
libstoff::Debug::dumpFile
bool dumpFile(librevenge::RVNGBinaryData &, char const *)
Definition STOFFDebug.hxx:183
libstoff::Debug::flattenFileName
std::string flattenFileName(std::string const &name)
returns a file name from an ole/... name
Definition STOFFDebug.hxx:188
libstoff
namespace used to regroup all libwpd functions, enumerations which we have redefined for internal usa...
Definition libstaroffice_internal.cxx:51