H3D API  2.4.1
TypedField.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 __TYPEDFIELD_H__
29 #define __TYPEDFIELD_H__
30 
31 #include <sstream>
32 #include <H3D/TypedFieldCheck.h>
33 
34 namespace H3D {
35  using namespace TypedFieldTypeCheck;
80 
81  template< class BaseField,
82  class RequiredArgTypes,
83  class OptionalArgTypes = void >
84  class TypedField : public BaseField {
85  public:
86  TypedField() {
87  try {
88  checkTemplateArguments();
89  } catch( const InvalidTemplateArguments &e ) {
90  stringstream s;
91  s << e << " in definition of field named \"" << this->getFullName()
92  << "\". ";
93  throw TypedFieldError( s.str() );
94  }
95  }
96 
97  protected:
106  void checkFieldType( Field *f, int index ) {
107  try {
108  TypedFieldCheck< RequiredArgTypes,
109  OptionalArgTypes >::checkFieldType( f, index, 0 );
110  } catch( TypedFieldError &e ) {
111  stringstream s;
112  s << e.message << " Source field: \"" << f->getFullName()
113  << "\". Destination field: \"" << this->getFullName()
114  << "\".";
115  e.message = s.str();
116  throw e;
117  }
118  }
119 
125  TypedFieldCheck< RequiredArgTypes,
126  OptionalArgTypes >::checkTemplateArguments();
127  }
128  };
129 }
130 
131 #endif
Contains a lot of help template classes for checking the types of a field given a TypedField template...
The Field class.
Definition: Field.h:46
string getFullName()
Get the full name of the field including the name of the owner node if it exists (ownername....
Definition: Field.cpp:406
An exception thrown when the field does not conform to the type specification from a TypedField.
Definition: TypedFieldCheck.h:45
InvalidTemplateArguments An exception thrown when the template argument list does not follow the rule...
Definition: TypedFieldCheck.h:57
A template modifier class for adding type checking on the routes to any Field class.
Definition: TypedField.h:84
void checkTemplateArguments()
Function for checking that a field given TypedField type specification is valid.
Definition: TypedField.h:124
void checkFieldType(Field *f, int index)
Function for checking that a field is of a correct type given type specification according to the Typ...
Definition: TypedField.h:106
H3D API namespace.
Definition: Anchor.h:38