forked from perabrahamsen/daisy-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattribute.C
executable file
·136 lines (120 loc) · 3 KB
/
attribute.C
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// attribute.C - A type system for attributes.
//
// Copyright 1996-2001 Per Abrahamsen and Søren Hansen
// Copyright 2000-2001 KVL.
// Copyright 2008 Per Abrahamsen and KVL.
//
// This file is part of Daisy.
//
// Daisy is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// Daisy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser Public License for more details.
//
// You should have received a copy of the GNU Lesser Public License
// along with Daisy; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#define BUILD_DLL
#include "attribute.h"
#include "assertion.h"
#include <sstream>
symbol
Attribute::size_name (const int size)
{
switch (size)
{
case Singleton:
return "singleton";
case Variable:
return "variable";
case CanopyCells:
return "canopy cells";
case CanopyEdges:
return "canopy edges";
case SoilCells:
return "soil cells";
case SoilEdges:
return "soil edges";
case Unspecified:
return "unspecified";
}
std::ostringstream tmp;
tmp << "[" << size << "]";
return tmp.str ();
}
// Each attribute should have an associated type.
symbol
Attribute::type_name (type t)
{
static const symbol names[] =
{ "Number", "Submodel", "PLF", "Boolean", "String",
"Integer", "Model", "Scalar", "Reference", "Error" };
daisy_assert (t >= 0);
daisy_assert (t < sizeof (names) / sizeof (symbol));
return names[t];
}
static Attribute::type operator++ (Attribute::type& t)
{
t = static_cast<Attribute::type> (static_cast<int> (t) + 1);
return t;
}
Attribute::type
Attribute::type_number (const symbol name)
{
for (type i = Number; i != Error; ++i)
if (name == type_name (i))
return i;
return Error;
}
symbol
Attribute::Unknown ()
{
static const symbol unknown ("<unknown>");
return unknown;
}
symbol
Attribute::None ()
{
static const symbol unit ("<none>");
return unit;
}
symbol
Attribute::Fraction ()
{
static const symbol unit ("<fraction>");
return unit;
}
symbol
Attribute::User ()
{
static const symbol unit ("<user>");
return unit;
}
symbol
Attribute::category_name (category c)
{
static const symbol names[] =
{ "Const", "State", "OptionalState", "OptionalConst", "LogOnly"};
daisy_assert (c >= 0);
daisy_assert (c < sizeof (names) / sizeof (symbol));
return names[c];
}
int
Attribute::category_number (const symbol name)
{
static const symbol category_end ("LogOnly");
for (int i = 0;; i++)
{
const symbol entry = category_name (category (i));
if (name == entry)
return i;
else if (entry == category_end)
return -1;
}
}
// attribute.C ends her.