⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keyval.h

📁 大型并行量子化学软件;支持密度泛函(DFT)。可以进行各种量子化学计算。支持CHARMM并行计算。非常具有应用价值。
💻 H
📖 第 1 页 / 共 2 页
字号:
//// keyval.h//// Copyright (C) 1996 Limit Point Systems, Inc.//// Author: Curtis Janssen <cljanss@limitpt.com>// Maintainer: LPS//// This file is part of the SC Toolkit.//// The SC Toolkit is free software; you can redistribute it and/or modify// it under the terms of the GNU Library General Public License as published by// the Free Software Foundation; either version 2, or (at your option)// any later version.//// The SC Toolkit is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU Library General Public License for more details.//// You should have received a copy of the GNU Library General Public License// along with the SC Toolkit; see the file COPYING.LIB.  If not, write to// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.//// The U.S. Government is granted a limited license as per AL 91-7.//#ifndef _util_keyval_keyval_h#define _util_keyval_keyval_h#ifdef __GNUG__#pragma interface#endif#include <iostream>#include <string>#include <map>#include <string.h>#include <stdlib.h>#include <stdarg.h>#include <util/class/class.h>#include <util/keyval/keyvalval.h>namespace sc {/** The KeyVal class is designed to simplify the process of allowing a user to specify keyword/value associations to a C++ program.  A flexible input style and ease of use for the programmer is achieved with this method.  Keywords are represented by null terminated character arrays. The keywords are organized hierarchially, in a manner similar to the way that many file systems are organized.  One character is special, ":", which is used to separate the various hierarchial labels, which are referred to as "segments", in the keyword. A convention for specifying arrays is provided by KeyVal.  Each index of the array is given by appending a segment containing the character representation of the index.  Thus, "array:3:4" would be a the keyword corresponding to fourth row and fifth column of "array", since indexing starts at zero. To allow the KeyVal class to have associations that can represent data for classes, the keyword can be associated with a class as well as a value.  This permits polymorphic data to be unambiguously represented by keyword/value associations.  Most use of KeyVal need not be concerned with this.*/class KeyVal: public RefCount {    // these classes need to directly access the key_value member    friend class AggregateKeyVal;    friend class PrefixKeyVal;  public:    enum {MaxKeywordLength = 256};    enum KeyValError { OK, HasNoValue, WrongType,                       UnknownKeyword, OperationFailed };  private:    KeyValError errcod;    // do not allow a copy constructor or assignment    KeyVal(const KeyVal&);    void operator=(const KeyVal&);  protected:    int verbose_;    KeyVal();    /// Set the current error condition.    void seterror(KeyValError err);    /// Set the current error condition.    void seterror(KeyValValue::KeyValValueError err);    /// Ultimately called by exists.    virtual int    key_exists(const char*) = 0;    /// Ultimately called by count.    virtual int    key_count(const char* =0);    /// Ultimately called by value.    virtual Ref<KeyValValue> key_value(const char*,                                     const KeyValValue& def) = 0;    /// Ultimately called by booleanvalue.    virtual int    key_booleanvalue(const char*,const KeyValValue& def);    /// Ultimately called by doublevalue.    virtual double key_doublevalue(const char* key,const KeyValValue& def);    /// Ultimately called by floatvalue.    virtual float  key_floatvalue(const char* key,const KeyValValue& def);    /// Ultimately called by charvalue.    virtual char   key_charvalue(const char* key,const KeyValValue& def);    /// Ultimately called by intvalue.    virtual int    key_intvalue(const char* key,const KeyValValue& def);    /// Ultimately called by sizevalue.    virtual size_t key_sizevalue(const char* key,const KeyValValue& def);    /// Ultimately called by pcharvalue.    virtual char*  key_pcharvalue(const char* key,const KeyValValue& def);    /// Ultimately called by stringvalue.    virtual std::string key_stringvalue(const char* key,                                        const KeyValValue& def);    /// Ultimately called by describedclassvalue.    virtual Ref<DescribedClass> key_describedclassvalue(const char* key,                                                      const KeyValValue& def);  public:    virtual ~KeyVal();    // For nonindexed things.   If a subclass defines one of these,    // then the overloaded functions will be hidden.  The key_... functions    // should be overridden instead.    /** This takes as its only argument a keyword.        Returns 1 if the keyword has a value and 0 otherwise. */    int    exists(const char*);    /** If the value of a keyword is an array, then return its length.        If no arguments are given then the top level will be checked to        see if it is an array and, if so, the number of elements will be        counted. */    int    count(const char* =0);    /// Return the value associated with the keyword.    Ref<KeyValValue> value(const char* = 0,                         const KeyValValue& def=KeyValValue());    /// Returns the boolean value (0 = false, 1 = true) of key.    int    booleanvalue(const char* key = 0,                        const KeyValValue& def=KeyValValueboolean());    /// Returns the double value of key.    double doublevalue(const char* key = 0,                       const KeyValValue& def=KeyValValuedouble());    /// Returns the float value of key.    float  floatvalue(const char* key = 0,                      const KeyValValue& def=KeyValValuefloat());    /// Returns the char value of key.    char   charvalue(const char* key = 0,                     const KeyValValue& def=KeyValValuechar());    /// Returns the int value of key.    int    intvalue(const char* key = 0,                    const KeyValValue& def=KeyValValueint());    /// Returns the size_t value of key.    size_t sizevalue(const char* key = 0,                     const KeyValValue& def=KeyValValuesize());    /** Returns a copy of the string representation of the key's        value. Storage for the copy is obtained with new. */    char*  pcharvalue(const char* key = 0,                      const KeyValValue& def=KeyValValuepchar());    /** Returns a string representation of the key's value. */    std::string stringvalue(const char* key = 0,                            const KeyValValue& def=KeyValValuestring());    /// Returns a reference to an object of type DescribedClass.    Ref<DescribedClass> describedclassvalue(const char* key = 0,                     const KeyValValue& def=KeyValValueRefDescribedClass());    /** These members correspond to the above members, but take        an additional integer argument, i, which is a vector index.        This is equivalent to getting a value for a keyword named        "<i>key</i>:<i>i</i>".  The routines that do not take        key arguments get the value for the keyword named "<i>i</i>".     */    //@{    int    exists(const char* key,int i);    int    count(const char* key,int i);    int    booleanvalue(const char* key,int i,                        const KeyValValue& def=KeyValValueboolean());    double doublevalue(const char* key,int i,                       const KeyValValue& def=KeyValValuedouble());    float  floatvalue(const char* key,int i,                      const KeyValValue& def=KeyValValuefloat());    char   charvalue(const char* key,int i,                     const KeyValValue& def=KeyValValuechar());    int    intvalue(const char* key,int i,                    const KeyValValue& def=KeyValValueint());    size_t sizevalue(const char* key,int i,                     const KeyValValue& def=KeyValValuesize());    char*  pcharvalue(const char* key,int i,                      const KeyValValue& def=KeyValValuepchar());    std::string stringvalue(const char* key,int i,                            const KeyValValue& def=KeyValValuestring());    Ref<DescribedClass> describedclassvalue(const char* key,int,                     const KeyValValue& def=KeyValValueRefDescribedClass());    int    exists(int i);    int    count(int i);    int    booleanvalue(int i,                        const KeyValValue& def=KeyValValueboolean());    double doublevalue(int i,                       const KeyValValue& def=KeyValValuedouble());    float  floatvalue(int i,                      const KeyValValue& def=KeyValValuefloat());    char   charvalue(int i,                     const KeyValValue& def=KeyValValuechar());    int    intvalue(int i,                    const KeyValValue& def=KeyValValueint());    size_t sizevalue(int i,                     const KeyValValue& def=KeyValValuesize());    char*  pcharvalue(int i,                      const KeyValValue& def=KeyValValuepchar());    std::string stringvalue(int i,                            const KeyValValue& def=KeyValValuestring());    Ref<DescribedClass> describedclassvalue(int i,                     const KeyValValue& def=KeyValValueRefDescribedClass());    //@}    /** These members correspond to the above members, but take additional        integer arguments, i and j, which is an array index.  This is        equivalent to getting a value for a keyword named        "<i>key</i>:<i>i</i>:<i>j</i>".  The routines that do not take key        arguments get the value for the keyword named "<i>i</i>:<i>j</i>".  */    //@{    int    exists(const char*,int,int);    int    count(const char*,int,int);    int    booleanvalue(const char*,int,int,                        const KeyValValue& def=KeyValValueboolean());    double doublevalue(const char* key,int,int,                       const KeyValValue& def=KeyValValuedouble());    float  floatvalue(const char* key,int,int,                      const KeyValValue& def=KeyValValuefloat());    char   charvalue(const char* key,int,int,                     const KeyValValue& def=KeyValValuechar());    int    intvalue(const char* key,int,int,                    const KeyValValue& def=KeyValValueint());    size_t sizevalue(const char* key,int,int,                     const KeyValValue& def=KeyValValuesize());    char*  pcharvalue(const char* key,int,int,                      const KeyValValue& def=KeyValValuepchar());    std::string stringvalue(const char* key,int,int,                            const KeyValValue& def=KeyValValuestring());    Ref<DescribedClass> describedclassvalue(const char* key,int,int,                     const KeyValValue& def=KeyValValueRefDescribedClass());    int    exists(int i,int j);    int    count(int i,int j);    int    booleanvalue(int i,int j,                        const KeyValValue& def=KeyValValueboolean());    double doublevalue(int i,int j,                       const KeyValValue& def=KeyValValuedouble());    float  floatvalue(int i,int j,                      const KeyValValue& def=KeyValValuefloat());    char   charvalue(int i,int j,                     const KeyValValue& def=KeyValValuechar());    int    intvalue(int i,int j,                    const KeyValValue& def=KeyValValueint());    size_t sizevalue(int i,int j,                     const KeyValValue& def=KeyValValuesize());    char*  pcharvalue(int i,int j,                      const KeyValValue& def=KeyValValuepchar());    std::string stringvalue(int i,int j,                            const KeyValValue& def=KeyValValuestring());    Ref<DescribedClass> describedclassvalue(int i,int j,                     const KeyValValue& def=KeyValValueRefDescribedClass());    //@}    /** These members correspond to the above members, but can be used        to read in arrays with more than two dimensions.  The nindex        argument is the number of indices in the array.  It is followed        by an int giving the value of each index.  */    //@{    int    Va_exists(const char* key,int nindex,...);    int    Va_count(const char* key,int nindex,...);    int    Va_booleanvalue(const char* key,int nindex,...);    double Va_doublevalue(const char* key,int nindex,...);    float  Va_floatvalue(const char* key,int nindex,...);    char   Va_charvalue(const char* key,int nindex,...);    int    Va_intvalue(const char* key,int nindex,...);    size_t Va_sizevalue(const char* key,int nindex,...);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -