WIP: remove the old database abstraction layer
remove such classes: - DbBase - DbConn - DbTextStream - Db while here: - remove: TextStream, SLog, TexTextStream
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -32,6 +32,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "core/misc.h"
|
||||
#include "templates.h"
|
||||
#include "core/request.h"
|
||||
#include "misc.h"
|
||||
|
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "core/slog.h"
|
||||
#include "templates.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
static size_t slog_index = 0;
|
||||
static LogManipulators slog_last_type;
|
||||
|
||||
|
||||
|
||||
bool slog_is()
|
||||
{
|
||||
if( !cur->session )
|
||||
return false;
|
||||
|
||||
return slog_index < cur->session->log_buffer.Size();
|
||||
}
|
||||
|
||||
|
||||
void slog_skipline()
|
||||
{
|
||||
if( !cur->session )
|
||||
return;
|
||||
|
||||
TextStream<std::wstring> & buf = cur->session->log_buffer;
|
||||
|
||||
while( slog_index < buf.Size() && buf[slog_index]!=10 )
|
||||
slog_index += 1;
|
||||
|
||||
if( slog_index < buf.Size() )
|
||||
slog_index += 1; // skipping the '\n'
|
||||
}
|
||||
|
||||
|
||||
void slog_settype()
|
||||
{
|
||||
if( !slog_is() )
|
||||
return;
|
||||
|
||||
TextStream<std::wstring> & buf = cur->session->log_buffer;
|
||||
slog_last_type = static_cast<LogManipulators>(buf[slog_index]);
|
||||
|
||||
switch( slog_last_type )
|
||||
{
|
||||
case loginfo:
|
||||
case logwarning:
|
||||
case logerror:
|
||||
slog_index += 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
slog_last_type = loginfo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void slog_tab(Info & i)
|
||||
{
|
||||
if( i.iter == 0 )
|
||||
slog_index = 0;
|
||||
else
|
||||
slog_skipline();
|
||||
|
||||
// the type is written as the first character (after '\n' or at the beginning of the string)
|
||||
slog_settype();
|
||||
|
||||
i.res = slog_is();
|
||||
|
||||
if( cur->session && !i.res )
|
||||
cur->session->log_buffer.Clear(); // the session log has been printed
|
||||
}
|
||||
|
||||
|
||||
void slog_tab_is_info(Info & i)
|
||||
{
|
||||
if( !slog_is() )
|
||||
return;
|
||||
|
||||
i.res = (slog_last_type == loginfo);
|
||||
}
|
||||
|
||||
|
||||
void slog_tab_is_warning(Info & i)
|
||||
{
|
||||
if( !slog_is() )
|
||||
return;
|
||||
|
||||
i.res = (slog_last_type == logwarning);
|
||||
}
|
||||
|
||||
|
||||
void slog_tab_is_error(Info & i)
|
||||
{
|
||||
if( !slog_is() )
|
||||
return;
|
||||
|
||||
i.res = (slog_last_type == logerror);
|
||||
}
|
||||
|
||||
|
||||
void slog_tab_print(Info & i)
|
||||
{
|
||||
if( !slog_is() )
|
||||
return;
|
||||
|
||||
TextStream<std::wstring> & buf = cur->session->log_buffer;
|
||||
|
||||
while( slog_index < buf.Size() && buf[slog_index]!=10 )
|
||||
{
|
||||
i.out << buf[slog_index];
|
||||
slog_index += 1;
|
||||
}
|
||||
|
||||
// don't skip the last '\n' here
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2022, Tomasz Sowa
|
||||
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -33,9 +33,7 @@
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "core/misc.h"
|
||||
#include "core/plugin.h"
|
||||
#include "core/textstream.h"
|
||||
#include "functions/functions.h"
|
||||
|
||||
namespace Winix
|
||||
@@ -75,7 +73,6 @@ const HtmlTextStream empty_stream;
|
||||
// en empty stack item for templates functions
|
||||
Ezc::Stack empty_stack;
|
||||
|
||||
Db * db = nullptr;
|
||||
Cur * cur = nullptr;
|
||||
Config * config = nullptr;
|
||||
System * system = nullptr;
|
||||
@@ -481,16 +478,6 @@ void Templates::CreateFunctions()
|
||||
ezc_functions.Insert("server_mode_is", server_mode_is);
|
||||
|
||||
|
||||
/*
|
||||
slog
|
||||
*/
|
||||
ezc_functions.Insert("slog_tab", slog_tab);
|
||||
ezc_functions.Insert("slog_tab_is_info", slog_tab_is_info);
|
||||
ezc_functions.Insert("slog_tab_is_warning", slog_tab_is_warning);
|
||||
ezc_functions.Insert("slog_tab_is_error", slog_tab_is_error);
|
||||
ezc_functions.Insert("slog_tab_print", slog_tab_print);
|
||||
|
||||
|
||||
/*
|
||||
stat
|
||||
*/
|
||||
@@ -1021,11 +1008,6 @@ void Templates::SetCur(Cur * pcur)
|
||||
|
||||
|
||||
|
||||
void Templates::SetDb(Db * pdb)
|
||||
{
|
||||
TemplatesFunctions::db = pdb;
|
||||
}
|
||||
|
||||
|
||||
void Templates::SetSystem(System * psystem)
|
||||
{
|
||||
|
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2022, Tomasz Sowa
|
||||
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -51,7 +51,6 @@
|
||||
#include "core/system.h"
|
||||
#include "core/sessionmanager.h"
|
||||
#include "html/htmlparser.h"
|
||||
#include "db/db.h"
|
||||
#include "core/winixrequest.h"
|
||||
|
||||
|
||||
@@ -81,7 +80,6 @@ namespace TemplatesFunctions
|
||||
extern pt::HTMLParser html_filter;
|
||||
extern Ezc::Stack empty_stack;
|
||||
|
||||
extern Db * db;
|
||||
extern Cur * cur; // will be removed when TemplateBase class will be implemented
|
||||
extern Config * config; // will be removed when TemplateBase class will be implemented
|
||||
extern System * system; // will be removed when TemplateBase class will be implemented
|
||||
@@ -404,16 +402,6 @@ namespace TemplatesFunctions
|
||||
void server_mode_is(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
slog
|
||||
*/
|
||||
void slog_tab(Info & i);
|
||||
void slog_tab_is_info(Info & i);
|
||||
void slog_tab_is_warning(Info & i);
|
||||
void slog_tab_is_error(Info & i);
|
||||
void slog_tab_print(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
stat
|
||||
*/
|
||||
@@ -581,7 +569,6 @@ public:
|
||||
|
||||
void SetConfig(Config * pconfig);
|
||||
void SetCur(Cur * pcur);
|
||||
void SetDb(Db * pdb);
|
||||
void SetSystem(System * psystem);
|
||||
void SetFunctions(Functions * pfunctions);
|
||||
void SetSessionManager(SessionManager * psession_manager);
|
||||
|
@@ -1,504 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "textextstream.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
TexTextStream::TexTextStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
without escaping
|
||||
*/
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutChar(char c)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(c);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutChar(wchar_t c)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(c);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const char * str)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const char * str, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const std::string * str)
|
||||
{
|
||||
return PutText(str->c_str());
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const std::string & str)
|
||||
{
|
||||
return PutText(str.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const wchar_t * str)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const std::wstring * str)
|
||||
{
|
||||
return PutText(str->c_str());
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const std::wstring & str)
|
||||
{
|
||||
return PutText(str.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const RawText<const char*> & raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const RawText<const wchar_t*> & raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<const std::string*> raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<const std::wstring*> raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<std::string> raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<std::wstring> raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<char> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<wchar_t> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<int> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<long> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<unsigned int> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<unsigned long> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<double> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<void*> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::Write(const char * buf, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::Write(buf, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
TexTextStream & TexTextStream::Write(const wchar_t * buf, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::Write(buf, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::write(const char * buf, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::write(buf, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
TexTextStream & TexTextStream::write(const wchar_t * buf, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::write(buf, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
with escaping
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::ETextPutChar(char c)
|
||||
{
|
||||
return ETextPutChar(static_cast<wchar_t>(c));
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::ETextPutChar(wchar_t c)
|
||||
{
|
||||
if( c == '$' )
|
||||
buffer += L"\\$";
|
||||
else
|
||||
if( c == '#' )
|
||||
buffer += L"\\#";
|
||||
else
|
||||
if( c == '%' )
|
||||
buffer += L"\\%";
|
||||
else
|
||||
if( c == '&' )
|
||||
buffer += L"\\&";
|
||||
else
|
||||
if( c == '\\' )
|
||||
buffer += L"$\\backslash$";
|
||||
else
|
||||
if( c == '{' )
|
||||
buffer += L"$\\{$";
|
||||
else
|
||||
if( c == '}' )
|
||||
buffer += L"$\\}$";
|
||||
else
|
||||
if( c == '^' )
|
||||
buffer += L""; // !! IMPROVE ME add \char with specific code
|
||||
else
|
||||
if( c == '_' )
|
||||
buffer += L"\\_";
|
||||
else
|
||||
if( c == '~' )
|
||||
buffer += L""; // !! IMPROVE ME add \char with specific code
|
||||
else
|
||||
if( c == '-' )
|
||||
buffer += L"{-}";
|
||||
else
|
||||
if( c != 0 )
|
||||
buffer += c;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const char * str)
|
||||
{
|
||||
for( ; *str ; ++str )
|
||||
ETextPutChar(*str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const char * str, size_t len)
|
||||
{
|
||||
for(size_t i=0 ; i<len ; ++i)
|
||||
ETextPutChar(str[i]);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const std::string * str)
|
||||
{
|
||||
return EPutText(str->c_str(), str->size());
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const std::string & str)
|
||||
{
|
||||
return EPutText(str.c_str(), str.size());
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const wchar_t * str)
|
||||
{
|
||||
for( ; *str ; ++str )
|
||||
ETextPutChar(*str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const wchar_t * str, size_t len)
|
||||
{
|
||||
for(size_t i=0 ; i<len ; ++i)
|
||||
ETextPutChar(str[i]);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const std::wstring * str)
|
||||
{
|
||||
return EPutText(str->c_str(), str->size());
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const std::wstring & str)
|
||||
{
|
||||
return EPutText(str.c_str(), str.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const char * str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const std::string * str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const std::string & str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const wchar_t * str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const std::wstring * str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const std::wstring & str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(char v)
|
||||
{
|
||||
ETextPutChar(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(wchar_t v)
|
||||
{
|
||||
ETextPutChar(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(int v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(long v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(unsigned int v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(unsigned long v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(double v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const void * v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const pt::Space & space)
|
||||
{
|
||||
tmp_stream.Clear();
|
||||
// !! IMPROVE ME
|
||||
// we can calculate how many memory is needed beforehand
|
||||
space.serialize_to_space_stream(tmp_stream, true);
|
||||
operator<<(tmp_stream.Str());
|
||||
tmp_stream.Clear();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const pt::Date & date)
|
||||
{
|
||||
tmp_stream.Clear();
|
||||
// !! IMPROVE ME
|
||||
// we can calculate how many memory is needed beforehand
|
||||
date.Serialize(tmp_stream);
|
||||
operator<<(tmp_stream.Str());
|
||||
tmp_stream.Clear();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
@@ -1,216 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_templates_textextstream
|
||||
#define headerfile_winix_templates_textextstream
|
||||
|
||||
#include <ctime>
|
||||
#include "core/textstream.h"
|
||||
#include "textstream/textstream.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
TexTextStream is used as a buffer for creating a TeX input
|
||||
By default all operators<< escape its string arguments. If you don't want
|
||||
to escape an argument you should use a helper function R() (raw argument)
|
||||
note: you have to define the function yourself, we do not provide it
|
||||
because such a short name would make a mess in namespaces
|
||||
|
||||
sample:
|
||||
create a helper function R as follows:
|
||||
|
||||
template<class RawType>
|
||||
TexTextStream::RawText<RawType> R(const RawType & par)
|
||||
{
|
||||
return TexTextStream::RawText<RawType>(par);
|
||||
}
|
||||
|
||||
now you can use TexTextStream in an easy way:
|
||||
TexTextStream page;
|
||||
std::string key = "some text with $# ^{} tex \\ special characters";
|
||||
page << key << R("\\def\\myfun{...}");
|
||||
|
||||
everything in 'key' is property escaped for using with TeX
|
||||
*/
|
||||
class TexTextStream : public TextStream<std::wstring>
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
TexTextStream();
|
||||
|
||||
|
||||
/*
|
||||
a helper struct to select a proper operator<<
|
||||
(for non-escaping versions of these operators)
|
||||
*/
|
||||
template<class RawType>
|
||||
struct RawText
|
||||
{
|
||||
const RawType & par;
|
||||
|
||||
RawText(const RawText<RawType> & p) : par(p.par) {}
|
||||
RawText(const RawType & p) : par(p) {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
without escaping
|
||||
*/
|
||||
TexTextStream & PutChar(char);
|
||||
TexTextStream & PutChar(wchar_t);
|
||||
|
||||
TexTextStream & PutText(const char *);
|
||||
TexTextStream & PutText(const char *, size_t len);
|
||||
TexTextStream & PutText(const std::string *);
|
||||
TexTextStream & PutText(const std::string &);
|
||||
TexTextStream & PutText(const wchar_t * str);
|
||||
TexTextStream & PutText(const wchar_t * str, size_t len);
|
||||
TexTextStream & PutText(const std::wstring * str);
|
||||
TexTextStream & PutText(const std::wstring & str);
|
||||
|
||||
/*
|
||||
we need this template operator for such calling:
|
||||
HtmlTextStream_object << R("some string");
|
||||
"some string" is actually a table (not a pointer)
|
||||
*/
|
||||
template<size_t str_size>
|
||||
TexTextStream & operator<<(const RawText<char [str_size]> & raw) { return PutText(raw.par); }
|
||||
|
||||
template<size_t str_size>
|
||||
TexTextStream & operator<<(const RawText<wchar_t [str_size]> & raw) { return PutText(raw.par); }
|
||||
|
||||
TexTextStream & operator<<(const RawText<const char*> & raw);
|
||||
TexTextStream & operator<<(const RawText<const wchar_t*> & raw);
|
||||
TexTextStream & operator<<(RawText<const std::string*> raw);
|
||||
TexTextStream & operator<<(RawText<const std::wstring*> raw);
|
||||
TexTextStream & operator<<(RawText<std::string> raw);
|
||||
TexTextStream & operator<<(RawText<std::wstring> raw);
|
||||
|
||||
TexTextStream & operator<<(RawText<char> raw);
|
||||
TexTextStream & operator<<(RawText<wchar_t> raw);
|
||||
TexTextStream & operator<<(RawText<int> raw);
|
||||
TexTextStream & operator<<(RawText<long> raw);
|
||||
TexTextStream & operator<<(RawText<unsigned int> raw);
|
||||
TexTextStream & operator<<(RawText<unsigned long> raw);
|
||||
TexTextStream & operator<<(RawText<double> raw);
|
||||
TexTextStream & operator<<(RawText<void*> raw);
|
||||
|
||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
TexTextStream & operator<<(RawText<pt::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> > raw);
|
||||
|
||||
|
||||
// 'write' don't escapes too
|
||||
// with these methods you can write a zero character too
|
||||
TexTextStream & Write(const char * buf, size_t len);
|
||||
TexTextStream & Write(const wchar_t * buf, size_t len);
|
||||
// for compatibility with standard library (Ezc uses it)
|
||||
TexTextStream & write(const char * buf, size_t len);
|
||||
TexTextStream & write(const wchar_t * buf, size_t len);
|
||||
|
||||
|
||||
/*
|
||||
with escaping
|
||||
*/
|
||||
|
||||
TexTextStream & ETextPutChar(char c);
|
||||
TexTextStream & ETextPutChar(wchar_t c);
|
||||
|
||||
TexTextStream & EPutText(const char * str);
|
||||
TexTextStream & EPutText(const char * str, size_t len);
|
||||
TexTextStream & EPutText(const std::string * str);
|
||||
TexTextStream & EPutText(const std::string & str);
|
||||
TexTextStream & EPutText(const wchar_t * str);
|
||||
TexTextStream & EPutText(const wchar_t * str, size_t len);
|
||||
TexTextStream & EPutText(const std::wstring * str);
|
||||
TexTextStream & EPutText(const std::wstring & str);
|
||||
|
||||
|
||||
TexTextStream & operator<<(const char * str);
|
||||
TexTextStream & operator<<(const std::string * str);
|
||||
TexTextStream & operator<<(const std::string & str);
|
||||
TexTextStream & operator<<(const wchar_t * str);
|
||||
TexTextStream & operator<<(const std::wstring * str);
|
||||
TexTextStream & operator<<(const std::wstring & str);
|
||||
TexTextStream & operator<<(char);
|
||||
TexTextStream & operator<<(wchar_t);
|
||||
TexTextStream & operator<<(int);
|
||||
TexTextStream & operator<<(long);
|
||||
TexTextStream & operator<<(unsigned int);
|
||||
TexTextStream & operator<<(unsigned long);
|
||||
TexTextStream & operator<<(double);
|
||||
TexTextStream & operator<<(const void *);
|
||||
TexTextStream & operator<<(const pt::Space & space);
|
||||
TexTextStream & operator<<(const pt::Date & Date);
|
||||
|
||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
TexTextStream & operator<<(const pt::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg);
|
||||
|
||||
private:
|
||||
|
||||
TextStream<std::wstring> tmp_stream;
|
||||
|
||||
};
|
||||
|
||||
|
||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
TexTextStream & TexTextStream::operator<<(RawText<pt::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> > raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
TexTextStream & TexTextStream::operator<<(const pt::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg)
|
||||
{
|
||||
typename pt::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size>::const_iterator i;
|
||||
|
||||
for(i=arg.begin() ; i != arg.end() ; ++i)
|
||||
ETextPutChar(*i);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
#endif
|
||||
|
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -33,6 +33,7 @@
|
||||
*/
|
||||
|
||||
#include <ctime>
|
||||
#include "core/misc.h"
|
||||
#include "core/request.h"
|
||||
#include "templates.h"
|
||||
#include "misc.h"
|
||||
|
Reference in New Issue
Block a user