WorldStateSegment.cpp
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package MemoryX::WorkingMemory
17* @author Thomas von der Heyde (tvh242 at hotmail dot com)
18* @date 2014
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#include "WorldStateSegment.h"
24
25namespace memoryx
26{
29 WorldStateSegmentBase::WorldStateSegmentBase()
30 {
31 }
32
33 ObjectInstanceBasePtr
34 WorldStateSegment::getWorldInstanceById(const ::std::string& id, const ::Ice::Current&) const
35 {
36 ObjectInstanceBasePtr res = ObjectInstanceBasePtr::dynamicCast(getEntityById(id));
37
38 if (!res)
39 {
40 ARMARX_WARNING_S << "Entity with id " << id << " is not of type ObjectInstance!"
41 << std::endl;
42 }
43
44 return res;
45 }
46
47 ObjectInstanceBasePtr
49 const ::Ice::Current&) const
50 {
51 ObjectInstanceBasePtr res = ObjectInstanceBasePtr::dynamicCast(getEntityByName(name));
52
53 if (!res)
54 {
55 ARMARX_WARNING_S << "Entity with name " << name << " is not of type ObjectInstance!"
56 << std::endl;
57 }
58
59 return res;
60 }
61
62 ObjectInstanceList
63 WorldStateSegment::getWorldInstancesByClass(const ::std::string& className,
64 const ::Ice::Current& c) const
65 {
66 NameList classList;
67 classList.push_back(className);
68 return getWorldInstancesByClassList(classList, c);
69 }
70
71 ObjectInstanceList
73 const ::Ice::Current& c) const
74 {
75 ObjectInstanceList result;
77
78 for (IdEntityMap::const_iterator it = entityMap.begin(); it != entityMap.end(); ++it)
79 {
80 ObjectInstanceBasePtr inst = ObjectInstanceBasePtr::dynamicCast(it->second);
81 ClassProbabilityMap instClasses = inst->getClasses();
82
83 for (NameList::const_iterator itCls = classList.begin(); itCls != classList.end();
84 ++itCls)
85 {
86 if (instClasses.count(*itCls))
87 {
88 result.push_back(inst);
89 break;
90 }
91 }
92 }
93
94 return result;
95 }
96} // namespace memoryx
constexpr T c
std::unique_ptr< ScopedSharedLock > ScopedSharedLockPtr
ScopedSharedLockPtr getReadLock(const Ice::Current &c) const
EntityBasePtr getEntityByName(const ::std::string &name) const
EntityBasePtr getEntityById(const ::std::string &id) const
ObjectInstanceList getWorldInstancesByClass(const ::std::string &className, const ::Ice::Current &c=Ice::emptyCurrent) const override
ObjectInstanceList getWorldInstancesByClassList(const NameList &classList, const ::Ice::Current &=Ice::emptyCurrent) const override
ObjectInstanceBasePtr getWorldInstanceByName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) const override
ObjectInstanceBasePtr getWorldInstanceById(const ::std::string &id, const ::Ice::Current &=Ice::emptyCurrent) const override
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:213
VirtualRobot headers.