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  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
48  WorldStateSegment::getWorldInstanceByName(const ::std::string& name,
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
memoryx::WorkingMemoryEntitySegment< ObjectInstance >::getEntityByName
EntityBasePtr getEntityByName(const ::std::string &name) const
Definition: WorkingMemoryEntitySegment.h:489
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:46
WorldStateSegment.h
memoryx::ObjectInstance
Definition: ObjectInstance.h:48
memoryx::WorldStateSegment::getWorldInstanceByName
ObjectInstanceBasePtr getWorldInstanceByName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: WorldStateSegment.cpp:48
memoryx::WorldStateSegment::WorldStateSegment
WorldStateSegment()
Definition: WorldStateSegment.cpp:27
memoryx::WorkingMemoryEntitySegment< ObjectInstance >::entityMap
IdEntityMap entityMap
Definition: WorkingMemoryEntitySegment.h:698
memoryx::WorkingMemoryEntitySegment
Definition: WorkingMemoryEntitySegment.h:45
memoryx::WorldStateSegment::getWorldInstancesByClassList
ObjectInstanceList getWorldInstancesByClassList(const NameList &classList, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: WorldStateSegment.cpp:72
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:213
memoryx::WorldStateSegment::getWorldInstancesByClass
ObjectInstanceList getWorldInstancesByClass(const ::std::string &className, const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: WorldStateSegment.cpp:63
memoryx::WorkingMemoryEntitySegment< ObjectInstance >::getEntityById
EntityBasePtr getEntityById(const ::std::string &id) const
Definition: WorkingMemoryEntitySegment.h:463
memoryx::SegmentUtilImplementations::ScopedSharedLockPtr
std::unique_ptr< ScopedSharedLock > ScopedSharedLockPtr
Definition: SegmentUtilImplementations.h:66