Options.h

Go to the documentation of this file.
00001 /*
00002  * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003  * downloading, copying, installing or using the software you agree to
00004  * this license. If you do not agree to this license, do not download,
00005  * install, copy or use the software.
00006  * 
00007  * Intel Open Source License 
00008  * 
00009  * Copyright (c) 2004 Intel Corporation. All rights reserved. 
00010  * 
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are
00013  * met:
00014  * 
00015  *   Redistributions of source code must retain the above copyright
00016  *   notice, this list of conditions and the following disclaimer.
00017  * 
00018  *   Redistributions in binary form must reproduce the above copyright
00019  *   notice, this list of conditions and the following disclaimer in the
00020  *   documentation and/or other materials provided with the distribution.
00021  * 
00022  *   Neither the name of the Intel Corporation nor the names of its
00023  *   contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *  
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
00030  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00031  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00032  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00033  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00034  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00035  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037  */
00038 #ifndef _OASYS_OPTIONS_H_
00039 #define _OASYS_OPTIONS_H_
00040 
00041 #include <config.h>
00042 #include <string>
00043 #include <vector>
00044 #include "../compat/inet_aton.h"
00045 
00046 namespace oasys {
00047 
00053 class Opt {
00054     friend class Getopt;
00055     friend class OptParser;
00056 
00057 public:
00058     virtual ~Opt();
00059     
00060 protected:
00064     Opt(char shortopt, const char* longopt,
00065         void* valp, bool* setp, bool needval,
00066         const char* valdesc, const char* desc);
00067 
00071     virtual int set(const char* val, size_t len) = 0;
00072     
00073     char shortopt_;
00074     const char* longopt_;
00075     void* valp_;
00076     bool* setp_;
00077     bool needval_;
00078     const char* valdesc_;
00079     const char* desc_;
00080     Opt*  next_;
00081 };
00082 
00086 class BoolOpt : public Opt {
00087 public:
00097     BoolOpt(const char* opt, bool* valp,
00098             const char* desc = "", bool* setp = NULL);
00099 
00111     BoolOpt(char shortopt, const char* longopt, bool* valp,
00112             const char* desc = "", bool* setp = NULL);
00113 
00114 protected:
00115     int set(const char* val, size_t len);
00116 };
00117 
00121 class IntOpt : public Opt {
00122 public:
00133     IntOpt(const char* opt, int* valp,
00134            const char* valdesc = "", const char* desc = "",
00135            bool* setp = NULL);
00136     
00149     IntOpt(char shortopt, const char* longopt, int* valp,
00150            const char* valdesc = "", const char* desc = "",
00151            bool* setp = NULL);
00152     
00153 protected:
00154     int set(const char* val, size_t len);
00155 };
00156 
00160 class UIntOpt : public Opt {
00161 public:
00172     UIntOpt(const char* opt, u_int* valp,
00173             const char* valdesc = "", const char* desc = "",
00174             bool* setp = NULL);
00175     
00188     UIntOpt(char shortopt, const char* longopt, u_int* valp,
00189             const char* valdesc = "", const char* desc = "",
00190             bool* setp = NULL);
00191     
00192 protected:
00193     int set(const char* val, size_t len);
00194 };
00195 
00199 class UInt16Opt : public Opt {
00200 public:
00211     UInt16Opt(const char* opt, u_int16_t* valp,
00212               const char* valdesc = "", const char* desc = "",
00213               bool* setp = NULL);
00214     
00227     UInt16Opt(char shortopt, const char* longopt, u_int16_t* valp,
00228               const char* valdesc = "", const char* desc = "",
00229               bool* setp = NULL);
00230     
00231 protected:
00232     int set(const char* val, size_t len);
00233 };
00234 
00238 class UInt8Opt : public Opt {
00239 public:
00250     UInt8Opt(const char* opt, u_int8_t* valp,
00251              const char* valdesc = "", const char* desc = "",
00252              bool* setp = NULL);
00253 
00266     UInt8Opt(char shortopt, const char* longopt, u_int8_t* valp,
00267              const char* valdesc = "", const char* desc = "",
00268              bool* setp = NULL);
00269 
00270     protected:
00271         int set(const char* val, size_t len);
00272 };
00273 
00277 class DoubleOpt : public Opt {
00278 public:
00289     DoubleOpt(const char* opt, double* valp,
00290               const char* valdesc = "", const char* desc = "",
00291               bool* setp = NULL);
00292     
00305     DoubleOpt(char shortopt, const char* longopt, double* valp,
00306               const char* valdesc = "", const char* desc = "",
00307               bool* setp = NULL);
00308     
00309 protected:
00310     int set(const char* val, size_t len);
00311 };
00312 
00316 class StringOpt : public Opt {
00317 public:
00328     StringOpt(const char* opt, std::string* valp,
00329               const char* valdesc = "", const char* desc = "",
00330               bool* setp = NULL);
00331     
00344     StringOpt(char shortopt, const char* longopt, std::string* valp,
00345               const char* valdesc = "", const char* desc = "",
00346               bool* setp = NULL);
00347 
00348 protected:
00349     int set(const char* val, size_t len);
00350 };
00351 
00355 class CharBufOpt : public Opt {
00356 public:
00369     CharBufOpt(const char* opt, char* valp, size_t* lenp, size_t buflen,
00370                const char* valdesc = "", const char* desc = "",
00371                bool* setp = NULL);
00372     
00387     CharBufOpt(char shortopt, const char* longopt,
00388                char* valp, size_t* lenp, size_t buflen,
00389                const char* valdesc = "", const char* desc = "",
00390                bool* setp = NULL);
00391     
00392 protected:
00393     size_t buflen_;
00394     size_t* lenp_;
00395     
00396     int set(const char* val, size_t len);
00397 };
00398 
00402 class InAddrOpt : public Opt {
00403 public:
00414     InAddrOpt(const char* opt, in_addr_t* valp,
00415               const char* valdesc = "", const char* desc = "",
00416               bool* setp = NULL);
00417     
00430     InAddrOpt(char shortopt, const char* longopt, in_addr_t* valp,
00431               const char* valdesc = "", const char* desc = "",
00432               bool* setp = NULL);
00433 
00434 protected:
00435     int set(const char* val, size_t len);
00436 };
00437 
00442 class EnumOpt : public Opt {
00443 public:
00444     struct Case {
00445         const char* key;
00446         int         val;
00447     };
00448     
00460     EnumOpt(const char* opt, Case* cases, int* valp,
00461             const char* valdesc = "", const char* desc = "",
00462             bool* setp = NULL);
00463     
00477     EnumOpt(char shortopt, const char* longopt,
00478             Case* cases, int* valp,
00479             const char* valdesc = "", const char* desc = "",
00480             bool* setp = NULL);
00481 
00482 protected:
00483     int set(const char* val, size_t len);
00484     Case* cases_;
00485 };
00486 
00487 #ifdef OASYS_BLUETOOTH_ENABLED
00488 #include <bluetooth/bluetooth.h>
00492 class BdAddrOpt : public Opt {
00493 public:
00504     BdAddrOpt(const char* opt, bdaddr_t* valp,
00505               const char* valdesc = "", const char* desc = "",
00506               bool* setp = NULL);
00507 
00520     BdAddrOpt(char shortopt, const char* longopt, bdaddr_t* valp,
00521               const char* valdesc = "", const char* desc = "",
00522               bool* setp = NULL);
00523 
00524 protected:
00525     int set(const char* val, size_t len);
00526 };
00527 #endif // OASYS_BLUETOOTH_ENABLED
00528 
00529 } // namespace oasys
00530 
00531 #endif /* _OASYS_OPTIONS_H_ */

Generated on Fri Dec 22 14:48:00 2006 for DTN Reference Implementation by  doxygen 1.5.1