00001 #ifndef TAGCOLL_TEXTFORMAT_H
00002 #define TAGCOLL_TEXTFORMAT_H
00003
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <wibble/mixin.h>
00027 #include <wibble/empty.h>
00028 #include <wibble/singleton.h>
00029 #include <tagcoll/input/base.h>
00030
00031 #include <stdio.h>
00032
00033
00034
00035 namespace tagcoll
00036 {
00037 template<class ITEM, class TAG>
00038 class PatchList;
00039 template<class ITEM, class TAG>
00040 class Patch;
00041
00042 namespace textformat
00043 {
00044
00058 class StdioWriter : public wibble::mixin::OutputIterator<StdioWriter>
00059 {
00060 protected:
00061 FILE* out;
00062
00063 public:
00064 StdioWriter(FILE* out) : out(out) {}
00065
00066 template<typename Items, typename Tags>
00067 StdioWriter& operator=(const std::pair<Items, Tags>& data);
00068 };
00069
00070 class OstreamWriter : public wibble::mixin::OutputIterator<OstreamWriter>
00071 {
00072 protected:
00073 std::ostream& out;
00074
00075 public:
00076 OstreamWriter(std::ostream& out) : out(out) {}
00077
00078 template<typename Items, typename Tags>
00079 OstreamWriter& operator=(const std::pair<Items, Tags>& data);
00080 };
00081
00094 int parseElement(input::Input& in, std::string& item);
00095
00096
00100 template<typename ITEM, typename TAG, typename ITEMSER, typename TAGSER>
00101 void outputPatch(
00102 ITEMSER& itemconv,
00103 TAGSER& tagconv,
00104 const PatchList<ITEM, TAG>& patch,
00105 FILE* out);
00106
00107 void outputPatch(
00108 const PatchList<std::string, std::string>& patch,
00109 FILE* out);
00110
00111
00112
00113
00114
00115
00116
00117
00118 template<typename OUT>
00119 void parse(input::Input& in, OUT out);
00120
00124 template<typename OUT>
00125 class PatchAssembler : public wibble::mixin::OutputIterator< PatchAssembler<OUT> >
00126 {
00127 OUT out;
00128 public:
00129 PatchAssembler(const OUT& out) : out(out) {}
00130
00131 template<typename ITEMS, typename TAGS>
00132 PatchAssembler& operator=(const std::pair<ITEMS, TAGS>& data);
00133 };
00134
00135 template<typename OUT>
00136 PatchAssembler<OUT> patchAssembler(const OUT& out)
00137 {
00138 return PatchAssembler<OUT>(out);
00139 }
00140
00141 template<typename OUT>
00142 void parsePatch(input::Input& in, OUT out)
00143 {
00144 parse(in, patchAssembler(out));
00145 }
00146
00150 template<typename ITEM, typename TAG, typename ITEMSER, typename TAGSER>
00151 PatchList<ITEM, TAG> parsePatch(
00152 ITEMSER& itemconv,
00153 TAGSER& tagconv,
00154 input::Input& in);
00155
00156 PatchList<std::string, std::string> parsePatch(input::Input& in);
00157
00158
00159
00160 template<typename ITEM, typename TAG, typename ITEMSER, typename TAGSER>
00161 class PatchBuilder : public wibble::mixin::OutputIterator< PatchBuilder<ITEM, TAG, ITEMSER, TAGSER> >
00162 {
00163 protected:
00164 PatchList<ITEM, TAG>& patch;
00165 const ITEMSER& itemconv;
00166 const TAGSER& tagconv;
00167
00168 public:
00169 PatchBuilder(
00170 PatchList<ITEM, TAG>& patch,
00171 const ITEMSER& itemconv,
00172 const TAGSER& tagconv)
00173 : patch(patch), itemconv(itemconv), tagconv(tagconv) {}
00174
00175 template<typename ITEMS, typename TAGS>
00176 PatchBuilder<ITEM, TAG, ITEMSER, TAGSER>& operator=(const std::pair<ITEMS, TAGS>& data);
00177
00178 const PatchList<ITEM, TAG>& getPatch() const throw () { return patch; }
00179 };
00180
00181 template<typename ITEM, typename TAG, typename ITEMSER, typename TAGSER>
00182 PatchBuilder<ITEM, TAG, ITEMSER, TAGSER> patchBuilder(
00183 PatchList<ITEM, TAG>& patch,
00184 const ITEMSER& itemconv,
00185 const TAGSER& tagconv)
00186 {
00187 return PatchBuilder<ITEM, TAG, ITEMSER, TAGSER>(patch, itemconv, tagconv);
00188 }
00189
00190 }
00191 }
00192
00193
00194 #endif