FormEntry.h
Go to the documentation of this file.
1 /* -*-mode:c++; c-file-style: "gnu";-*- */
2 /*
3  * $Id: FormEntry.h,v 1.15 2014/04/23 20:55:04 sebdiaz Exp $
4  *
5  * Copyright (C) 1996 - 2004 Stephen F. Booth <sbooth@gnu.org>
6  * 2007 Sebastien DIAZ <sebastien.diaz@gmail.com>
7  * Part of the GNU cgicc library, http://www.gnu.org/software/cgicc
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
22  */
23 
24 #ifndef _FORMENTRY_H_
25 #define _FORMENTRY_H_ 1
26 
27 #ifdef __GNUG__
28 # pragma interface
29 #endif
30 
41 #include <iostream>
42 #include <string>
43 #include <climits>
44 #include <cfloat>
45 
46 #include "CgiDefs.h"
47 #include "CgiUtils.h"
48 
49 namespace cgicc {
50 
51  // ============================================================
52  // Class FormEntry
53  // ============================================================
54 
70  class CGICC_API FormEntry
71  {
72  public:
73 
74  // ============================================================
75 
78 
84  inline
86  {}
87 
95  inline
96  FormEntry(const std::string& name,
97  const std::string& value)
98  : fName(name), fValue(value)
99  {}
100 
107  inline
108  FormEntry(const FormEntry& entry)
109  { operator=(entry); }
110 
116  inline
118  {}
120 
121  // ============================================================
122 
125 
133  inline bool
134  operator== (const FormEntry& entry) const
135  { return stringsAreEqual(fName, entry.fName); }
136 
144  inline bool
145  operator!= (const FormEntry& entry) const
146  { return ! operator==(entry); }
147 
148 #ifdef WIN32
149  /* Dummy operator for MSVC++ */
150  inline bool
151  operator< (const FormEntry& entry) const
152  { return false; }
153 #endif
154 
162  FormEntry&
163  operator= (const FormEntry& entry);
165 
166  // ============================================================
167 
172 
180  inline std::string
181  getName() const
182  { return fName; }
183 
190  inline std::string
191  getValue() const
192  { return fValue; }
193 
200  inline std::string
201  operator* () const
202  { return getValue(); }
203 
212  inline std::string
213  getValue(std::string::size_type maxChars) const
214  { return makeString(maxChars, true); }
215 
222  inline std::string
224  { return getStrippedValue(INT_MAX); }
225 
235  inline std::string
236  getStrippedValue(std::string::size_type maxChars) const
237  { return makeString(maxChars, false); }
238 
247  long
248  getIntegerValue(long min = LONG_MIN,
249  long max = LONG_MAX) const;
250 
261  long
262  getIntegerValue(long min,
263  long max,
264  bool& bounded) const;
265 
274  double
275  getDoubleValue(double min = -DBL_MAX,
276  double max = DBL_MAX) const;
277 
288  double
289  getDoubleValue(double min,
290  double max,
291  bool& bounded) const;
292 
293 
300  inline std::string::size_type
301  length() const
302  { return fValue.length(); }
303 
310  inline bool
311  isEmpty() const
312  { return (0 == length()); }
314 
315  private:
316  // utility function
317  std::string
318  makeString(std::string::size_type maxLen,
319  bool allowNewlines) const;
320 
321  std::string fName; // the name of this form element
322  std::string fValue; // the value of this form element
323  };
324 
325 } // namespace cgicc
326 
327 #endif /* ! _FORMENTRY_H_ */
Class representing a single HTML form entry.
Definition: FormEntry.h:70
std::string::size_type length() const
Get the number of characters in the value of the form element.
Definition: FormEntry.h:301
Platform and operating system specific macro definitions.
FormEntry()
Default constructor.
Definition: FormEntry.h:85
std::string getValue() const
Get the value of the form element as a string.
Definition: FormEntry.h:191
std::string getStrippedValue() const
Get the value of the form element as a string.
Definition: FormEntry.h:223
~FormEntry()
Destructor.
Definition: FormEntry.h:117
FormEntry(const std::string &name, const std::string &value)
Create a new FormEntry.
Definition: FormEntry.h:96
std::string getName() const
Get the name of the form element.
Definition: FormEntry.h:181
std::string getValue(std::string::size_type maxChars) const
Get the value of the form element as a string.
Definition: FormEntry.h:213
bool isEmpty() const
Determine if this form element is empty.
Definition: FormEntry.h:311
A collection of utility functions.
std::string getStrippedValue(std::string::size_type maxChars) const
Get the value of the form element as a string.
Definition: FormEntry.h:236
FormEntry(const FormEntry &entry)
Copy constructor.
Definition: FormEntry.h:108
bool stringsAreEqual(const std::string &s1, const std::string &s2)
Compare two strings for equality, ignoring case.
The namespace containing the cgicc library.
Definition: Cgicc.h:52
string getValue(string pName)
Get all personnal information from the cookie&#39;s Id.
Definition: cardgame.cpp:247

GNU cgicc - A C++ class library for writing CGI applications
Copyright © 1996 - 2004 Stephen F. Booth
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front Cover Texts, and with no Back-Cover Texts.
Documentation generated Fri Jan 28 2022 06:24:15 for cgicc by doxygen 1.8.13