30 #ifndef __TYPEDFIELDCHECK_H__
31 #define __TYPEDFIELDCHECK_H__
50 namespace TypedFieldTypeCheck {
71 template<
class Type >
78 TypesType< Type >::checkTemplateArguments();
82 H3D_DISABLE_UNUSED_PARAMETER_WARNING()
90 TypesType< Type >::checkType( f );
99 template<H3D_TYPES_TEMPLATE_LIST>
104 static void checkTemplateArguments() {
105 H3D_TYPES_CLASS::checkTemplateArguments();
114 static void checkType( Field *f,
int index ) {
115 int nr_types = H3D_TYPES_CLASS::numberTypes();
116 H3D_TYPES_CLASS::checkType( f, index % nr_types );
126 template<
class Type >
127 struct AnyNumber< AnyNumber< Type > > {
134 string s=
"No AnyNumber statements allowed in AnyNumber statement.";
135 throw InvalidTemplateArguments( s );
142 static void checkType( Field *f,
int index ) {
143 string s=
"No AnyNumber statements allowed in AnyNumber statement.";
144 throw InvalidTemplateArguments( s );
153 template<
class Type >
159 static void checkTemplateArguments() {}
163 static bool checkType( Field *f ) {
164 return dynamic_cast< Type *
>( f ) != NULL;
174 template<H3D_ANY_TEMPLATE_LIST>
175 struct AnyType< H3D_ANY_CLASS > {
181 static void checkTemplateArguments() {
182 string s =
"No Any statements allowed in Any statement.";
183 throw InvalidTemplateArguments( s );
191 static bool checkType( Field *f ) {
192 string s =
"No Any statements allowed in Any statement.";
193 throw InvalidTemplateArguments( s );
203 template<H3D_TYPES_TEMPLATE_LIST>
204 struct AnyType< H3D_TYPES_CLASS > {
211 static void checkTemplateArguments() {
212 string s =
"No Types statements allowed in Any statement.";
213 throw InvalidTemplateArguments( s );
221 static bool checkType( Field *f ) {
222 string s =
"No Types statements allowed in Any statement.";
223 throw InvalidTemplateArguments( s );
233 template<
class Type >
234 struct AnyType< AnyNumber< Type > > {
241 static void checkTemplateArguments() {
242 string s =
"No AnyNumber statements allowed in Any statement.";
243 throw InvalidTemplateArguments( s );
251 static bool checkType( Field *f ) {
252 string s =
"No AnyNumber statements allowed in Any statement.";
253 throw InvalidTemplateArguments( s );
262 template<
class Type >
268 static void checkTemplateArguments() {}
272 static void checkType( Field *f ) {
273 if( !
dynamic_cast< Type *
>( f ) ) {
274 throw InvalidType( f->getTypeName(),
275 Type::classTypeName() );
284 template< H3D_ANY_TEMPLATE_LIST >
285 struct TypesType< H3D_ANY_CLASS > {
288 static void checkTemplateArguments() {
289 H3D_ANY_CLASS::checkTemplateArguments();
294 static void checkType( Field *f ) {
295 H3D_ANY_CLASS::checkType( f );
305 template< H3D_TYPES_TEMPLATE_LIST >
306 struct TypesType< H3D_TYPES_CLASS > {
312 static void checkTemplateArguments() {
313 string s =
"No Types statements allowed in another Types statement.";
314 throw InvalidTemplateArguments( s );
322 static void checkType( Field *f ) {
323 string s =
"No Types statements allowed in another Types statement.";
324 throw InvalidTemplateArguments( s );
335 template<
class Type >
336 struct TypesType< AnyNumber< Type > > {
343 static void checkTemplateArguments() {
344 string s =
"No AnyNumber statements allowed in Types statement.";
345 throw InvalidTemplateArguments( s );
353 static bool checkType( Field *f ) {
354 string s =
"No AnyNumber statements allowed in Types statement.";
355 throw InvalidTemplateArguments( s );
364 template<
class RequiredArgType,
365 class OptionalArgTypes >
366 struct TypedFieldCheck {
370 static void checkTemplateArguments() {
371 TypesType<RequiredArgType>::checkTemplateArguments();
372 TypedFieldCheck< void,
373 OptionalArgTypes >::checkTemplateArguments();
384 static void checkFieldType( Field *f,
387 if( field_index == type_index ) {
389 TypesType<RequiredArgType>::checkType( f );
392 s <<
"Route " << field_index <<
" has type "
393 << f->getTypeName() <<
". Expecting "
394 << RequiredArgType::classTypeName() <<
".";
398 TypedFieldCheck< void,
399 OptionalArgTypes >::checkFieldType( f,
411 template< H3D_TYPES_TEMPLATE_LIST,
class OptionalArgTypes >
412 struct TypedFieldCheck< H3D_TYPES_CLASS, OptionalArgTypes >{
416 static void checkTemplateArguments() {
417 H3D_TYPES_CLASS::checkTemplateArguments();
418 TypedFieldCheck< void,
419 OptionalArgTypes >::checkTemplateArguments();
430 static void checkFieldType( Field *f,
433 int nr_types = H3D_TYPES_CLASS::numberTypes();
434 if( field_index < type_index + nr_types ) {
436 H3D_TYPES_CLASS::checkType( f,
437 field_index - type_index );
438 }
catch(
const InvalidType &e ) {
440 s <<
"Route " << field_index <<
" has type "
441 << e.value <<
". Expecting "
446 TypedFieldCheck< void,
447 OptionalArgTypes >::checkFieldType( f,
461 template<
class Type,
class OptionalArgTypes >
462 struct TypedFieldCheck< AnyNumber< Type >, OptionalArgTypes >{
468 static void checkTemplateArguments() {
469 string s =
"AnyNumber statements not allowed as RequiredArgTypes";
470 throw InvalidTemplateArguments( s );
478 static void checkFieldType( Field *f,
481 string s =
"AnyNumber statements not allowed as RequiredArgTypes";
482 throw InvalidTemplateArguments( s );
491 struct TypedFieldCheck< void, void > {
495 static void checkTemplateArguments() {}
498 H3D_DISABLE_UNUSED_PARAMETER_WARNING()
507 static
void checkFieldType( Field *f,
511 s <<
"Too many routes. Expecing a maximum of "
512 << type_index <<
" routes.";
513 throw TypedFieldError( s.str() );
523 template< class OptionalArgType >
524 struct TypedFieldCheck<
void, OptionalArgType > {
528 static void checkTemplateArguments() {
529 TypesType< OptionalArgType >::checkTemplateArguments();
540 static void checkFieldType( Field *f,
543 if( field_index == type_index ) {
545 TypesType<OptionalArgType>::checkType( f );
548 s <<
"Route " << field_index <<
" has type "
549 << f->getTypeName() <<
". Expecting "
550 << OptionalArgType::classTypeName()
556 s <<
"Too many routes. Expecing a maximum of "
557 << type_index <<
" routes.";
568 template< H3D_TYPES_TEMPLATE_LIST >
569 struct TypedFieldCheck< void, H3D_TYPES_CLASS >{
573 static void checkTemplateArguments() {
574 H3D_TYPES_CLASS::checkTemplateArguments();
585 static void checkFieldType( Field *f,
588 int nr_types = H3D_TYPES_CLASS::numberTypes();
589 if( field_index < type_index + nr_types ) {
590 H3D_TYPES_CLASS::checkType( f,
591 field_index - type_index );
594 s <<
"Too many routes. Expecting a maximum of "
595 << type_index <<
" routes.";
606 template<
class Type >
607 struct TypedFieldCheck< void, AnyNumber< Type > >{
611 static void checkTemplateArguments() {
623 static void checkFieldType( Field *f,
628 }
catch(
const InvalidType &e ) {
630 s <<
"Route " << field_index <<
" has type "
631 << e.value <<
". Expecting "
Contains the Field class.
This file has been automatically generated from the Util/TypedFieldAnyTmpl.py.
This file has been automatically generated from the Util/TypedFieldTypesTmpl.py.
The Field class.
Definition: Field.h:46
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
H3D_API_EXCEPTION(Vec2dNormalizeError)
H3D API namespace.
Definition: Anchor.h:38
The AnyNumber template can be used in the OptionalArgTypes argument of a TypedField template instanti...
Definition: TypedFieldCheck.h:72
static void checkType(Field *f, int index)
Check that a field is of the correct type.
Definition: TypedFieldCheck.h:89
static void checkTemplateArguments()
Check that the template arguments are on the correct form, i.e.
Definition: TypedFieldCheck.h:77