Skip to content

Commit 78908bd

Browse files
committed
move method definitions
1 parent 2df11a0 commit 78908bd

File tree

2 files changed

+59
-43
lines changed

2 files changed

+59
-43
lines changed

include/behaviortree_cpp/blackboard.h

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -65,42 +65,17 @@ class Blackboard
6565

6666
[[nodiscard]] const Entry* getEntry(const std::string& key) const;
6767

68-
[[nodiscard]] Entry* getEntry(const std::string& key)
69-
{
70-
// "Avoid Duplication in const and Non-const Member Function,"
71-
// on p. 23, in Item 3 "Use const whenever possible," in Effective C++, 3d ed
72-
return const_cast<Entry*>( static_cast<const Blackboard &>(*this).getEntry(key));
73-
}
68+
[[nodiscard]] Entry* getEntry(const std::string& key);
7469

75-
[[nodiscard]] AnyPtrLocked getAnyLocked(const std::string& key)
76-
{
77-
if(auto entry = getEntry(key))
78-
{
79-
return AnyPtrLocked(&entry->value, &entry->entry_mutex);
80-
}
81-
return {};
82-
}
70+
[[nodiscard]] AnyPtrLocked getAnyLocked(const std::string& key);
8371

84-
[[nodiscard]] AnyPtrLocked getAnyLocked(const std::string& key) const
85-
{
86-
if(auto entry = getEntry(key))
87-
{
88-
return AnyPtrLocked(&entry->value, const_cast<std::mutex*>(&entry->entry_mutex));
89-
}
90-
return {};
91-
}
72+
[[nodiscard]] AnyPtrLocked getAnyLocked(const std::string& key) const;
9273

9374
[[deprecated("Use getAnyLocked instead")]]
94-
const Any* getAny(const std::string& key) const
95-
{
96-
return getAnyLocked(key).get();
97-
}
75+
const Any* getAny(const std::string& key) const;
9876

9977
[[deprecated("Use getAnyLocked instead")]]
100-
Any* getAny(const std::string& key)
101-
{
102-
return const_cast<Any*>(getAnyLocked(key).get());
103-
}
78+
Any* getAny(const std::string& key);
10479

10580
/** Return true if the entry with the given key was found.
10681
* Note that this method may throw an exception if the cast to T failed.
@@ -218,22 +193,12 @@ class Blackboard
218193

219194
[[nodiscard]] std::vector<StringView> getKeys() const;
220195

221-
void clear()
222-
{
223-
std::unique_lock<std::mutex> lock(mutex_);
224-
storage_.clear();
225-
}
196+
void clear();
226197

227198
[[deprecated("Use getAnyLocked to access safely an Entry")]]
228-
std::recursive_mutex& entryMutex() const
229-
{
230-
return entry_mutex_;
231-
}
199+
std::recursive_mutex& entryMutex() const;
232200

233-
void createEntry(const std::string& key, const PortInfo& info)
234-
{
235-
createEntryImpl(key, info);
236-
}
201+
void createEntry(const std::string& key, const PortInfo& info);
237202

238203
private:
239204
mutable std::mutex mutex_;

src/blackboard.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,41 @@ void Blackboard::enableAutoRemapping(bool remapping)
88
autoremapping_ = remapping;
99
}
1010

11+
Blackboard::Entry *Blackboard::getEntry(const std::string &key)
12+
{
13+
// "Avoid Duplication in const and Non-const Member Function,"
14+
// on p. 23, in Item 3 "Use const whenever possible," in Effective C++, 3d ed
15+
return const_cast<Entry*>( static_cast<const Blackboard &>(*this).getEntry(key));
16+
}
17+
18+
AnyPtrLocked Blackboard::getAnyLocked(const std::string &key)
19+
{
20+
if(auto entry = getEntry(key))
21+
{
22+
return AnyPtrLocked(&entry->value, &entry->entry_mutex);
23+
}
24+
return {};
25+
}
26+
27+
AnyPtrLocked Blackboard::getAnyLocked(const std::string &key) const
28+
{
29+
if(auto entry = getEntry(key))
30+
{
31+
return AnyPtrLocked(&entry->value, const_cast<std::mutex*>(&entry->entry_mutex));
32+
}
33+
return {};
34+
}
35+
36+
const Any *Blackboard::getAny(const std::string &key) const
37+
{
38+
return getAnyLocked(key).get();
39+
}
40+
41+
Any *Blackboard::getAny(const std::string &key)
42+
{
43+
return const_cast<Any*>(getAnyLocked(key).get());
44+
}
45+
1146
const Blackboard::Entry *Blackboard::getEntry(const std::string &key) const
1247
{
1348
std::unique_lock<std::mutex> lock(mutex_);
@@ -65,6 +100,22 @@ std::vector<StringView> Blackboard::getKeys() const
65100
return out;
66101
}
67102

103+
void Blackboard::clear()
104+
{
105+
std::unique_lock<std::mutex> lock(mutex_);
106+
storage_.clear();
107+
}
108+
109+
std::recursive_mutex &Blackboard::entryMutex() const
110+
{
111+
return entry_mutex_;
112+
}
113+
114+
void Blackboard::createEntry(const std::string &key, const PortInfo &info)
115+
{
116+
createEntryImpl(key, info);
117+
}
118+
68119
std::shared_ptr<Blackboard::Entry>
69120
Blackboard::createEntryImpl(const std::string& key, const PortInfo& info)
70121
{

0 commit comments

Comments
 (0)