AbstractEntityWrapper.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 ALexey Kozlov ( kozlov 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 <MemoryX/interface/core/EntityBase.h>
26 #include <MemoryX/interface/memorytypes/MemoryEntities.h>
27 #include <memory>
28 
29 namespace memoryx
30 {
31  class GridFileManager;
32  using GridFileManagerPtr = std::shared_ptr<GridFileManager>;
33 }
34 
36 {
37 
38  /**
39  * AbstractEntityWrapper is a superclass for all covenience classes, which provide typed access to entity attributes.
40  * See memoryx::EntityWrappers::SimoxObjectWrapper for sample implementation.
41  *
42  * Apart of convenience, such wrapper classes give a maintance advantage, since they encapsulate all
43  * the implementation details (attribute names, storing formats), avoiding the need to duplicate them
44  * in multiple places in client code. So it's recommended to use this approach whenever possible.
45  *
46  */
48  public AbstractEntityWrapperBase
49  {
50  public:
52  ~AbstractEntityWrapper() override;
53 
54  /**
55  * Get the identifier of the stored entity.
56  */
57  std::string getId() const;
58 
59  /**
60  * Get the name of the stored entity.
61  */
62  std::string getName() const;
63 
64  /**
65  * Get the stored name of the stored entity.
66  */
67  EntityBasePtr getEntity() const;
68 
69  /**
70  * Replace the stored entity with a new one
71  *
72  * @param entity entity to set
73  */
74  // void setEntity(EntityBase* entity);
75  void setEntity(const EntityBasePtr& entity);
76  private:
77  EntityBasePtr entity;
78  };
79 
80 
81 
84  {
85  public:
87  protected:
88  /**
89  * @brief cleanUpAttributeFiles compares the files attached to the two
90  * given attributes and removes the files of the oldAttr, if they dont
91  * match. Thus, this function should only be called with attributes of
92  * the same kind (e.g. Attribute for texture files).
93  * If multiple files are attached to that attribute, they must appear
94  * in the same order.
95  * @param oldAttr
96  * @param newAttr
97  */
98  void cleanUpAttributeFiles(EntityAttributeBasePtr oldAttr, EntityAttributeBasePtr newAttr);
99  /**
100  * @brief removes all files of an attribute from the gridfs
101  * @param attr
102  */
103  void removeAttributeFiles(const memoryx::EntityAttributeBasePtr& attr);
104  std::string cacheAttributeFile(const std::string& attrName, bool preserveOriginalFName = false) const;
105 
107  };
108 
109  /**
110  * Typedef of AbstractEntityWrapperPtr as IceUtil::Handle<AbstractEntityWrapper> for convenience.
111  */
113 
114 }
memoryx::EntityWrappers::AbstractFileEntityWrapper::removeAttributeFiles
void removeAttributeFiles(const memoryx::EntityAttributeBasePtr &attr)
removes all files of an attribute from the gridfs
Definition: AbstractEntityWrapper.cpp:102
memoryx::EntityWrappers::AbstractFileEntityWrapper::cleanUpAttributeFiles
void cleanUpAttributeFiles(EntityAttributeBasePtr oldAttr, EntityAttributeBasePtr newAttr)
cleanUpAttributeFiles compares the files attached to the two given attributes and removes the files o...
Definition: AbstractEntityWrapper.cpp:64
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::EntityWrappers::AbstractEntityWrapper::getEntity
EntityBasePtr getEntity() const
Get the stored name of the stored entity.
Definition: AbstractEntityWrapper.cpp:49
memoryx::EntityWrappers::AbstractEntityWrapper::AbstractEntityWrapper
AbstractEntityWrapper()
Definition: AbstractEntityWrapper.cpp:30
memoryx::EntityWrappers::AbstractEntityWrapper
AbstractEntityWrapper is a superclass for all covenience classes, which provide typed access to entit...
Definition: AbstractEntityWrapper.h:47
IceInternal::Handle
Definition: forward_declarations.h:8
memoryx::EntityWrappers::AbstractEntityWrapper::~AbstractEntityWrapper
~AbstractEntityWrapper() override
Definition: AbstractEntityWrapper.cpp:35
memoryx::EntityWrappers::AbstractFileEntityWrapper
Definition: AbstractEntityWrapper.h:82
memoryx::EntityWrappers::AbstractEntityWrapper::getName
std::string getName() const
Get the name of the stored entity.
Definition: AbstractEntityWrapper.cpp:44
memoryx::EntityWrappers::AbstractFileEntityWrapper::cacheAttributeFile
std::string cacheAttributeFile(const std::string &attrName, bool preserveOriginalFName=false) const
Definition: AbstractEntityWrapper.cpp:129
memoryx::EntityWrappers
Definition: AbstractEntityWrapper.cpp:28
memoryx::EntityWrappers::AbstractEntityWrapper::setEntity
void setEntity(const EntityBasePtr &entity)
Replace the stored entity with a new one.
Definition: AbstractEntityWrapper.cpp:54
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:32
memoryx::EntityWrappers::AbstractEntityWrapper::getId
std::string getId() const
Get the identifier of the stored entity.
Definition: AbstractEntityWrapper.cpp:39
memoryx::EntityWrappers::AbstractFileEntityWrapper::AbstractFileEntityWrapper
AbstractFileEntityWrapper(GridFileManagerPtr fileManager)
Definition: AbstractEntityWrapper.cpp:142
memoryx::EntityWrappers::AbstractFileEntityWrapper::fileManager
GridFileManagerPtr fileManager
Definition: AbstractEntityWrapper.h:106