-
Notifications
You must be signed in to change notification settings - Fork 5
/
domains.cc
109 lines (88 loc) · 3.12 KB
/
domains.cc
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
/*
* Copyright 2003-2005 Carnegie Mellon University and Rutgers University
* Copyright 2007 Håkan Younes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "domains.h"
/* ====================================================================== */
/* Domain */
/* Table of defined domains. */
Domain::DomainMap Domain::domains = Domain::DomainMap();
/* Returns a const_iterator pointing to the first domain. */
Domain::DomainMap::const_iterator Domain::begin() {
return domains.begin();
}
/* Returns a const_iterator pointing beyond the last domain. */
Domain::DomainMap::const_iterator Domain::end() {
return domains.end();
}
/* Returns a pointer to the domain with the given name, or 0 if it
is undefined. */
const Domain* Domain::find(const std::string& name) {
DomainMap::const_iterator di = domains.find(name);
return (di != domains.end()) ? (*di).second : 0;
}
/* Removes all defined domains. */
void Domain::clear() {
DomainMap::const_iterator di = begin();
while (di != end()) {
delete (*di).second;
di = begin();
}
domains.clear();
}
/* Constructs an empty domain with the given name. */
Domain::Domain(const std::string& name)
: name_(name), total_time_(functions_.add_function("total-time")),
goal_achieved_(functions_.add_function("goal-achieved")) {
const Domain* d = find(name);
if (d != 0) {
delete d;
}
domains[name] = this;
FunctionTable::make_dynamic(total_time_);
FunctionTable::make_dynamic(goal_achieved_);
}
/* Deletes a domain. */
Domain::~Domain() {
domains.erase(name());
for (ActionSchemaMap::const_iterator ai = actions().begin();
ai != actions().end(); ai++) {
delete (*ai).second;
}
}
/* Adds the given action to this domain. */
void Domain::add_action(const ActionSchema& action) {
actions_.insert(std::make_pair(action.name(), &action));
}
/* Returns a pointer to the action with the given name, or 0 if
there is no action with the given name. */
const ActionSchema* Domain::find_action(const std::string& name) const {
ActionSchemaMap::const_iterator ai = actions_.find(name);
return (ai != actions_.end()) ? (*ai).second : 0;
}
/* Output operator for domains. */
std::ostream& operator<<(std::ostream& os, const Domain& d) {
os << "name: " << d.name();
os << std::endl << "types:" << d.types();
os << std::endl << "constants:" << d.terms();
os << std::endl << "predicates:" << d.predicates();
os << std::endl << "functions:" << d.functions();
os << std::endl << "actions:";
for (ActionSchemaMap::const_iterator ai = d.actions().begin();
ai != d.actions().end(); ai++) {
os << std::endl << *(*ai).second;
}
return os;
}