TextFormat.h

Go to the documentation of this file.
00001 #ifndef TAGCOLL_TEXTFORMAT_H
00002 #define TAGCOLL_TEXTFORMAT_H
00003 
00008 /*
00009  * Copyright (C) 2003--2006  Enrico Zini <enrico@debian.org>
00010  *
00011  * This library is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU Lesser General Public
00013  * License as published by the Free Software Foundation; either
00014  * version 2.1 of the License, or (at your option) any later version.
00015  *
00016  * This library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License along with this library; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
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 //#define TRACE_PARSE
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  * Parse a tagged collection, sending the results to out.
00114  *
00115  * @param out
00116  *   An output iterator accepting a std::pair<string, string>
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 // vim:set ts=4 sw=4:
00194 #endif

Generated on Fri Feb 8 10:50:41 2008 for libtagcoll by  doxygen 1.5.4