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
85 FormEntry()
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
117 ~FormEntry()
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
223 getStrippedValue() const
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_ */
CgiDefs.h
Platform and operating system specific macro definitions.
CgiUtils.h
A collection of utility functions.
cgicc::FormEntry
Class representing a single HTML form entry.
Definition: FormEntry.h:71
cgicc::FormEntry::getIntegerValue
long getIntegerValue(long min, long max, bool &bounded) const
Get the value of the form element as an integer.
cgicc::FormEntry::isEmpty
bool isEmpty() const
Determine if this form element is empty.
Definition: FormEntry.h:311
cgicc::FormEntry::~FormEntry
~FormEntry()
Destructor.
Definition: FormEntry.h:117
cgicc::FormEntry::getDoubleValue
double getDoubleValue(double min=-DBL_MAX, double max=DBL_MAX) const
Get the value of the form element as a double.
cgicc::FormEntry::getValue
std::string getValue(std::string::size_type maxChars) const
Get the value of the form element as a string.
Definition: FormEntry.h:213
cgicc::FormEntry::FormEntry
FormEntry()
Default constructor.
Definition: FormEntry.h:85
cgicc::FormEntry::FormEntry
FormEntry(const FormEntry &entry)
Copy constructor.
Definition: FormEntry.h:108
cgicc::FormEntry::getDoubleValue
double getDoubleValue(double min, double max, bool &bounded) const
Get the value of the form element as a double.
cgicc::FormEntry::getIntegerValue
long getIntegerValue(long min=LONG_MIN, long max=LONG_MAX) const
Get the value of the form element as an integer.
cgicc::FormEntry::getValue
std::string getValue() const
Get the value of the form element as a string.
Definition: FormEntry.h:191
cgicc::FormEntry::getStrippedValue
std::string getStrippedValue(std::string::size_type maxChars) const
Get the value of the form element as a string.
Definition: FormEntry.h:236
cgicc::FormEntry::FormEntry
FormEntry(const std::string &name, const std::string &value)
Create a new FormEntry.
Definition: FormEntry.h:96
cgicc::FormEntry::getName
std::string getName() const
Get the name of the form element.
Definition: FormEntry.h:181
cgicc::FormEntry::getStrippedValue
std::string getStrippedValue() const
Get the value of the form element as a string.
Definition: FormEntry.h:223
cgicc::FormEntry::length
std::string::size_type length() const
Get the number of characters in the value of the form element.
Definition: FormEntry.h:301
CardGameTools::getValue
string getValue(string pName)
Get all personnal information from the cookie's Id.
Definition: cardgame.cpp:247
cgicc
The namespace containing the cgicc library.
Definition: Cgicc.h:52
cgicc::stringsAreEqual
bool stringsAreEqual(const std::string &s1, const std::string &s2)
Compare two strings for equality, ignoring case.