-
Notifications
You must be signed in to change notification settings - Fork 0
/
AttributeCreator.cpp
101 lines (91 loc) · 3.07 KB
/
AttributeCreator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* @file AttributeCreator.cpp
* @author Dan R. Lipsa
*
* Member definitions for classes that know how to create various
* kinds of attributes which can be attached to vertices, edges, faces
* and bodies.
*/
#include "AttributeCreator.h"
#include "Attribute.h"
#include "Debug.h"
Attribute* IntegerAttributeCreator::operator() (
const EvolverData::parser::semantic_type& value,
AttributeType::Enum type) const
{
RuntimeAssert (type == AttributeType::INT,
"Attribute declared with INTEGER type has value of type ",
type);
return new IntegerAttribute (value.m_int);
}
// ======================================================================
Attribute* ColorAttributeCreator::operator() (
const EvolverData::parser::semantic_type& value,
AttributeType::Enum type) const
{
RuntimeAssert (type == AttributeType::COLOR,
"Attribute declared with INTEGER type has value of type ",
type);
return new ColorAttribute (value.m_color);
}
// ======================================================================
Attribute* RealAttributeCreator::operator() (
const EvolverData::parser::semantic_type& value,
AttributeType::Enum type) const
{
switch (type)
{
case AttributeType::REAL:
return new RealAttribute (value.m_real);
case AttributeType::INT:
return new RealAttribute (value.m_int);
default:
RuntimeAssert (false,
"Attribute declared with REAL type has value of type ",
type);
return 0;
}
}
// ======================================================================
Attribute* IntegerArrayAttributeCreator::operator() (
const EvolverData::parser::semantic_type& value,
AttributeType::Enum type) const
{
RuntimeAssert (
type == AttributeType::INT_ARRAY,
"Attribute declared with INTEGER_ARRAY type has value of type ",
type);
RuntimeAssert (
value.m_intList->size () == m_size,
"Declared size of integer array attribute differs "
"from size of the attribute value: ",
m_size, " != ", value.m_intList->size());
return new IntegerArrayAttribute (value.m_intList);
}
// ======================================================================
Attribute* IntegerVectorAttributeCreator::operator() (
const EvolverData::parser::semantic_type& value,
AttributeType::Enum type) const
{
RuntimeAssert (
type == AttributeType::INT_ARRAY,
"Attribute declared with INTEGER_ARRAY type has value of type ",
type);
return new IntegerArrayAttribute (value.m_intList);
}
// ======================================================================
Attribute* RealArrayAttributeCreator::operator() (
const EvolverData::parser::semantic_type& value,
AttributeType::Enum type) const
{
RuntimeAssert (
type == AttributeType::REAL_ARRAY,
"Attribute declared with REAL_ARRAY type "
"has value of type ", type);
RuntimeAssert (
value.m_realList->size () == m_size,
"Declared size of integer array attribute differs "
"from size of the attribute value: ", m_size, " != ",
value.m_realList->size());
return new RealArrayAttribute (value.m_realList);
}