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>
26
28
30
31namespace memoryx
32{
33 /**
34 * @class AttributeReplacementFusion
35 * @ingroup WorkingMemory
36 */
38 {
39 public:
40 /**
41 * Creates a new AttributeEnrichementFusion
42 */
43 AttributeReplacementFusion() : 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
56 fuseEntity(const EntityBasePtr& baseEntity,
57 const EntityBasePtr& updateEntity,
58 const ::Ice::Current&) override
59 {
60 ARMARX_DEBUG_S << "AttributeReplacementFusion::fuseEntity() called";
61
62 // do we really need to clone ??
63 EntityBasePtr fusedEntity = EntityBasePtr::dynamicCast(baseEntity->ice_clone());
64 addAttributesWithReplacement(updateEntity, fusedEntity);
65
66 return fusedEntity;
67 }
68
69 private:
70 void
71 addAttributesWithReplacement(const EntityBasePtr& srcEntity,
72 const EntityBasePtr& destEntity) const
73 {
74 NameList attrNames = srcEntity->getAttributeNames();
75
76 for (NameList::const_iterator it = attrNames.begin(); it != attrNames.end(); ++it)
77 {
78 destEntity->putAttribute(srcEntity->getAttribute(*it));
79 }
80 }
81 };
82} // namespace memoryx
#define ARMARXCORE_IMPORT_EXPORT
EntityBasePtr fuseEntity(const EntityBasePtr &baseEntity, const EntityBasePtr &updateEntity, const ::Ice::Current &) override
Copies attributes from the update entity to the stored entity.
AttributeReplacementFusion()
Creates a new AttributeEnrichementFusion.
EntityFusionMethod(std::string methodName)
Constructs a new fusion method.
#define ARMARX_DEBUG_S
The logging level for output that is only interesting while debugging.
Definition Logging.h:205
VirtualRobot headers.