OacMemorySegment.h
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 Kai Welke ( welke at kit dot edu)
18 * @date 2012
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #pragma once
24 
25 #include <vector>
26 
28 
31 #include <MemoryX/interface/core/EntityBase.h>
32 #include <MemoryX/interface/memorytypes/MemoryEntities.h>
33 #include <MemoryX/interface/memorytypes/MemorySegments.h>
35 
36 namespace memoryx
37 {
39  virtual public PersistentEntitySegment,
40  virtual public OacMemorySegmentBase
41  {
42  public:
43  OacMemorySegment(PersistentObjectClassSegmentBasePrx objClassSegment,
44  CollectionInterfacePrx entityCollection,
46  bool useMongoIds = true) :
47  PersistentEntitySegment(entityCollection, ic, useMongoIds),
48  OacMemorySegmentBase(),
49  objClassSegment(objClassSegment)
50  {
51  }
52 
53  OacBasePtr
54  getOacById(const ::std::string& id,
55  const ::Ice::Current& = Ice::emptyCurrent) const override
56  {
57  return completeOac(OacBasePtr::dynamicCast(getEntityById(id)));
58  }
59 
60  OacBasePtr
61  getOacByName(const ::std::string& name,
62  const ::Ice::Current& = Ice::emptyCurrent) const override
63  {
64  return completeOac(OacBasePtr::dynamicCast(getEntityByName(name)));
65  }
66 
67  OacBaseList
68  getAll(const ::Ice::Current& = Ice::emptyCurrent) const override
69  {
70  OacBaseList result;
71 
72  EntityIdList entityIdList = getAllEntityIds();
73 
74  for (EntityIdList::const_iterator it = entityIdList.begin(); it != entityIdList.end();
75  ++it)
76  {
77  OacBasePtr oac = getOacById(*it);
78 
79  if (oac)
80  {
81  result.push_back(oac);
82  }
83  }
84 
85  return result;
86  }
87 
88  protected:
89  /*!
90  * \brief replaceObjectDummies checks the objects class in the SEC part of an OAC
91  * and completes it with the real object class entities from the
92  * PersistentObjectClassSegment.
93  * \param oac OAC in which the object should be replaced
94  * \return Returns same instance as the parameter oac for convenience.
95  */
96  OacBasePtr replaceObjectDummies(OacBasePtr oac) const;
97 
98  /*!
99  * \brief completeOac checks the data of an OAC and completes it with
100  * data from other segments (e.g: object with only the name are fetched
101  * from the PersistentObjectClassSegment.
102  * \param oac OAC that should be completed.
103  * \return Returns same instance as the parameter oac for convenience.
104  */
105  OacBasePtr completeOac(OacBasePtr oac) const;
106  PersistentObjectClassSegmentBasePrx objClassSegment;
107  };
108 
110 
111  OacBasePtr
112  OacMemorySegment::completeOac(OacBasePtr oac) const
113  {
114  return replaceObjectDummies(oac);
115  }
116 
117  OacBasePtr
118  OacMemorySegment::replaceObjectDummies(OacBasePtr oac) const
119  {
120  if (!oac)
121  {
122  return NULL;
123  }
124 
125  OacPtr oacCast = OacPtr::dynamicCast(oac);
126 
127  if (!oacCast)
128  {
129  throw IceUtil::NullHandleException("Could not cast OacBase into Oac Ptr", 0);
130  }
131 
132  if (!objClassSegment)
133  {
134  throw armarx::LocalException("PersistentObjectClassSegmentBaseProxy is NULL");
135  }
136 
137  SECObjectRelationsBasePtr pre = oacCast->getPredictionFunction()->getSECPreconditions();
138  SECObjectRelationsBasePtr post = oacCast->getPredictionFunction()->getSECEffects();
139 
140  if (pre)
141  {
143  }
144 
145  if (post)
146  {
148  }
149 
150  return oacCast;
151  }
152 
153 } // namespace memoryx
cyberglove_with_calib_22dof.ic
ic
Definition: cyberglove_with_calib_22dof.py:22
memoryx::OacMemorySegment::getAll
OacBaseList getAll(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: OacMemorySegment.h:68
memoryx::OacMemorySegment::getOacByName
OacBasePtr getOacByName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: OacMemorySegment.h:61
memoryx::OacMemorySegment::OacMemorySegment
OacMemorySegment(PersistentObjectClassSegmentBasePrx objClassSegment, CollectionInterfacePrx entityCollection, Ice::CommunicatorPtr ic, bool useMongoIds=true)
Definition: OacMemorySegment.h:43
Oac.h
SemanticEventChainSegment.h
memoryx::OacMemorySegment
Definition: OacMemorySegment.h:38
memoryx::OacMemorySegment::replaceObjectDummies
OacBasePtr replaceObjectDummies(OacBasePtr oac) const
replaceObjectDummies checks the objects class in the SEC part of an OAC and completes it with the rea...
Definition: BodySchemaMemorySegment.h:113
PersistentEntitySegment.h
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::OacPtr
IceInternal::Handle< Oac > OacPtr
Definition: Oac.h:39
IceInternal::Handle<::Ice::Communicator >
memoryx::SemanticEventChainSegment::ReplaceObjectDummies
static void ReplaceObjectDummies(SECObjectRelationsBasePtr objRelations, PersistentObjectClassSegmentBasePrx objClassSegment)
Definition: SemanticEventChainSegment.cpp:41
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
memoryx::OacMemorySegment::completeOac
OacBasePtr completeOac(OacBasePtr oac) const
completeOac checks the data of an OAC and completes it with data from other segments (e....
Definition: BodySchemaMemorySegment.h:107
memoryx::OacMemorySegment::objClassSegment
PersistentObjectClassSegmentBasePrx objClassSegment
Definition: OacMemorySegment.h:106
memoryx::PersistentEntitySegment
The PersistentEntitySegment class is the base class for all memory segments containing memoryx::Entit...
Definition: PersistentEntitySegment.h:105
memoryx::OacMemorySegment::getOacById
OacBasePtr getOacById(const ::std::string &id, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: OacMemorySegment.h:54
ImportExportComponent.h