reSIProcate/stack  9694
ParserContainerBase.hxx
Go to the documentation of this file.
00001 #ifndef RESIP_ParserContainerBase_hxx
00002 #define RESIP_ParserContainerBase_hxx
00003 
00004 #include "resip/stack/ParserCategory.hxx"
00005 #include <iosfwd>
00006 #include "resip/stack/HeaderTypes.hxx"
00007 #include <vector>
00008 
00009 #include "rutil/StlPoolAllocator.hxx"
00010 #include "rutil/PoolBase.hxx"
00011 
00012 namespace resip
00013 {
00014 
00015 class HeaderFieldValueList;
00016 class PoolBase;
00017 
00022 class ParserContainerBase
00023 {
00024    public:
00025       typedef size_t size_type;
00026 
00030       ParserContainerBase(Headers::Type type = Headers::UNKNOWN);
00031 
00035       ParserContainerBase(Headers::Type type,
00036                            PoolBase& pool);
00037 
00042       ParserContainerBase(const ParserContainerBase& rhs);
00043 
00044       ParserContainerBase(const ParserContainerBase& rhs,
00045                            PoolBase& pool);
00046 
00051       ParserContainerBase& operator=(const ParserContainerBase& rhs);
00052 
00056       virtual ~ParserContainerBase();
00057 
00061       inline void clear() {mParsers.clear();}
00062 
00067       virtual ParserContainerBase* clone() const = 0;
00068 
00072       inline size_t size() const {return mParsers.size();}
00073 
00078       inline bool empty() const {return mParsers.empty();}
00079 
00087       EncodeStream& encode(const Data& headerName, EncodeStream& str) const;
00088 
00093       std::ostream& encode(Headers::Type type,std::ostream& str) const;
00094 
00099       EncodeStream& encodeEmbedded(const Data& headerName, EncodeStream& str) const;
00100 
00104       void pop_front();
00105 
00109       void pop_back();
00110 
00116       void append(const ParserContainerBase& rhs);
00117 
00123       virtual void parseAll()=0;
00124    protected:
00125       const Headers::Type mType;
00126 
00130       class HeaderKit
00131       {
00132          public:
00133             static const HeaderKit Empty;
00134 
00135             HeaderKit(): pc(0){}
00136             HeaderKit(const HeaderKit& orig) 
00137             : pc(orig.pc),
00138                hfv(orig.hfv)
00139             {}
00140 
00141             HeaderKit& operator=(const HeaderKit& rhs)
00142             {
00143                if(this!=&rhs)
00144                {
00145                   pc=rhs.pc;
00146                   hfv=rhs.hfv;
00147                }
00148                return *this;
00149             }
00150             
00151             ~HeaderKit()
00152             {}
00153             
00154             EncodeStream& encode(EncodeStream& str) const
00155             {
00156                if(pc)
00157                {
00158                   pc->encode(str);
00159                }
00160                else
00161                {
00162                   hfv.encode(str);
00163                }
00164                return str;
00165             }
00166             
00167             ParserCategory* pc;
00168             HeaderFieldValue hfv;
00169       };
00170 
00171       typedef std::vector<HeaderKit, StlPoolAllocator<HeaderKit, PoolBase> > Parsers;
00175       Parsers mParsers;
00176       PoolBase* mPool;
00177       
00181       void copyParsers(const Parsers& parsers);
00182 
00186       void freeParsers();
00187       
00188       inline void freeParser(HeaderKit& kit)
00189       {
00190          if(kit.pc)
00191          {
00192             kit.pc->~ParserCategory();
00193             if(mPool)
00194             {
00195                mPool->deallocate(kit.pc);
00196             }
00197             else
00198             {
00199                ::operator delete(kit.pc);
00200             }
00201             kit.pc=0;
00202          }
00203       }
00204 
00205       inline ParserCategory* makeParser(const ParserCategory& orig)
00206       {
00207          return orig.clone(mPool);
00208       }
00209 };
00210  
00211 }
00212 
00213 #endif
00214 
00215 /* ====================================================================
00216  * The Vovida Software License, Version 1.0 
00217  * 
00218  * Copyright (c) 2000-2005
00219  * 
00220  * Redistribution and use in source and binary forms, with or without
00221  * modification, are permitted provided that the following conditions
00222  * are met:
00223  * 
00224  * 1. Redistributions of source code must retain the above copyright
00225  *    notice, this list of conditions and the following disclaimer.
00226  * 
00227  * 2. Redistributions in binary form must reproduce the above copyright
00228  *    notice, this list of conditions and the following disclaimer in
00229  *    the documentation and/or other materials provided with the
00230  *    distribution.
00231  * 
00232  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00233  *    and "Vovida Open Communication Application Library (VOCAL)" must
00234  *    not be used to endorse or promote products derived from this
00235  *    software without prior written permission. For written
00236  *    permission, please contact vocal@vovida.org.
00237  *
00238  * 4. Products derived from this software may not be called "VOCAL", nor
00239  *    may "VOCAL" appear in their name, without prior written
00240  *    permission of Vovida Networks, Inc.
00241  * 
00242  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00243  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00244  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00245  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00246  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00247  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00248  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00249  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00250  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00251  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00252  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00253  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00254  * DAMAGE.
00255  * 
00256  * ====================================================================
00257  * 
00258  * This software consists of voluntary contributions made by Vovida
00259  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00260  * Inc.  For more information on Vovida Networks, Inc., please see
00261  * <http://www.vovida.org/>.
00262  *
00263  */