added: to membuffer:
template<typename in_item_type> void append(const in_item_type * item_array, size_t len); when adding values from item_array are casted to the type of the internal buffer changed: some minor optimizations in Space (in Add() methods with WTextStream as an argument) changed: removed following write() methods from TextStreamBase: TextStreamBase & write(const char * buf, size_t len); TextStreamBase & write(const wchar_t * buf, size_t len); and added a template instead: template<typename in_buffer_type> TextStreamBase & write(const in_buffer_type * buf, size_t len); this allows to write char* buffer to TextStreamBase<wchar_t...> (and vice versa) added: two write() methods to TextStreamBase: write(const char * format, double val); write(const wchar_t * format, double val); converting double value to the text (format is the same as in snprintf) git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@448 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
3cc5fd5e12
commit
28ea8f3c3e
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012, Tomasz Sowa
|
||||
* Copyright (c) 2012-2013, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -35,8 +35,8 @@
|
|||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef headerfile_picotools_membuffer_convert_inttostr
|
||||
#define headerfile_picotools_membuffer_convert_inttostr
|
||||
#ifndef headerfile_picotools_convert_inttostr
|
||||
#define headerfile_picotools_convert_inttostr
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012, Tomasz Sowa
|
||||
* Copyright (c) 2012-2013, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -39,6 +39,8 @@
|
|||
#define headerfile_picotools_membuffer_membuffer
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace PT
|
||||
{
|
||||
|
||||
|
@ -116,6 +118,9 @@ public:
|
|||
|
||||
void append(item_type item);
|
||||
void append(const item_type * item_array, size_t len);
|
||||
|
||||
template<typename in_item_type>
|
||||
void append(const in_item_type * item_array, size_t len);
|
||||
|
||||
template<typename arg_item_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
void append(const MemBuffer<arg_item_type, arg_stack_size, arg_heap_block_size> & arg);
|
||||
|
@ -595,6 +600,18 @@ void MemBuffer<item_type, stack_size, heap_block_size>::append(const item_type *
|
|||
|
||||
|
||||
|
||||
|
||||
template<typename item_type, size_t stack_size, size_t heap_block_size>
|
||||
template<typename in_item_type>
|
||||
void MemBuffer<item_type, stack_size, heap_block_size>::append(const in_item_type * item_array, size_t len)
|
||||
{
|
||||
for(size_t i=0 ; i<len ; ++i)
|
||||
append(static_cast<item_type>(item_array[i]));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename item_type, size_t stack_size, size_t heap_block_size>
|
||||
template<typename arg_item_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
void MemBuffer<item_type, stack_size, heap_block_size>::append(
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2012, Tomasz Sowa
|
||||
* Copyright (c) 2008-2013, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -574,10 +574,8 @@ return val;
|
|||
std::wstring & Space::Add(const wchar_t * name, const WTextStream & value)
|
||||
{
|
||||
tmp_name = name;
|
||||
value.to_string(tmp_value_text, true);
|
||||
|
||||
std::wstring & val = table_single[tmp_name];
|
||||
val = tmp_value_text;
|
||||
value.to_string(val, true);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
@ -586,11 +584,8 @@ return val;
|
|||
|
||||
std::wstring & Space::Add(const std::wstring & name, const WTextStream & value)
|
||||
{
|
||||
tmp_name = name;
|
||||
value.to_string(tmp_value_text, true);
|
||||
|
||||
std::wstring & val = table_single[tmp_name];
|
||||
val = tmp_value_text;
|
||||
std::wstring & val = table_single[name];
|
||||
value.to_string(val, true);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
@ -600,10 +595,9 @@ return val;
|
|||
std::wstring & Space::Add(const WTextStream & name, const WTextStream & value)
|
||||
{
|
||||
name.to_string(tmp_name, true);
|
||||
value.to_string(tmp_value_text, true);
|
||||
|
||||
std::wstring & val = table_single[tmp_name];
|
||||
val = tmp_value_text;
|
||||
value.to_string(val, true);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012, Tomasz Sowa
|
||||
* Copyright (c) 2012-2013, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -46,7 +46,7 @@
|
|||
#include "types.h"
|
||||
|
||||
|
||||
// for sprintf
|
||||
// for snprintf
|
||||
#include <cstdio>
|
||||
|
||||
namespace PT
|
||||
|
@ -103,16 +103,20 @@ public:
|
|||
TextStreamBase & operator<<(unsigned int);
|
||||
TextStreamBase & operator<<(unsigned long);
|
||||
TextStreamBase & operator<<(double);
|
||||
TextStreamBase & operator<<(const void *);// printing a pointer
|
||||
TextStreamBase & operator<<(const void *); // printing a pointer
|
||||
TextStreamBase & operator<<(const PT::Space & space);
|
||||
TextStreamBase & operator<<(const PT::Date & date);
|
||||
|
||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
TextStreamBase & operator<<(const TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg);
|
||||
|
||||
TextStreamBase & write(const char * buf, size_t len);
|
||||
TextStreamBase & write(const wchar_t * buf, size_t len);
|
||||
template<typename in_buffer_type>
|
||||
TextStreamBase & write(const in_buffer_type * buf, size_t len);
|
||||
|
||||
// write double value in a specified format
|
||||
// format is the same as in the snprintf function, e.g. write("%f", 10.0)
|
||||
TextStreamBase & write(const char * format, double val);
|
||||
TextStreamBase & write(const wchar_t * format, double val);
|
||||
|
||||
/*
|
||||
raw access
|
||||
|
@ -365,10 +369,9 @@ template<typename char_type, size_t stack_size, size_t heap_block_size>
|
|||
TextStreamBase<char_type, stack_size, heap_block_size> &
|
||||
TextStreamBase<char_type, stack_size, heap_block_size>::operator<<(double v)
|
||||
{
|
||||
char buf[50];
|
||||
char buf[100];
|
||||
|
||||
// !! IMPROVE ME we need our own double->string convertion
|
||||
sprintf(buf, "%f", v);
|
||||
snprintf(buf, sizeof(buf)/sizeof(char), "%f", v);
|
||||
return operator<<(buf);
|
||||
}
|
||||
|
||||
|
@ -393,32 +396,39 @@ return *this;
|
|||
|
||||
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
template<typename in_buffer_type>
|
||||
TextStreamBase<char_type, stack_size, heap_block_size> &
|
||||
TextStreamBase<char_type, stack_size, heap_block_size>::write(const char * buf, size_t len)
|
||||
TextStreamBase<char_type, stack_size, heap_block_size>::write(const in_buffer_type * buf, size_t len)
|
||||
{
|
||||
if( sizeof(char_type) == sizeof(char) )
|
||||
buffer.append(buf, len);
|
||||
else
|
||||
operator<<(buf);
|
||||
buffer.append(buf, len);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
TextStreamBase<char_type, stack_size, heap_block_size> &
|
||||
TextStreamBase<char_type, stack_size, heap_block_size>::write(const wchar_t * buf, size_t len)
|
||||
TextStreamBase<char_type, stack_size, heap_block_size>::write(const char * format, double val)
|
||||
{
|
||||
if( sizeof(char_type) == sizeof(wchar_t) )
|
||||
buffer.append(buf, len);
|
||||
else
|
||||
operator<<(buf);
|
||||
char buf[100];
|
||||
|
||||
return *this;
|
||||
snprintf(buf, sizeof(buf)/sizeof(char), format, val);
|
||||
return operator<<(buf);
|
||||
}
|
||||
|
||||
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
TextStreamBase<char_type, stack_size, heap_block_size> &
|
||||
TextStreamBase<char_type, stack_size, heap_block_size>::write(const wchar_t * format, double val)
|
||||
{
|
||||
wchar_t buf[100];
|
||||
|
||||
swprintf(buf, sizeof(buf)/sizeof(wchar_t), format, val);
|
||||
return operator<<(buf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
TextStreamBase<char_type, stack_size, heap_block_size> &
|
||||
TextStreamBase<char_type, stack_size, heap_block_size>::operator<<(const PT::Space & space)
|
||||
|
|
Loading…
Reference in New Issue