H3D API  2.4.1
MFString.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 __MFSTRING_H__
29 #define __MFSTRING_H__
30 
31 #include <H3D/MField.h>
32 
33 namespace H3D {
34 
35  // template specializations in order to get nicer type printouts.
36  template<>
37  inline string MFieldBase< string >::classTypeName() { return "MFString"; }
38 
41  class H3DAPI_API MFString: public MField< string > {
42  public:
43  MFString(){}
44  MFString( size_type sz ): MField< string >( sz ){}
45  inline virtual string getValueAsString( const string& separator = " " ) {
46  stringstream s;
47  const vector< string > &v = getValue();
48  if( v.size() == 0 )
49  return "";
50  unsigned int i;
51  for( i = 0; i < v.size() - 1; ++i )
52  s << "\"" << v[i] << "\"" << separator;
53  s << "\"" << v[i] << "\"";
54  return s.str();
55  }
56  virtual X3DTypes::X3DType getX3DType() { return X3DTypes::MFSTRING; }
57  };
58 }
59 
60 #endif
61 
Contains base classes used to create multivalued fields.
The MFString field conatins a vector of strings.
Definition: MFString.h:41
virtual string getValueAsString(const string &separator=" ")
Get the value of the field as a string.
Definition: MFString.h:45
static string classTypeName()
Returns a string name for this field type e.g. MFInt32.
Definition: MField.h:340
VectorClass::size_type size_type
An unsigned integral type.
Definition: MField.h:118
Template class that adds the Field mechanism to a vector of values.
Definition: MField.h:357
Type getValue(const char *s, const char *&rest)
Function that reads characters from a char * and converts them to a given type.
Definition: X3DFieldConversion.h:134
H3D API namespace.
Definition: Anchor.h:38