H3D API  2.4.1
SFString.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
26 //
28 #ifndef __SFSTRING_H__
29 #define __SFSTRING_H__
30 
31 #include <H3D/SField.h>
32 
33 namespace H3D {
34 
35  // template specializations in order to get nicer type printouts.
36  template<>
37  inline string SField< string >::classTypeName() { return "SFString"; }
38 
41  class H3DAPI_API SFString: public SField< string > {
42  public:
43  SFString() {}
44  SFString( const string &_value ): SField< string >( _value ){}
45  virtual X3DTypes::X3DType getX3DType() { return X3DTypes::SFSTRING; }
46 
51  inline void addValidValue( const string &s ) {
52  valid_values.insert( s );
53  }
54 
59  template< class InputIterator >
60  inline void addValidValues( InputIterator begin, InputIterator end ) {
61  valid_values.insert( begin, end );
62  }
63 
66  inline bool isValidValue( const string &s ) {
67  return valid_values.find( s ) != valid_values.end();
68  }
69 
72  inline bool hasValidValues() {
73  return valid_values.size() > 0;
74  }
75 
77  const set< string > &getValidValues() {
78  return valid_values;
79  }
80 
83  valid_values.clear();
84  }
85 
86  protected:
87  set< string > valid_values;
88  };
89 }
90 
91 #endif
92 
Contains the SField template class.
virtual X3DTypes::X3DType getX3DType()
Returns the X3DType of the field.
Definition: Field.h:138
The SFString field contains a string.
Definition: SFString.h:41
bool isValidValue(const string &s)
Returns true if the given string is one of the specified valid values for the field.
Definition: SFString.h:66
void clearValidValues()
Clears the valid values for the field.
Definition: SFString.h:82
bool hasValidValues()
Returns true if any valid values have been specified for the field.
Definition: SFString.h:72
const set< string > & getValidValues()
Returns the valid values for the field.
Definition: SFString.h:77
void addValidValues(InputIterator begin, InputIterator end)
Add valid values for the string.
Definition: SFString.h:60
void addValidValue(const string &s)
Add a valid value for the string.
Definition: SFString.h:51
Template class that adds the Field mechanisms to an encapsulated value of specified type.
Definition: SField.h:90
static string classTypeName()
Returns a string name for this field type e.g. SFInt32.
Definition: SField.h:169
H3D API namespace.
Definition: Anchor.h:38