Options.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #ifndef _OASYS_OPTIONS_H_
00018 #define _OASYS_OPTIONS_H_
00019 
00020 #include <config.h>
00021 #include <string>
00022 #include <vector>
00023 #include "../compat/inet_aton.h"
00024 
00025 #ifdef OASYS_BLUETOOTH_ENABLED
00026 #include <bluetooth/bluetooth.h>
00027 #endif // OASYS_BLUETOOTH_ENABLED
00028 
00029 namespace oasys {
00030 
00031 class StringBuffer;
00032 
00038 class Opt {
00039     friend class Getopt;
00040     friend class OptParser;
00041     friend class TclCommand;
00042 
00043 public:
00044     virtual ~Opt();
00045     
00046 protected:
00050     Opt(char shortopt, const char* longopt,
00051         void* valp, bool* setp, bool needval,
00052         const char* valdesc, const char* desc);
00053 
00057     virtual int set(const char* val, size_t len) = 0;
00058     
00062     virtual void get(StringBuffer* buf) = 0;
00063     
00064     char        shortopt_;
00065     const char* longopt_;
00066     void*       valp_;
00067     bool*       setp_;
00068     bool        needval_;
00069     const char* valdesc_;
00070     const char* desc_;
00071 };
00072 
00076 class BoolOpt : public Opt {
00077 public:
00087     BoolOpt(const char* opt, bool* valp,
00088             const char* desc = "", bool* setp = NULL);
00089 
00101     BoolOpt(char shortopt, const char* longopt, bool* valp,
00102             const char* desc = "", bool* setp = NULL);
00103 
00104 protected:
00105     int set(const char* val, size_t len);
00106     void get(StringBuffer* buf);
00107 };
00108 
00112 class IntOpt : public Opt {
00113 public:
00124     IntOpt(const char* opt, int* valp,
00125            const char* valdesc = "", const char* desc = "",
00126            bool* setp = NULL);
00127     
00140     IntOpt(char shortopt, const char* longopt, int* valp,
00141            const char* valdesc = "", const char* desc = "",
00142            bool* setp = NULL);
00143     
00144 protected:
00145     int set(const char* val, size_t len);
00146     void get(StringBuffer* buf);
00147 };
00148 
00152 class UIntOpt : public Opt {
00153 public:
00164     UIntOpt(const char* opt, u_int* valp,
00165             const char* valdesc = "", const char* desc = "",
00166             bool* setp = NULL);
00167     
00180     UIntOpt(char shortopt, const char* longopt, u_int* valp,
00181             const char* valdesc = "", const char* desc = "",
00182             bool* setp = NULL);
00183     
00184 protected:
00185     int set(const char* val, size_t len);
00186     void get(StringBuffer* buf);
00187 };
00188 
00192 class UInt64Opt : public Opt {
00193 public:
00204     UInt64Opt(const char* opt, u_int64_t* valp,
00205               const char* valdesc = "", const char* desc = "",
00206               bool* setp = NULL);
00207     
00220     UInt64Opt(char shortopt, const char* longopt, u_int64_t* valp,
00221               const char* valdesc = "", const char* desc = "",
00222               bool* setp = NULL);
00223     
00224 protected:
00225     int set(const char* val, size_t len);
00226     void get(StringBuffer* buf);
00227 };
00228 
00232 class UInt16Opt : public Opt {
00233 public:
00244     UInt16Opt(const char* opt, u_int16_t* valp,
00245               const char* valdesc = "", const char* desc = "",
00246               bool* setp = NULL);
00247     
00260     UInt16Opt(char shortopt, const char* longopt, u_int16_t* valp,
00261               const char* valdesc = "", const char* desc = "",
00262               bool* setp = NULL);
00263     
00264 protected:
00265     int set(const char* val, size_t len);
00266     void get(StringBuffer* buf);
00267 };
00268 
00272 class UInt8Opt : public Opt {
00273 public:
00284     UInt8Opt(const char* opt, u_int8_t* valp,
00285              const char* valdesc = "", const char* desc = "",
00286              bool* setp = NULL);
00287 
00300     UInt8Opt(char shortopt, const char* longopt, u_int8_t* valp,
00301              const char* valdesc = "", const char* desc = "",
00302              bool* setp = NULL);
00303 
00304 protected:
00305     int set(const char* val, size_t len);
00306     void get(StringBuffer* buf);
00307 };
00308 
00312 class DoubleOpt : public Opt {
00313 public:
00324     DoubleOpt(const char* opt, double* valp,
00325               const char* valdesc = "", const char* desc = "",
00326               bool* setp = NULL);
00327     
00340     DoubleOpt(char shortopt, const char* longopt, double* valp,
00341               const char* valdesc = "", const char* desc = "",
00342               bool* setp = NULL);
00343     
00344 protected:
00345     int set(const char* val, size_t len);
00346     void get(StringBuffer* buf);
00347 };
00348 
00352 class StringOpt : public Opt {
00353 public:
00364     StringOpt(const char* opt, std::string* valp,
00365               const char* valdesc = "", const char* desc = "",
00366               bool* setp = NULL);
00367     
00380     StringOpt(char shortopt, const char* longopt, std::string* valp,
00381               const char* valdesc = "", const char* desc = "",
00382               bool* setp = NULL);
00383 
00384 protected:
00385     int set(const char* val, size_t len);
00386     void get(StringBuffer* buf);
00387 };
00388 
00392 class CharBufOpt : public Opt {
00393 public:
00406     CharBufOpt(const char* opt, char* valp, size_t* lenp, size_t buflen,
00407                const char* valdesc = "", const char* desc = "",
00408                bool* setp = NULL);
00409     
00424     CharBufOpt(char shortopt, const char* longopt,
00425                char* valp, size_t* lenp, size_t buflen,
00426                const char* valdesc = "", const char* desc = "",
00427                bool* setp = NULL);
00428     
00429 protected:
00430     size_t buflen_;
00431     size_t* lenp_;
00432     
00433     int set(const char* val, size_t len);
00434     void get(StringBuffer* buf);
00435 };
00436 
00440 class InAddrOpt : public Opt {
00441 public:
00452     InAddrOpt(const char* opt, in_addr_t* valp,
00453               const char* valdesc = "", const char* desc = "",
00454               bool* setp = NULL);
00455     
00468     InAddrOpt(char shortopt, const char* longopt, in_addr_t* valp,
00469               const char* valdesc = "", const char* desc = "",
00470               bool* setp = NULL);
00471 
00472 protected:
00473     int set(const char* val, size_t len);
00474     void get(StringBuffer* buf);
00475 };
00476 
00481 class EnumOpt : public Opt {
00482 public:
00483     struct Case {
00484         const char* key;
00485         int         val;
00486     };
00487     
00499     EnumOpt(const char* opt, Case* cases, int* valp,
00500             const char* valdesc = "", const char* desc = "",
00501             bool* setp = NULL);
00502     
00516     EnumOpt(char shortopt, const char* longopt,
00517             Case* cases, int* valp,
00518             const char* valdesc = "", const char* desc = "",
00519             bool* setp = NULL);
00520 
00521 protected:
00522     int set(const char* val, size_t len);
00523     void get(StringBuffer* buf);
00524     Case* cases_;
00525 };
00526 
00527 #ifdef OASYS_BLUETOOTH_ENABLED
00528 
00531 class BdAddrOpt : public Opt {
00532 public:
00543     BdAddrOpt(const char* opt, bdaddr_t* valp,
00544               const char* valdesc = "", const char* desc = "",
00545               bool* setp = NULL);
00546 
00559     BdAddrOpt(char shortopt, const char* longopt, bdaddr_t* valp,
00560               const char* valdesc = "", const char* desc = "",
00561               bool* setp = NULL);
00562 
00563 protected:
00564     int set(const char* val, size_t len);
00565     void get(StringBuffer* buf);
00566 };
00567 #endif // OASYS_BLUETOOTH_ENABLED
00568 
00569 } // namespace oasys
00570 
00571 #endif /* _OASYS_OPTIONS_H_ */

Generated on Thu Jun 7 16:56:51 2007 for DTN Reference Implementation by  doxygen 1.5.1