reSIProcate/stack  9694
IntegerCategory.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/IntegerCategory.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 // Integer:
00017 //====================
00018 IntegerCategory::IntegerCategory()
00019    : ParserCategory(), 
00020      mValue(0), 
00021      mComment() 
00022 {}
00023 
00024 IntegerCategory::IntegerCategory(const HeaderFieldValue& hfv, 
00025                                  Headers::Type type,
00026                                  PoolBase* pool)
00027    : ParserCategory(hfv, type, pool), 
00028      mValue(0), 
00029      mComment() 
00030 {}
00031 
00032 IntegerCategory::IntegerCategory(const IntegerCategory& rhs,
00033                                  PoolBase* pool)
00034    : ParserCategory(rhs, pool),
00035      mValue(rhs.mValue),
00036      mComment(rhs.mComment)
00037 {}
00038 
00039 IntegerCategory&
00040 IntegerCategory::operator=(const IntegerCategory& 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* IntegerCategory::clone() const
00052 {
00053    return new IntegerCategory(*this);
00054 }
00055 
00056 ParserCategory* IntegerCategory::clone(void* location) const
00057 {
00058    return new (location) IntegerCategory(*this);
00059 }
00060 
00061 ParserCategory* 
00062 IntegerCategory::clone(PoolBase* pool) const
00063 {
00064    return new (pool) IntegerCategory(*this, pool);
00065 }
00066 
00067 int IntegerCategory::value() const 
00068 {
00069    checkParsed(); 
00070    return mValue;
00071 }
00072 
00073 const Data& 
00074 IntegerCategory::comment() const 
00075 {
00076    checkParsed(); 
00077    return mComment;
00078 }
00079 
00080 int& IntegerCategory::value()
00081 {
00082    checkParsed(); 
00083    return mValue;
00084 }
00085 
00086 Data& 
00087 IntegerCategory::comment()
00088 {
00089    checkParsed(); 
00090    return mComment;
00091 }
00092 
00093 
00094 void
00095 IntegerCategory::parse(ParseBuffer& pb)
00096 {
00097    const char* start = pb.skipWhitespace();
00098    mValue = pb.integer();
00099    pb.skipToChar('(');
00100    if (!pb.eof())
00101    {
00102       start = pb.skipChar();
00103       pb.skipToEndQuote(')');
00104       pb.data(mComment, start);
00105       pb.skipChar();
00106    }
00107    else
00108    {
00109       pb.reset(start);
00110       start = pb.skipNonWhitespace();
00111    }
00112    
00113    parseParameters(pb);
00114 }
00115 
00116 EncodeStream& 
00117 IntegerCategory::encodeParsed(EncodeStream& str) const
00118 {
00119   str << mValue;
00120 
00121   if (!mComment.empty())
00122   {
00123      str << "(" << mComment << ")";
00124   }
00125   
00126   encodeParameters(str);
00127   return str;
00128 }
00129 
00130 
00131 /* ====================================================================
00132  * The Vovida Software License, Version 1.0 
00133  * 
00134  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00135  * 
00136  * Redistribution and use in source and binary forms, with or without
00137  * modification, are permitted provided that the following conditions
00138  * are met:
00139  * 
00140  * 1. Redistributions of source code must retain the above copyright
00141  *    notice, this list of conditions and the following disclaimer.
00142  * 
00143  * 2. Redistributions in binary form must reproduce the above copyright
00144  *    notice, this list of conditions and the following disclaimer in
00145  *    the documentation and/or other materials provided with the
00146  *    distribution.
00147  * 
00148  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00149  *    and "Vovida Open Communication Application Library (VOCAL)" must
00150  *    not be used to endorse or promote products derived from this
00151  *    software without prior written permission. For written
00152  *    permission, please contact vocal@vovida.org.
00153  *
00154  * 4. Products derived from this software may not be called "VOCAL", nor
00155  *    may "VOCAL" appear in their name, without prior written
00156  *    permission of Vovida Networks, Inc.
00157  * 
00158  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00159  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00160  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00161  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00162  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00163  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00164  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00165  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00166  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00167  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00168  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00169  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00170  * DAMAGE.
00171  * 
00172  * ====================================================================
00173  * 
00174  * This software consists of voluntary contributions made by Vovida
00175  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00176  * Inc.  For more information on Vovida Networks, Inc., please see
00177  * <http://www.vovida.org/>.
00178  *
00179  */