reSIProcate/stack  9694
UInt32Category.cxx
Go to the documentation of this file.
00001 #if defined(HAVE_CONFIG_H)
00002 #include "config.h"
00003 #endif
00004 
00005 #include "resip/stack/UInt32Category.hxx"
00006 #include "rutil/Logger.hxx"
00007 #include "rutil/ParseBuffer.hxx"
00008 //#include "rutil/WinLeakCheck.hxx"  // not compatible with placement new used below
00009 
00010 using namespace resip;
00011 using namespace std;
00012 
00013 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
00014 
00015 //====================
00016 // UInt32:
00017 //====================
00018 UInt32Category::UInt32Category()
00019    : ParserCategory(), 
00020      mValue(0), 
00021      mComment() 
00022 {}
00023 
00024 UInt32Category::UInt32Category(const HeaderFieldValue& hfv, 
00025                                  Headers::Type type,
00026                                  PoolBase* pool)
00027    : ParserCategory(hfv, type, pool), 
00028      mValue(0), 
00029      mComment() 
00030 {}
00031 
00032 UInt32Category::UInt32Category(const UInt32Category& rhs,
00033                                  PoolBase* pool)
00034    : ParserCategory(rhs, pool),
00035      mValue(rhs.mValue),
00036      mComment(rhs.mComment)
00037 {}
00038 
00039 UInt32Category&
00040 UInt32Category::operator=(const UInt32Category& rhs)
00041 {
00042    if (this != &rhs)
00043    {
00044       ParserCategory::operator=(rhs);
00045       mValue = rhs.mValue;
00046       mComment = rhs.mComment;
00047    }
00048    return *this;
00049 }
00050 
00051 ParserCategory* UInt32Category::clone() const
00052 {
00053    return new UInt32Category(*this);
00054 }
00055 
00056 ParserCategory* UInt32Category::clone(void* location) const
00057 {
00058    return new (location) UInt32Category(*this);
00059 }
00060 
00061 ParserCategory* 
00062 UInt32Category::clone(PoolBase* pool) const
00063 {
00064    return new (pool) UInt32Category(*this, pool);
00065 }
00066 
00067 const UInt32& 
00068 UInt32Category::value() const
00069 {
00070    checkParsed(); 
00071    return mValue;
00072 }
00073 
00074 const Data& 
00075 UInt32Category::comment() const
00076 {
00077    checkParsed(); 
00078    return mComment;
00079 }
00080 
00081 UInt32& 
00082 UInt32Category::value()
00083 {
00084    checkParsed(); 
00085    return mValue;
00086 }
00087 
00088 Data& 
00089 UInt32Category::comment()
00090 {
00091    checkParsed(); 
00092    return mComment;
00093 }
00094 
00095 void
00096 UInt32Category::parse(ParseBuffer& pb)
00097 {
00098    const char* start = pb.skipWhitespace();
00099    mValue = pb.uInt32();
00100    pb.skipToChar('(');
00101    if (!pb.eof())
00102    {
00103       start = pb.skipChar();
00104       pb.skipToEndQuote(')');
00105       pb.data(mComment, start);
00106       pb.skipChar();
00107    }
00108    else
00109    {
00110       pb.reset(start);
00111       start = pb.skipNonWhitespace();
00112    }
00113    
00114    parseParameters(pb);
00115 }
00116 
00117 EncodeStream& 
00118 UInt32Category::encodeParsed(EncodeStream& str) const
00119 {
00120   str << mValue;
00121 
00122   if (!mComment.empty())
00123   {
00124      str << "(" << mComment << ")";
00125   }
00126   
00127   encodeParameters(str);
00128   return str;
00129 }
00130 
00131 ParameterTypes::Factory UInt32Category::ParameterFactories[ParameterTypes::MAX_PARAMETER]={0};
00132 
00133 Parameter* 
00134 UInt32Category::createParam(ParameterTypes::Type type, ParseBuffer& pb, const std::bitset<256>& terminators, PoolBase* pool)
00135 {
00136    if(type > ParameterTypes::UNKNOWN && type < ParameterTypes::MAX_PARAMETER && ParameterFactories[type])
00137    {
00138       return ParameterFactories[type](type, pb, terminators, pool);
00139    }
00140    return 0;
00141 }
00142 
00143 bool 
00144 UInt32Category::exists(const Param<UInt32Category>& paramType) const
00145 {
00146     checkParsed();
00147     bool ret = getParameterByEnum(paramType.getTypeNum()) != NULL;
00148     return ret;
00149 }
00150 
00151 void 
00152 UInt32Category::remove(const Param<UInt32Category>& paramType)
00153 {
00154     checkParsed();
00155     removeParameterByEnum(paramType.getTypeNum());
00156 }
00157 
00158 #define defineParam(_enum, _name, _type, _RFC_ref_ignored)                                                      \
00159 _enum##_Param::DType&                                                                                           \
00160 UInt32Category::param(const _enum##_Param& paramType)                                                           \
00161 {                                                                                                               \
00162    checkParsed();                                                                                               \
00163    _enum##_Param::Type* p =                                                                                     \
00164       static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum()));                            \
00165    if (!p)                                                                                                      \
00166    {                                                                                                            \
00167       p = new _enum##_Param::Type(paramType.getTypeNum());                                                      \
00168       mParameters.push_back(p);                                                                                 \
00169    }                                                                                                            \
00170    return p->value();                                                                                           \
00171 }                                                                                                               \
00172                                                                                                                 \
00173 const _enum##_Param::DType&                                                                                     \
00174 UInt32Category::param(const _enum##_Param& paramType) const                                                     \
00175 {                                                                                                               \
00176    checkParsed();                                                                                               \
00177    _enum##_Param::Type* p =                                                                                     \
00178       static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum()));                            \
00179    if (!p)                                                                                                      \
00180    {                                                                                                            \
00181       InfoLog(<< "Missing parameter " _name " " << ParameterTypes::ParameterNames[paramType.getTypeNum()]);     \
00182       DebugLog(<< *this);                                                                                       \
00183       throw Exception("Missing parameter " _name, __FILE__, __LINE__);                                          \
00184    }                                                                                                            \
00185    return p->value();                                                                                           \
00186 }
00187 
00188 defineParam(duration, "duration", UInt32Parameter, "RFC 3261");
00189 
00190 #undef defineParam
00191 
00192 /* ====================================================================
00193  * The Vovida Software License, Version 1.0 
00194  * 
00195  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00196  * 
00197  * Redistribution and use in source and binary forms, with or without
00198  * modification, are permitted provided that the following conditions
00199  * are met:
00200  * 
00201  * 1. Redistributions of source code must retain the above copyright
00202  *    notice, this list of conditions and the following disclaimer.
00203  * 
00204  * 2. Redistributions in binary form must reproduce the above copyright
00205  *    notice, this list of conditions and the following disclaimer in
00206  *    the documentation and/or other materials provided with the
00207  *    distribution.
00208  * 
00209  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00210  *    and "Vovida Open Communication Application Library (VOCAL)" must
00211  *    not be used to endorse or promote products derived from this
00212  *    software without prior written permission. For written
00213  *    permission, please contact vocal@vovida.org.
00214  *
00215  * 4. Products derived from this software may not be called "VOCAL", nor
00216  *    may "VOCAL" appear in their name, without prior written
00217  *    permission of Vovida Networks, Inc.
00218  * 
00219  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00220  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00221  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00222  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00223  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00224  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00225  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00226  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00227  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00228  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00229  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00230  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00231  * DAMAGE.
00232  * 
00233  * ====================================================================
00234  * 
00235  * This software consists of voluntary contributions made by Vovida
00236  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00237  * Inc.  For more information on Vovida Networks, Inc., please see
00238  * <http://www.vovida.org/>.
00239  *
00240  */