removed: in some places a dependencies to tm struct has left

removed: operator<<(tm&) from streams: textstream, log, dbtextstream, htmltextstream



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@840 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2012-05-27 18:11:34 +00:00
parent 1b858f5782
commit 9d5d088b4a
14 changed files with 24 additions and 159 deletions

View File

@ -20,7 +20,7 @@ Item::Item()
// !! IMPROVE ME
// now we have Request::start_time and Request::start_tm
// now we have Request::start_time and Request::start_date
// we can somehow get the current time from the request
// may setting the date should be completetly removed from here?
void Item::SetDateToNow()

View File

@ -227,16 +227,6 @@ return *this;
}
Log & Log::operator<<(const tm & tm_)
{
if( current_level <= log_level )
{
buffer << tm_;
}
return *this;
}
Log & Log::operator<<(const PT::Date & date)
{
@ -249,6 +239,7 @@ return *this;
}
Log & Log::operator<<(LogManipulators m)
{
switch(m)

View File

@ -44,7 +44,6 @@ public:
Log & operator<<(double s);
Log & operator<<(const PT::Space & space);
Log & operator<<(LogManipulators m);
Log & operator<<(const tm & tm_);
Log & operator<<(const PT::Date & date);

View File

@ -60,7 +60,6 @@ public:
TextStream & operator<<(double);
TextStream & operator<<(const void *);// printing a pointer
TextStream & operator<<(const PT::Space & space);
TextStream & operator<<(const tm & tm_);
TextStream & operator<<(const PT::Date & date);
TextStream & Write(const char * buf, size_t len);
@ -318,26 +317,6 @@ return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const tm & tm_)
{
char buf[50];
sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d",
tm_.tm_year + 1900,
tm_.tm_mon + 1,
tm_.tm_mday,
tm_.tm_hour,
tm_.tm_min,
tm_.tm_sec);
for(size_t i=0 ; buf[i] ; ++i)
buffer += buf[i];
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const PT::Date & date)

View File

@ -156,7 +156,7 @@ return res;
const std::wstring & DbBase::AssertValueWide(PGresult * r, int row, int col)
{
const char * res = AssertValue(r, row, col);
static std::wstring temp_wide_value; // !! dac jako skladowa klasy (niestatyczna)
static std::wstring temp_wide_value; // !! IMPROVE ME add as a class field (nonstatic)
PT::UTF8ToWide(res, temp_wide_value);
@ -217,11 +217,6 @@ unsigned int DbBase::AssertValueUInt(PGresult * r, int row, int col)
}
tm DbBase::AssertValueTm(PGresult * r, int row, int col)
{
return ConvertTime(AssertValue(r, row, col));
}
PT::Date DbBase::AssertValueDate(PGresult * r, int row, int col)
{
@ -338,55 +333,8 @@ return AssertValueLong(r, 0, 0);
tm DbBase::ConvertTime(const char * str)
{
tm t;
memset(&t, 0, sizeof(t));
if( !str )
return t;
size_t len = strlen(str);
if( len != 19 )
{
// the format must be like this: 2008-12-31 22:30:00
log << log1 << "DbBase: ConvertTime: unknown time format: \"" << str << "\"" << logend;
return t;
}
t.tm_year = Toi(str + 0) - 1900; /* year - 1900 */
t.tm_mon = Toi(str + 5) - 1; /* month of year (0 - 11) */
t.tm_mday = Toi(str + 8); /* day of month (1 - 31) */
t.tm_hour = Toi(str + 11); /* hours (0 - 23) */
t.tm_min = Toi(str + 14); /* minutes (0 - 59) */
t.tm_sec = Toi(str + 17); /* seconds (0 - 60) */
// t.tm_wday = 0; /* day of week (Sunday = 0) */
// t.tm_yday = 0; /* day of year (0 - 365) */
// t.tm_isdst = 0; /* is summer time in effect? */
// t.tm_zone = 0; // const_cast<char*>(""); /* abbreviation of timezone name */
return t;
}
const char * DbBase::ConvertTime(const tm & t)
{
// not thread safe
static char buffer[100];
sprintf(buffer, "%04d-%02d-%02d %02d:%02d:%02d",
t.tm_year + 1900,
t.tm_mon + 1,
t.tm_mday,
t.tm_hour,
t.tm_min,
t.tm_sec);
return buffer;
}

View File

@ -50,7 +50,6 @@ public:
static bool AssertValueBool(PGresult * r, int row, int col);
static unsigned long AssertValueULong(PGresult * r, int row, int col);
static unsigned int AssertValueUInt(PGresult * r, int row, int col);
static tm AssertValueTm(PGresult * r, int row, int col);
static PT::Date AssertValueDate(PGresult * r, int row, int col);
// non static assignments
@ -64,8 +63,6 @@ public:
int Cols(PGresult * r);
long AffectedRows(PGresult * r);
static tm ConvertTime(const char * str);
static const char * ConvertTime(const tm & t); // warning: it uses its own static buffer
void CreateIdList(const std::vector<long> & id_tab, std::wstring & list, bool add_parentheses = true);
Error DoCommand(const DbTextStream & command);

View File

@ -55,8 +55,8 @@ void DbItemColumns::SetItem(PGresult * r, long row, Item & item)
if( user_id != -1 ) item.user_id = DbBase::AssertValueLong(r, row, user_id);
if( group_id != -1 ) item.group_id = DbBase::AssertValueLong(r, row, group_id);
if( privileges != -1 ) item.privileges = DbBase::AssertValueInt(r, row, privileges);
if( date_creation != -1 ) item.date_creation = DbBase::AssertValueTm(r, row, date_creation);
if( date_modification != -1 ) item.date_modification = DbBase::AssertValueTm(r, row, date_modification);
if( date_creation != -1 ) item.date_creation = DbBase::AssertValueDate(r, row, date_creation);
if( date_modification != -1 ) item.date_modification = DbBase::AssertValueDate(r, row, date_modification);
if( type != -1 ) item.type = static_cast<Item::Type>( DbBase::AssertValueInt(r, row, type) );
if( parent_id != -1 ) item.parent_id = DbBase::AssertValueLong(r, row, parent_id);
if( content_id != -1 ) item.content_id = DbBase::AssertValueLong(r, row, content_id);

View File

@ -194,18 +194,15 @@ return *this;
}
DbTextStream & DbTextStream::operator<<(RawText<tm> t)
{
buffer += ConvertTime(t.par);
was_param = false;
return *this;
}
DbTextStream & DbTextStream::operator<<(RawText<PT::Date> date)
{
date.par.Serialize(*this);
tmp_stream.Clear();
date.par.Serialize(tmp_stream);
AssignString(tmp_stream.CStr(), buffer, false);
tmp_stream.Clear();
was_param = false;
return *this;
@ -529,18 +526,6 @@ return *this;
DbTextStream & DbTextStream::operator<<(const tm & t)
{
if( was_param )
buffer += ", ";
buffer += '\'';
buffer += ConvertTime(t);
buffer += '\'';
was_param = true;
return *this;
}
DbTextStream & DbTextStream::operator<<(const std::vector<long> & tabid)
@ -566,22 +551,6 @@ return *this;
}
const char * DbTextStream::ConvertTime(const tm & t)
{
// not thread safe
static char buffer[100];
sprintf(buffer, "%04d-%02d-%02d %02d:%02d:%02d",
t.tm_year + 1900,
t.tm_mon + 1,
t.tm_mday,
t.tm_hour,
t.tm_min,
t.tm_sec);
return buffer;
}

View File

@ -113,7 +113,6 @@ public:
DbTextStream & operator<<(RawText<unsigned long> raw);
DbTextStream & operator<<(RawText<double> raw);
DbTextStream & operator<<(RawText<void*> raw);
DbTextStream & operator<<(RawText<tm> t);
DbTextStream & operator<<(RawText<PT::Date> date);
@ -151,14 +150,11 @@ public:
DbTextStream & operator<<(unsigned long);
DbTextStream & operator<<(double);
DbTextStream & operator<<(const void *);
DbTextStream & operator<<(const tm & t);
DbTextStream & operator<<(const std::vector<long> & tabid);
DbTextStream & operator<<(const PT::Space & space);
DbTextStream & operator<<(const PT::Date & date);
static const char * ConvertTime(const tm & t);
private:
bool was_param;

View File

@ -90,13 +90,12 @@ funthread.o: ../../core/run.h ../../core/users.h ../../core/groups.h
funthread.o: ../../core/group.h ../../core/loadavg.h ../../core/image.h
funthread.o: ../../core/threadmanager.h ../../core/synchro.h tdb.h thread.h
funthread.o: ../../db/dbbase.h threadinfo.h
init.o: tdb.h thread.h ../../db/dbbase.h ../../core/error.h reply.h
init.o: ../../functions/functionbase.h ../../core/item.h
init.o: ../../../pikotools/space/space.h ../../../pikotools/date/date.h
init.o: ../../db/db.h ../../db/dbbase.h ../../db/dbconn.h
init.o: ../../db/dbtextstream.h ../../core/textstream.h ../../core/misc.h
init.o: ../../core/item.h ../../core/requesttypes.h
init.o: ../../../pikotools/space/spaceparser.h
init.o: tdb.h thread.h ../../../pikotools/date/date.h ../../db/dbbase.h
init.o: ../../core/error.h reply.h ../../functions/functionbase.h
init.o: ../../core/item.h ../../../pikotools/space/space.h ../../db/db.h
init.o: ../../db/dbbase.h ../../db/dbconn.h ../../db/dbtextstream.h
init.o: ../../core/textstream.h ../../core/misc.h ../../core/item.h
init.o: ../../core/requesttypes.h ../../../pikotools/space/spaceparser.h
init.o: ../../../pikotools/space/space.h ../../db/dbitemquery.h
init.o: ../../db/dbitemcolumns.h ../../core/user.h ../../core/group.h
init.o: ../../core/dircontainer.h ../../core/ugcontainer.h ../../core/log.h
@ -238,7 +237,8 @@ showthreads.o: ../../core/groups.h ../../core/group.h ../../core/loadavg.h
showthreads.o: ../../core/image.h ../../core/threadmanager.h
showthreads.o: ../../core/synchro.h tdb.h thread.h ../../db/dbbase.h
showthreads.o: threadinfo.h
tdb.o: tdb.h thread.h ../../db/dbbase.h ../../core/error.h ../../core/log.h
tdb.o: tdb.h thread.h ../../../pikotools/date/date.h ../../db/dbbase.h
tdb.o: ../../core/error.h ../../core/log.h
templates.o: threadinfo.h ../../core/item.h ../../../pikotools/space/space.h
templates.o: ../../../pikotools/date/date.h ../../core/system.h
templates.o: ../../core/job.h ../../core/basethread.h ../../core/synchro.h

View File

@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* Copyright (c) 2010-2012, Tomasz Sowa
* All rights reserved.
*
*/
@ -50,7 +50,7 @@ void TDb::SetThread(PGresult * r, int col, Thread & thread)
thread.replies = AssertValueLong(r, col, creplies);
thread.closed = AssertValueBool(r, col, cclosed);
thread.last_item_id = AssertValueLong(r, col, clast_item);
thread.last_item_date_modification = AssertValueTm(r, col, cdate_modification);
thread.last_item_date_modification = AssertValueDate(r, col, cdate_modification);
thread.last_item_user_id = AssertValueLong(r, col, cuser_id);
AssertValueWide(r, col, cguest, thread.last_item_guest_name);
}

View File

@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2009-2010, Tomasz Sowa
* Copyright (c) 2009-2012, Tomasz Sowa
* All rights reserved.
*
*/
@ -12,14 +12,13 @@
#include <string>
#include <string.h>
#include "date/date.h"
namespace Thread
{
class Thread
{
public:
@ -30,7 +29,7 @@ public:
// the last file in a thread
long last_item_id;
tm last_item_date_modification;
PT::Date last_item_date_modification;
long last_item_user_id;
std::wstring last_item_guest_name;
@ -43,7 +42,7 @@ public:
replies = 0;
last_item_id = -1;
last_item_user_id = -1;
memset(&last_item_date_modification, 0, sizeof(tm));
last_item_date_modification.Clear();
last_item_guest_name.clear();
}

View File

@ -12,9 +12,6 @@
/*
without escaping
*/
@ -401,15 +398,6 @@ return *this;
HtmlTextStream & HtmlTextStream::operator<<(const tm & t)
{
buffer += DateToStr(t); // from core/misc
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(const PT::Space & space)
{
tmp_stream.Clear();

View File

@ -143,7 +143,6 @@ public:
HtmlTextStream & operator<<(unsigned long);
HtmlTextStream & operator<<(double);
HtmlTextStream & operator<<(const void *);
HtmlTextStream & operator<<(const tm & t);
HtmlTextStream & operator<<(const PT::Space & space);
HtmlTextStream & operator<<(const PT::Date & Date);