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 
25 namespace memoryx
26 {
29  WorldStateSegmentBase::WorldStateSegmentBase()
30  {
31 
32  }
33 
34  ObjectInstanceBasePtr 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!" << std::endl;
41  }
42 
43  return res;
44  }
45 
46  ObjectInstanceBasePtr WorldStateSegment::getWorldInstanceByName(const ::std::string& name, const ::Ice::Current&) const
47  {
48  ObjectInstanceBasePtr res = ObjectInstanceBasePtr::dynamicCast(getEntityByName(name));
49 
50  if (!res)
51  {
52  ARMARX_WARNING_S << "Entity with name " << name << " is not of type ObjectInstance!" << std::endl;
53  }
54 
55  return res;
56  }
57 
58  ObjectInstanceList WorldStateSegment::getWorldInstancesByClass(const ::std::string& className, const ::Ice::Current& c) const
59  {
60  NameList classList;
61  classList.push_back(className);
62  return getWorldInstancesByClassList(classList, c);
63  }
64 
65  ObjectInstanceList WorldStateSegment::getWorldInstancesByClassList(const NameList& classList, const ::Ice::Current& c) const
66  {
67  ObjectInstanceList result;
69 
70  for (IdEntityMap::const_iterator it = entityMap.begin(); it != entityMap.end(); ++it)
71  {
72  ObjectInstanceBasePtr inst = ObjectInstanceBasePtr::dynamicCast(it->second);
73  ClassProbabilityMap instClasses = inst->getClasses();
74 
75  for (NameList::const_iterator itCls = classList.begin(); itCls != classList.end(); ++itCls)
76  {
77  if (instClasses.count(*itCls))
78  {
79  result.push_back(inst);
80  break;
81  }
82  }
83  }
84 
85  return result;
86  }
87 }
memoryx::WorkingMemoryEntitySegment< ObjectInstance >::getEntityByName
EntityBasePtr getEntityByName(const ::std::string &name) const
Definition: WorkingMemoryEntitySegment.h:451
memoryx::SegmentUtilImplementations::getReadLock
ScopedSharedLockPtr getReadLock(const Ice::Current &c) const
Definition: SegmentUtilImplementations.cpp:45
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
WorldStateSegment.h
memoryx::ObjectInstance
Definition: ObjectInstance.h:47
memoryx::WorldStateSegment::getWorldInstanceByName
ObjectInstanceBasePtr getWorldInstanceByName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: WorldStateSegment.cpp:46
memoryx::WorldStateSegment::WorldStateSegment
WorldStateSegment()
Definition: WorldStateSegment.cpp:27
memoryx::WorkingMemoryEntitySegment< ObjectInstance >::entityMap
IdEntityMap entityMap
Definition: WorkingMemoryEntitySegment.h:637
memoryx::WorkingMemoryEntitySegment
Definition: WorkingMemoryEntitySegment.h:44
memoryx::WorldStateSegment::getWorldInstancesByClassList
ObjectInstanceList getWorldInstancesByClassList(const NameList &classList, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: WorldStateSegment.cpp:65
memoryx::WorldStateSegment::getWorldInstanceById
ObjectInstanceBasePtr getWorldInstanceById(const ::std::string &id, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: WorldStateSegment.cpp:34
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:206
memoryx::WorldStateSegment::getWorldInstancesByClass
ObjectInstanceList getWorldInstancesByClass(const ::std::string &className, const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: WorldStateSegment.cpp:58
memoryx::WorkingMemoryEntitySegment< ObjectInstance >::getEntityById
EntityBasePtr getEntityById(const ::std::string &id) const
Definition: WorkingMemoryEntitySegment.h:427
memoryx::SegmentUtilImplementations::ScopedSharedLockPtr
std::unique_ptr< ScopedSharedLock > ScopedSharedLockPtr
Definition: SegmentUtilImplementations.h:62