diff --git a/src/Makefile.dep b/src/Makefile.dep index 53fbb00..a3e1eb4 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep @@ -10,28 +10,31 @@ ./convert/double.o: convert/inttostr.h utf8/utf8.h textstream/stream.h ./convert/double.o: utf8/utf8_templates.h utf8/utf8_private.h date/date.h ./convert/double.o: membuffer/membuffer.h textstream/types.h +./convert/double.o: textstream/stream_private.h ./convert/baseparser.o: ./convert/baseparser.h textstream/textstream.h ./convert/baseparser.o: textstream/stream.h space/space.h textstream/types.h ./convert/baseparser.o: convert/inttostr.h utf8/utf8.h textstream/stream.h ./convert/baseparser.o: utf8/utf8_templates.h utf8/utf8_private.h date/date.h ./convert/baseparser.o: membuffer/membuffer.h textstream/types.h +./convert/baseparser.o: textstream/stream_private.h ./date/date.o: ./date/date.h convert/inttostr.h ./log/filelog.o: ./log/filelog.h textstream/textstream.h textstream/stream.h ./log/filelog.o: space/space.h textstream/types.h convert/inttostr.h ./log/filelog.o: utf8/utf8.h textstream/stream.h utf8/utf8_templates.h ./log/filelog.o: utf8/utf8_private.h date/date.h membuffer/membuffer.h -./log/filelog.o: textstream/types.h +./log/filelog.o: textstream/types.h textstream/stream_private.h ./log/log.o: ./log/log.h textstream/textstream.h textstream/stream.h ./log/log.o: space/space.h textstream/types.h convert/inttostr.h utf8/utf8.h ./log/log.o: textstream/stream.h utf8/utf8_templates.h utf8/utf8_private.h ./log/log.o: date/date.h membuffer/membuffer.h textstream/types.h -./log/log.o: ./log/filelog.h +./log/log.o: textstream/stream_private.h ./log/filelog.h ./space/space.o: ./space/space.h textstream/types.h convert/inttostr.h ./space/space.o: utf8/utf8.h textstream/stream.h utf8/utf8_templates.h ./space/space.o: utf8/utf8_private.h convert/convert.h ./convert/inttostr.h ./space/space.o: convert/patternreplacer.h textstream/textstream.h ./space/space.o: textstream/stream.h space/space.h date/date.h -./space/space.o: membuffer/membuffer.h textstream/types.h convert/strtoint.h +./space/space.o: membuffer/membuffer.h textstream/types.h +./space/space.o: textstream/stream_private.h convert/strtoint.h ./space/space.o: ./convert/text.h ./convert/misc.h ./convert/double.h ./space/spaceparser.o: ./space/spaceparser.h ./space/space.h ./space/spaceparser.o: textstream/types.h convert/inttostr.h utf8/utf8.h @@ -39,8 +42,18 @@ ./space/spaceparser.o: utf8/utf8_private.h convert/baseparser.h ./space/spaceparser.o: textstream/textstream.h textstream/stream.h ./space/spaceparser.o: space/space.h date/date.h membuffer/membuffer.h -./space/spaceparser.o: textstream/types.h convert/strtoint.h ./convert/text.h -./space/spaceparser.o: ./convert/misc.h +./space/spaceparser.o: textstream/types.h textstream/stream_private.h +./space/spaceparser.o: convert/strtoint.h ./convert/text.h ./convert/misc.h +./space/keyvalueparser.o: ./space/keyvalueparser.h ./space/space.h +./space/keyvalueparser.o: textstream/types.h convert/inttostr.h utf8/utf8.h +./space/keyvalueparser.o: textstream/stream.h utf8/utf8_templates.h +./space/keyvalueparser.o: utf8/utf8_private.h convert/baseparser.h +./space/keyvalueparser.o: textstream/textstream.h textstream/stream.h +./space/keyvalueparser.o: space/space.h date/date.h membuffer/membuffer.h +./space/keyvalueparser.o: textstream/types.h textstream/stream_private.h +./space/keyvalueparser.o: convert/strtoint.h ./convert/text.h +./space/keyvalueparser.o: ./convert/misc.h +./textstream/stream_private.o: textstream/stream_private.h ./utf8/utf8.o: ./utf8/utf8.h textstream/stream.h utf8/utf8_templates.h ./utf8/utf8.o: utf8/utf8_private.h ./utf8/utf8_private.o: utf8/utf8_private.h @@ -49,7 +62,7 @@ ./csv/csvparser.o: utf8/utf8_templates.h utf8/utf8_private.h ./csv/csvparser.o: convert/baseparser.h textstream/textstream.h ./csv/csvparser.o: textstream/stream.h date/date.h membuffer/membuffer.h -./csv/csvparser.o: textstream/types.h +./csv/csvparser.o: textstream/types.h textstream/stream_private.h ./mainoptions/mainoptionsparser.o: ./mainoptions/mainoptionsparser.h ./mainoptions/mainoptionsparser.o: space/space.h textstream/types.h ./mainoptions/mainoptionsparser.o: convert/inttostr.h utf8/utf8.h @@ -61,9 +74,11 @@ ./html/bbcodeparser.o: convert/inttostr.h utf8/utf8.h textstream/stream.h ./html/bbcodeparser.o: utf8/utf8_templates.h utf8/utf8_private.h date/date.h ./html/bbcodeparser.o: membuffer/membuffer.h textstream/types.h +./html/bbcodeparser.o: textstream/stream_private.h ./html/htmlparser.o: ./html/htmlparser.h convert/baseparser.h ./html/htmlparser.o: textstream/textstream.h textstream/stream.h ./html/htmlparser.o: space/space.h textstream/types.h convert/inttostr.h ./html/htmlparser.o: utf8/utf8.h textstream/stream.h utf8/utf8_templates.h ./html/htmlparser.o: utf8/utf8_private.h date/date.h membuffer/membuffer.h -./html/htmlparser.o: textstream/types.h convert/text.h +./html/htmlparser.o: textstream/types.h textstream/stream_private.h +./html/htmlparser.o: convert/text.h diff --git a/src/textstream/stream_private.cpp b/src/textstream/stream_private.cpp new file mode 100644 index 0000000..1e2ad77 --- /dev/null +++ b/src/textstream/stream_private.cpp @@ -0,0 +1,55 @@ +/* + * This file is a part of PikoTools + * and is distributed under the 2-Clause BSD licence. + * Author: Tomasz Sowa + */ + +/* + * Copyright (c) 2024, 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 "stream_private.h" + +#ifdef PT_HAS_MORM_LIBRARY +#include "morm.h" +#endif + +namespace pt::private_namespace +{ + +#ifdef PT_HAS_MORM_LIBRARY +void serialize_to_stream(morm::Model & model, pt::Stream & str) +{ + str << model.to_string(); +} +#endif + + +} + + + diff --git a/src/textstream/stream_private.h b/src/textstream/stream_private.h new file mode 100644 index 0000000..c56ed5a --- /dev/null +++ b/src/textstream/stream_private.h @@ -0,0 +1,62 @@ +/* + * This file is a part of PikoTools + * and is distributed under the 2-Clause BSD licence. + * Author: Tomasz Sowa + */ + +/* + * Copyright (c) 2024, 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_pikotools_src_textstream_stream_private +#define headerfile_pikotools_src_textstream_stream_private + + +#ifdef PT_HAS_MORM_LIBRARY +namespace morm +{ + class Model; +} +#endif + + +namespace pt +{ +class Stream; + + +namespace private_namespace +{ + +#ifdef PT_HAS_MORM_LIBRARY + void serialize_to_stream(morm::Model & model, pt::Stream & str); +#endif + +} +} + +#endif diff --git a/src/textstream/textstream.h b/src/textstream/textstream.h index 7b48818..f703e4a 100644 --- a/src/textstream/textstream.h +++ b/src/textstream/textstream.h @@ -43,11 +43,13 @@ #include "membuffer/membuffer.h" #include "types.h" #include "utf8/utf8.h" +#include "stream_private.h" // for snprintf #include + namespace pt { @@ -194,6 +196,10 @@ public: TextStreamBase & operator<<(const Space & space); TextStreamBase & operator<<(const Date & date); +#ifdef PT_HAS_MORM_LIBRARY + TextStreamBase & operator<<(morm::Model & model); +#endif + template TextStreamBase & operator<<(const TextStreamBase & arg); @@ -1200,6 +1206,23 @@ return *this; } + +#ifdef PT_HAS_MORM_LIBRARY + +template +TextStreamBase & +TextStreamBase::operator<<(morm::Model & model) +{ + private_namespace::serialize_to_stream(model, *this); + +return *this; +} + +#endif + + + + template template TextStreamBase & diff --git a/tests/Makefile.dep b/tests/Makefile.dep index 5fd8554..0356e4f 100644 --- a/tests/Makefile.dep +++ b/tests/Makefile.dep @@ -7,16 +7,17 @@ ./convert.o: ../src/utf8/utf8.h ../src/textstream/stream.h ./convert.o: ../src/utf8/utf8_templates.h ../src/utf8/utf8_private.h ./convert.o: ../src/date/date.h ../src/membuffer/membuffer.h -./convert.o: ../src/textstream/types.h ../src/convert/strtoint.h -./convert.o: ../src/convert/text.h ../src/convert/misc.h -./convert.o: ../src/convert/double.h test.h +./convert.o: ../src/textstream/types.h ../src/textstream/stream_private.h +./convert.o: ../src/convert/strtoint.h ../src/convert/text.h +./convert.o: ../src/convert/misc.h ../src/convert/double.h test.h ./csvparser.o: csvparser.h ../src/csv/csvparser.h ../src/space/space.h ./csvparser.o: ../src/textstream/types.h ../src/convert/inttostr.h ./csvparser.o: ../src/utf8/utf8.h ../src/textstream/stream.h ./csvparser.o: ../src/utf8/utf8_templates.h ../src/utf8/utf8_private.h ./csvparser.o: ../src/convert/baseparser.h ../src/textstream/textstream.h ./csvparser.o: ../src/textstream/stream.h ../src/date/date.h -./csvparser.o: ../src/membuffer/membuffer.h ../src/textstream/types.h test.h +./csvparser.o: ../src/membuffer/membuffer.h ../src/textstream/types.h +./csvparser.o: ../src/textstream/stream_private.h test.h ./main.o: convert.h ../src/convert/convert.h ../src/convert/inttostr.h ./main.o: ../src/convert/patternreplacer.h ../src/textstream/textstream.h ./main.o: ../src/textstream/stream.h ../src/space/space.h @@ -24,9 +25,10 @@ ./main.o: ../src/utf8/utf8.h ../src/textstream/stream.h ./main.o: ../src/utf8/utf8_templates.h ../src/utf8/utf8_private.h ./main.o: ../src/date/date.h ../src/membuffer/membuffer.h -./main.o: ../src/textstream/types.h ../src/convert/strtoint.h -./main.o: ../src/convert/text.h ../src/convert/misc.h ../src/convert/double.h -./main.o: test.h mainoptionsparser.h csvparser.h +./main.o: ../src/textstream/types.h ../src/textstream/stream_private.h +./main.o: ../src/convert/strtoint.h ../src/convert/text.h +./main.o: ../src/convert/misc.h ../src/convert/double.h test.h +./main.o: mainoptionsparser.h csvparser.h ./test.o: test.h ./mainoptionsparser.o: mainoptionsparser.h test.h ./mainoptionsparser.o: ../src/mainoptions/mainoptionsparser.h @@ -40,5 +42,6 @@ ./mainoptionsparser.o: ../src/textstream/textstream.h ./mainoptionsparser.o: ../src/textstream/stream.h ../src/date/date.h ./mainoptionsparser.o: ../src/membuffer/membuffer.h ../src/textstream/types.h +./mainoptionsparser.o: ../src/textstream/stream_private.h ./mainoptionsparser.o: ../src/convert/strtoint.h ../src/convert/text.h ./mainoptionsparser.o: ../src/convert/misc.h ../src/convert/double.h