From 5ad48470b660a01437ec6c90d8a971823fbae7d3 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Wed, 25 Jul 2012 10:27:20 +0000 Subject: [PATCH] added: to Space: std::wstring & FindAdd(const WTextStream & name); std::wstring & Add(const wchar_t * name, const WTextStream & value); std::wstring & Add(const std::wstring & name, const WTextStream & value); std::wstring & Add(const WTextStream & name, const WTextStream & value); git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@430 e52654a7-88a9-db11-a3e9-0013d4bc506e --- space/Makefile.dep | 12 +++++--- space/space.cpp | 57 ++++++++++++++++++++++++++++++++++++++ space/space.h | 10 +++++-- space/spacetojson.h | 6 ++-- textstream/textstream.h | 4 +-- textstream/types.h | 61 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 138 insertions(+), 12 deletions(-) create mode 100644 textstream/types.h diff --git a/space/Makefile.dep b/space/Makefile.dep index ad73066..1992b2b 100755 --- a/space/Makefile.dep +++ b/space/Makefile.dep @@ -1,6 +1,10 @@ # DO NOT DELETE -jsontospaceparser.o: jsontospaceparser.h space.h ../utf8/utf8.h -space.o: space.h ../utf8/utf8.h -spaceparser.o: spaceparser.h space.h ../utf8/utf8.h -spacetojson.o: spacetojson.h space.h +jsontospaceparser.o: jsontospaceparser.h space.h ../textstream/types.h +jsontospaceparser.o: ../utf8/utf8.h +space.o: space.h ../textstream/types.h ../utf8/utf8.h +space.o: ../textstream/textstream.h ../space/space.h ../date/date.h +space.o: ../convert/convert.h ../convert/inttostr.h ../membuffer/membuffer.h +space.o: ../textstream/types.h +spaceparser.o: spaceparser.h space.h ../textstream/types.h ../utf8/utf8.h +spacetojson.o: spacetojson.h space.h ../textstream/types.h diff --git a/space/space.cpp b/space/space.cpp index bbe9033..a617ee7 100755 --- a/space/space.cpp +++ b/space/space.cpp @@ -39,6 +39,7 @@ #include #include "space.h" #include "utf8/utf8.h" +#include "textstream/textstream.h" @@ -396,6 +397,22 @@ return *value; } +std::wstring & Space::FindAdd(const WTextStream & name) +{ + name.to_string(tmp_name); + std::wstring * value = GetValue(tmp_name); + + if( !value ) + { + value = &table_single[tmp_name]; + table.erase(tmp_name); + } + +return *value; +} + + + std::wstring & Space::Add(const wchar_t * name, bool value) { if( value ) @@ -503,6 +520,46 @@ 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; + +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; + +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; + +return val; +} + + + + void Space::Remove(const wchar_t * name) { diff --git a/space/space.h b/space/space.h index c4f8ade..d495440 100755 --- a/space/space.h +++ b/space/space.h @@ -41,6 +41,8 @@ #include #include #include +#include "textstream/types.h" + namespace PT @@ -215,6 +217,7 @@ public: std::wstring & FindAdd(const wchar_t * name); std::wstring & FindAdd(const std::wstring & name); + std::wstring & FindAdd(const WTextStream & name); std::wstring & Add(const wchar_t * name, bool value); std::wstring & Add(const std::wstring & name, bool value); @@ -228,6 +231,10 @@ public: std::wstring & Add(const wchar_t * name, const std::wstring & value); std::wstring & Add(const std::wstring & name, const std::wstring & value); + std::wstring & Add(const wchar_t * name, const WTextStream & value); + std::wstring & Add(const std::wstring & name, const WTextStream & value); + std::wstring & Add(const WTextStream & name, const WTextStream & value); + void Remove(const wchar_t * name); void Remove(const std::wstring & name); @@ -343,8 +350,6 @@ private: - - template void Space::PrintLevel(Stream & out, bool use_indents, int level) { @@ -498,6 +503,7 @@ void Space::Serialize(Stream & out, bool use_indents, bool use_comments, int lev } + } // namespace diff --git a/space/spacetojson.h b/space/spacetojson.h index 7cf4f28..0bb1551 100644 --- a/space/spacetojson.h +++ b/space/spacetojson.h @@ -197,8 +197,7 @@ bool is_special; PrintToken(out, i2->first); out << L": "; - if( i2->second.size() != 1 ) - out << '['; + out << '['; for(v = 0 ; v < i2->second.size() ; ++v) { @@ -211,8 +210,7 @@ bool is_special; out << L",\n"; } - if( i2->second.size() != 1 ) - out << ']'; + out << ']'; if( index + 1 < space.table.size() ) out << ','; diff --git a/textstream/textstream.h b/textstream/textstream.h index 3f93a5e..13c48e7 100644 --- a/textstream/textstream.h +++ b/textstream/textstream.h @@ -43,6 +43,8 @@ #include "date/date.h" #include "convert/convert.h" #include "membuffer/membuffer.h" +#include "types.h" + // for sprintf #include @@ -120,8 +122,6 @@ public: }; -typedef TextStreamBase TextStream; -typedef TextStreamBase WTextStream; diff --git a/textstream/types.h b/textstream/types.h new file mode 100644 index 0000000..d2fe229 --- /dev/null +++ b/textstream/types.h @@ -0,0 +1,61 @@ +/* + * This file is a part of PikoTools + * and is distributed under the (new) BSD licence. + * Author: Tomasz Sowa + */ + +/* + * Copyright (c) 2012, 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: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name Tomasz Sowa nor the names of contributors to this + * project may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * 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 OWNER 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_picotools_space_types +#define headerfile_picotools_space_types + + + +namespace PT +{ + + +template +class TextStreamBase; + + +typedef TextStreamBase TextStream; +typedef TextStreamBase WTextStream; + + + + +} // namespace + + +#endif +