cgicc: FormEntry.h Source File

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

# FormEntry.h

Go to the documentation of this file.

    00001 /* -*-mode:c++; c-file-style: "gnu";-*- */
    00002 /*
    00003  *  $Id: FormEntry.h,v 1.14 2007/07/02 18:48:18 sebdiaz Exp $
    00004  *
    00005  *  Copyright (C) 1996 - 2004 Stephen F. Booth <sbooth@gnu.org>
    00006  *                       2007 Sebastien DIAZ <sebastien.diaz@gmail.com>
    00007  *  Part of the GNU cgicc library, http://www.gnu.org/software/cgicc
    00008  *
    00009  *  This library is free software; you can redistribute it and/or
    00010  *  modify it under the terms of the GNU Lesser General Public
    00011  *  License as published by the Free Software Foundation; either
    00012  *  version 3 of the License, or (at your option) any later version.
    00013  *
    00014  *  This library is distributed in the hope that it will be useful,
    00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00017  *  Lesser General Public License for more details.
    00018  *
    00019  *  You should have received a copy of the GNU Lesser General Public
    00020  *  License along with this library; if not, write to the Free Software
    00021  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
    00022  */
    00023
    00024 #ifndef _FORMENTRY_H_
    00025 #define _FORMENTRY_H_ 1
    00026
    00027 #ifdef __GNUG__
    00028 #  pragma interface
    00029 #endif
    00030
    00041 #include <iostream>
    00042 #include <string>
    00043 #include <climits>
    00044 #include <cfloat>
    00045
    00046 #include "cgicc/CgiDefs.h"
    00047 #include "cgicc/CgiUtils.h"
    00048
    00049 namespace cgicc {
    00050
    00051   // ============================================================
    00052   // Class FormEntry
    00053   // ============================================================
    00054
    00070   class CGICC_API FormEntry
    00071   {
    00072   public:
    00073
    00074     // ============================================================
    00075
    00078
    00084     inline
    00085     FormEntry()
    00086     {}
    00087
    00095     inline
    00096     FormEntry(const std::string& name,
    00097               const std::string& value)
    00098       : fName(name), fValue(value)
    00099     {}
    00100
    00107     inline
    00108     FormEntry(const FormEntry& entry)
    00109     { operator=(entry); }
    00110
    00116     inline
    00117     ~FormEntry()
    00118     {}
    00120
    00121     // ============================================================
    00122
    00125
    00133     inline bool
    00134     operator== (const FormEntry& entry)                 const
    00135     { return stringsAreEqual(fName, entry.fName); }
    00136
    00144     inline bool
    00145     operator!= (const FormEntry& entry)                 const
    00146     { return ! operator==(entry); }
    00147
    00148 #ifdef WIN32
    00149     /* Dummy operator for MSVC++ */
    00150     inline bool
    00151     operator< (const FormEntry& entry)                  const
    00152     { return false; }
    00153 #endif
    00154
    00162     FormEntry&
    00163     operator= (const FormEntry& entry);
    00165
    00166     // ============================================================
    00167
    00172
    00180     inline std::string
    00181     getName()                                           const
    00182     { return fName; }
    00183
    00190     inline std::string
    00191     getValue()                                          const
    00192     { return fValue; }
    00193
    00200     inline std::string
    00201     operator* ()                                        const
    00202     { return getValue(); }
    00203
    00212     inline std::string
    00213     getValue(std::string::size_type maxChars)           const
    00214     { return makeString(maxChars, true); }
    00215
    00222     inline std::string
    00223     getStrippedValue()                                  const
    00224     { return getStrippedValue(INT_MAX); }
    00225
    00235     inline std::string
    00236     getStrippedValue(std::string::size_type maxChars)   const
    00237     { return makeString(maxChars, false); }
    00238
    00247     long
    00248     getIntegerValue(long min = LONG_MIN,
    00249                     long max = LONG_MAX)                const;
    00250
    00261     long
    00262     getIntegerValue(long min,
    00263                     long max,
    00264                     bool& bounded)                      const;
    00265
    00274     double
    00275     getDoubleValue(double min = -DBL_MAX,
    00276                    double max = DBL_MAX)                const;
    00277
    00288     double
    00289     getDoubleValue(double min,
    00290                    double max,
    00291                    bool& bounded)                       const;
    00292
    00293
    00300     inline std::string::size_type
    00301     length()                                            const
    00302     { return fValue.length(); }
    00303
    00310     inline bool
    00311     isEmpty()                                           const
    00312     { return (0 == length()); }
    00314
    00315   private:
    00316     // utility function
    00317     std::string
    00318     makeString(std::string::size_type maxLen,
    00319                bool allowNewlines)                      const;
    00320
    00321     std::string fName;          // the name of this form element
    00322     std::string fValue;         // the value of this form element
    00323   };
    00324
    00325 } // namespace cgicc
    00326
    00327 #endif /* ! _FORMENTRY_H_ */