reSIProcate/rutil  9694
ConfigParse.hxx
Go to the documentation of this file.
00001 #if !defined(ConfigParse_hxx)
00002 #define ConfigParse_hxx
00003 
00004 #include <vector>
00005 #include "rutil/BaseException.hxx"
00006 #include "rutil/HashMap.hxx"
00007 #include "rutil/Data.hxx"
00008 
00009 namespace resip
00010 {
00011 
00012 class ConfigParse
00013 {
00014 public:
00015    class Exception : public BaseException
00016    {
00017       public:
00018          Exception(const Data& msg,
00019                    const Data& file,
00020                    const int line)
00021             : BaseException(msg, file, line) {}            
00022       protected:
00023          virtual const char* name() const { return "ConfigParse::Exception"; }
00024    };
00025 
00026    ConfigParse();
00027    ConfigParse(int argc, char** argv, const resip::Data& defaultConfigFilename);
00028    virtual ~ConfigParse();
00029 
00030    virtual void printHelpText(int argc, char **argv) = 0;
00031 
00032    void parseCommandLine(int argc, char** argv);
00033    void parseConfigFile(const resip::Data& filename);
00034 
00035    bool getConfigValue(const resip::Data& name, resip::Data &value);
00036    resip::Data getConfigData(const resip::Data& name, const resip::Data& defaultValue, bool useDefaultIfEmpty=false);
00037 
00038    bool getConfigValue(const resip::Data& name, bool &value);
00039    bool getConfigBool(const resip::Data& name, bool defaultValue);
00040    
00041    bool getConfigValue(const resip::Data& name, unsigned long &value);
00042    unsigned long getConfigUnsignedLong(const resip::Data& name, unsigned long defaultValue);
00043 
00044    bool getConfigValue(const resip::Data& name, int &value);
00045    int getConfigInt(const resip::Data& name, int defaultValue);
00046 
00047    bool getConfigValue(const resip::Data& name, unsigned short &value);
00048    unsigned short getConfigUnsignedShort(const resip::Data& name, int defaultValue);
00049 
00050    bool getConfigValue(const resip::Data& name, std::vector<resip::Data> &value);
00051    
00052 protected:
00053    void insertConfigValue(const resip::Data& name, const resip::Data& value);
00054 
00055    typedef HashMultiMap<resip::Data, resip::Data> ConfigValuesMap;
00056    ConfigValuesMap mConfigValues;
00057 
00058    // Config filename from command line
00059    resip::Data mCmdLineConfigFilename;
00060 
00061 private:
00062    friend EncodeStream& operator<<(EncodeStream& strm, const ConfigParse& config);
00063 };
00064 
00065 EncodeStream& operator<<(EncodeStream& strm, const ConfigParse& config);
00066  
00067 }
00068 
00069 #endif
00070 
00071 /* ====================================================================
00072  * The Vovida Software License, Version 1.0 
00073  * 
00074  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00075  * 
00076  * Redistribution and use in source and binary forms, with or without
00077  * modification, are permitted provided that the following conditions
00078  * are met:
00079  * 
00080  * 1. Redistributions of source code must retain the above copyright
00081  *    notice, this list of conditions and the following disclaimer.
00082  * 
00083  * 2. Redistributions in binary form must reproduce the above copyright
00084  *    notice, this list of conditions and the following disclaimer in
00085  *    the documentation and/or other materials provided with the
00086  *    distribution.
00087  * 
00088  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00089  *    and "Vovida Open Communication Application Library (VOCAL)" must
00090  *    not be used to endorse or promote products derived from this
00091  *    software without prior written permission. For written
00092  *    permission, please contact vocal@vovida.org.
00093  *
00094  * 4. Products derived from this software may not be called "VOCAL", nor
00095  *    may "VOCAL" appear in their name, without prior written
00096  *    permission of Vovida Networks, Inc.
00097  * 
00098  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00099  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00100  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00101  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00102  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00103  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00104  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00105  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00106  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00107  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00108  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00109  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00110  * DAMAGE.
00111  * 
00112  * ====================================================================
00113  * 
00114  * This software consists of voluntary contributions made by Vovida
00115  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00116  * Inc.  For more information on Vovida Networks, Inc., please see
00117  * <http://www.vovida.org/>.
00118  *
00119  */