Fawkes API Fawkes Development Version
predicate.cpp
1
2/***************************************************************************
3 * predicate.cpp - stn-generator
4 *
5 * Created: Sat May 6 20:16:21 2017
6 * Copyright 2017 Matthias Loebach
7 ****************************************************************************/
8
9/* This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Library General Public License for more details.
18 *
19 * Read the full text in the LICENSE.GPL file in the doc directory.
20 */
21
22#include "predicate.h"
23
24namespace fawkes {
25namespace stn {
26
27/** @class Predicate "predicate.h"
28 * A representation of a Predicate in the STN.
29 */
30
31/** Constructor.
32 * @param name The name of the predicate.
33 * @param condition False iff this predicate is negated.
34 * @param attrs Parameters of the predicate.
35 */
36Predicate::Predicate(const std::string &name, bool condition, const std::vector<std::string> &attrs)
37: name_(name), condition_(condition), attrs_(attrs)
38{
39}
40
41/** Print a Predicate.
42 * This prints all relevant information about the predicate.
43 * @param strm The stream to pass the information to.
44 * @param a The predicate to show.
45 */
46std::ostream &
47operator<<(std::ostream &strm, const Predicate &a)
48{
49 strm << "\t" << a.name_ << "," << a.condition_;
50 for (std::string s : a.attrs_) {
51 strm << "," << s;
52 }
53 strm << std::endl;
54
55 return strm;
56}
57
58/** Compare two Predicates.
59 * @param rhs The other predicatge.
60 * @return True iff the two predicates have the same properties.
61 */
62bool
64{
65 return ((name_ == rhs.name_) && (condition_ == rhs.condition_) && (attrs_ == rhs.attrs_));
66}
67
68/** Get the name of the predicate.
69 * @return The name of the predicate.
70 */
71std::string
73{
74 return name_;
75}
76
77/** Get the condition of the predicate.
78 * @return True iff the predicate's condition is true.
79 */
80bool
82{
83 return condition_;
84}
85
86/** Get the attributes of the predicate.
87 * @return A vector of attributes as strings.
88 */
89const std::vector<std::string> &
91{
92 return attrs_;
93}
94} // namespace stn
95} // namespace fawkes
A representation of a Predicate in the STN.
Definition: predicate.h:33
Predicate(const std::string &name, bool condition, const std::vector< std::string > &attrs)
Constructor.
Definition: predicate.cpp:36
bool condition() const
Get the condition of the predicate.
Definition: predicate.cpp:81
const std::vector< std::string > & attrs() const
Get the attributes of the predicate.
Definition: predicate.cpp:90
std::string name() const
Get the name of the predicate.
Definition: predicate.cpp:72
bool operator==(const Predicate &rhs)
Compare two Predicates.
Definition: predicate.cpp:63
Fawkes library namespace.