AttributeReplacementFusion.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::Core
17 * @author Kai Welke <welke@kit.edu>
18 * @copyright 2012 Kai Welke
19 * @license http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #pragma once
24 
25 #include <string>
28 
29 namespace memoryx
30 {
31  /**
32  * @class AttributeReplacementFusion
33  * @ingroup WorkingMemory
34  */
36  virtual public EntityFusionMethod
37  {
38  public:
39  /**
40  * Creates a new AttributeEnrichementFusion
41  */
43  EntityFusionMethod("AttributeReplacementFusion")
44  {
45  }
46 
47  /**
48  * Copies attributes from the update entity to the stored entity. Replaces existing attributes and adds those which have not been present so far.
49  *
50  * @param baseEntity base entity for fusion
51  * @param updateEntity entity to be fused with base entity
52  *
53  * @return fused entity
54  */
55  EntityBasePtr fuseEntity(const EntityBasePtr& baseEntity, const EntityBasePtr& updateEntity, const ::Ice::Current&) override
56  {
57  ARMARX_DEBUG_S << "AttributeReplacementFusion::fuseEntity() called";
58 
59  // do we really need to clone ??
60  EntityBasePtr fusedEntity = EntityBasePtr::dynamicCast(baseEntity->ice_clone());
61  addAttributesWithReplacement(updateEntity, fusedEntity);
62 
63  return fusedEntity;
64  }
65 
66  private:
67  void addAttributesWithReplacement(const EntityBasePtr& srcEntity, const EntityBasePtr& destEntity) const
68  {
69  NameList attrNames = srcEntity->getAttributeNames();
70 
71  for (NameList::const_iterator it = attrNames.begin(); it != attrNames.end(); ++it)
72  {
73  destEntity->putAttribute(srcEntity->getAttribute(*it));
74  }
75  }
76  };
77 }
78 
memoryx::AttributeReplacementFusion::fuseEntity
EntityBasePtr fuseEntity(const EntityBasePtr &baseEntity, const EntityBasePtr &updateEntity, const ::Ice::Current &) override
Copies attributes from the update entity to the stored entity.
Definition: AttributeReplacementFusion.h:55
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::EntityFusionMethod
Interface for fusion methods used for entities in working memory.
Definition: EntityFusionMethod.h:43
memoryx::AttributeReplacementFusion
Definition: AttributeReplacementFusion.h:35
ARMARX_DEBUG_S
#define ARMARX_DEBUG_S
Definition: Logging.h:198
memoryx::AttributeReplacementFusion::AttributeReplacementFusion
AttributeReplacementFusion()
Creates a new AttributeEnrichementFusion.
Definition: AttributeReplacementFusion.h:42
ImportExport.h
ARMARXCORE_IMPORT_EXPORT
#define ARMARXCORE_IMPORT_EXPORT
Definition: ImportExport.h:38
EntityFusionMethod.h