src/stream/ZStrimW_ML.h

00001 /*  @(#) $Id: ZStrimW_ML.h,v 1.21 2006/04/27 03:19:32 agreen Exp $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2003 Andrew Green and Learning in Motion, Inc.
00005 http://www.zoolib.org
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020 COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023 ------------------------------------------------------------ */
00024 
00025 #ifndef __ZStrimW_ML__
00026 #define __ZStrimW_ML__ 1
00027 #include "zconfig.h"
00028 
00029 #include "ZCompat_NonCopyable.h"
00030 #include "ZDebug.h"
00031 #include "ZStrim.h"
00032 #include "ZStrimmer.h"
00033 
00034 #include <vector>
00035 
00036 class ZTuple;
00037 class ZTupleValue;
00038 
00039 // =================================================================================================
00040 #pragma mark -
00041 #pragma mark * ZStrimW_ML
00042 
00044 
00045 class ZStrimW_ML : public ZStrimW_NativeUTF8, ZooLib::NonCopyable
00046         {
00047 public:
00048         // The copy constructor is deliberately not implemented. See docs for reason.
00049         ZStrimW_ML(const ZStrimW_ML&);
00050 
00051         explicit ZStrimW_ML(const ZStrimW& iStrimSink);
00052 
00053         ZStrimW_ML(bool iIndent, const ZStrimW& iStrimSink);
00054         ZStrimW_ML(const string8& iEOL, const string8& iIndent, const ZStrimW& iStrimSink);
00055         ~ZStrimW_ML();
00056 
00057 // From ZStrimW
00058         virtual void Imp_WriteUTF8(const UTF8* iSource, size_t iCountCU, size_t* oCountCU);
00059 
00060         virtual void Imp_Flush();
00061 
00062 // Our protocol
00063 
00065         const ZStrimW& Raw() const;
00066 
00068         void WriteNBSP() const;
00069         void NBSP() const { this->WriteNBSP(); }
00070 
00072         void WriteEntity(const string8& iEntity) const;
00073         void WriteEntity(const UTF8* iEntity) const;
00074 
00076         void Begin(const string8& iTag) const;
00077 
00080         void End(const string8& iTag) const;
00081 
00084         void End() const;
00085 
00087         void Empty(const string8& iTag) const;
00088 
00090         void PI(const string8& iTag) const;
00091 
00094         void Tag(const string8& iTag) const;
00095 
00097         void Attr(const string8& iValue) const;
00098 
00100         void Attr(const string8& iName, const string8& iValue) const;
00101 
00103         void Attr(const string8& iName, const UTF8* iValue) const;
00104 
00107         void Attr(const string8& iName, int iValue) const;
00108 
00111         void Attrf(const string8& iName, const UTF8* iValue, ...) const;
00112 
00115         void Attr(const string8& iName, const ZTupleValue& iValue) const;
00116 
00121         void Attrs(const ZTuple& iTuple) const;
00122 
00124         bool Indent(bool iIndent) const;
00125 
00127         void Abandon();
00128 
00130         void EndAll();
00131 
00133         void EndAll(const string8& iTag);
00134 
00139         void WritePending();
00140 
00141 protected:
00142         enum ETagType
00143                 { eTagTypeNone, eTagTypeNormal, eTagTypeEmpty, eTagTypePI, eTagTypeNoEnd };
00144 
00145         void pBegin(const string8& iTag, ETagType iTagType);
00146         void pWritePending();
00147         void pAttr(const string8& iName, string8* iValue);
00148         void pEnd();
00149 
00150         const ZStrimW& fStrimSink;
00151         
00152         ETagType fTagType;
00153         bool fWrittenSinceLastTag;
00154         bool fLastWasEOL;
00155         bool fIndentEnabled;
00156         string8 fString_EOL;
00157         string8 fString_Indent;
00158         std::vector<string8> fTags;
00159         std::vector<string8> fAttributeNames;
00160         std::vector<string8*> fAttributeValues;
00161         };
00162 
00163 // =================================================================================================
00164 #pragma mark -
00165 #pragma mark * ZStrimmerW_ML
00166 
00168 
00169 class ZStrimmerW_ML : public ZStrimmerW
00170         {
00171 public:
00172         ZStrimmerW_ML(ZRef<ZStrimmerW> iStrimmer);
00173         ZStrimmerW_ML(bool iIndent, ZRef<ZStrimmerW> iStrimmer);
00174         ZStrimmerW_ML(const string8& iEOL, const string8& iIndent, ZRef<ZStrimmerW> iStrimmer);
00175         virtual ~ZStrimmerW_ML();
00176 
00177 // From ZStrimmerW
00178         virtual const ZStrimW& GetStrimW();
00179 
00180 protected:
00181         ZRef<ZStrimmerW> fStrimmer;
00182         ZStrimW_ML fStrim;
00183         };
00184 
00185 #endif // __ZStrimW_ML__

Generated on Thu Jul 26 11:21:55 2007 for ZooLib by  doxygen 1.4.7