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 <memory>
26
27#include <MemoryX/interface/core/EntityBase.h>
28#include <MemoryX/interface/memorytypes/MemoryEntities.h>
29
30namespace memoryx
31{
32 class GridFileManager;
33 using GridFileManagerPtr = std::shared_ptr<GridFileManager>;
34} // namespace memoryx
35
37{
38
39 /**
40 * AbstractEntityWrapper is a superclass for all covenience classes, which provide typed access to entity attributes.
41 * See memoryx::EntityWrappers::SimoxObjectWrapper for sample implementation.
42 *
43 * Apart of convenience, such wrapper classes give a maintance advantage, since they encapsulate all
44 * the implementation details (attribute names, storing formats), avoiding the need to duplicate them
45 * in multiple places in client code. So it's recommended to use this approach whenever possible.
46 *
47 */
48 class AbstractEntityWrapper : 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
77 private:
78 EntityBasePtr entity;
79 };
80
82 {
83 public:
85
86 protected:
87 /**
88 * @brief cleanUpAttributeFiles compares the files attached to the two
89 * given attributes and removes the files of the oldAttr, if they dont
90 * match. Thus, this function should only be called with attributes of
91 * the same kind (e.g. Attribute for texture files).
92 * If multiple files are attached to that attribute, they must appear
93 * in the same order.
94 * @param oldAttr
95 * @param newAttr
96 */
97 void cleanUpAttributeFiles(EntityAttributeBasePtr oldAttr, EntityAttributeBasePtr newAttr);
98 /**
99 * @brief removes all files of an attribute from the gridfs
100 * @param attr
101 */
102 void removeAttributeFiles(const memoryx::EntityAttributeBasePtr& attr);
103 std::string cacheAttributeFile(const std::string& attrName,
104 bool preserveOriginalFName = false) const;
105
107 };
108
109 /**
110 * Typedef of AbstractEntityWrapperPtr as IceUtil::Handle<AbstractEntityWrapper> for convenience.
111 */
113
114} // namespace memoryx::EntityWrappers
EntityBasePtr getEntity() const
Get the stored name of the stored entity.
std::string getName() const
Get the name of the stored entity.
void setEntity(const EntityBasePtr &entity)
Replace the stored entity with a new one.
std::string getId() const
Get the identifier of the stored entity.
std::string cacheAttributeFile(const std::string &attrName, bool preserveOriginalFName=false) const
void cleanUpAttributeFiles(EntityAttributeBasePtr oldAttr, EntityAttributeBasePtr newAttr)
cleanUpAttributeFiles compares the files attached to the two given attributes and removes the files o...
void removeAttributeFiles(const memoryx::EntityAttributeBasePtr &attr)
removes all files of an attribute from the gridfs
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
IceInternal::Handle< AbstractEntityWrapper > AbstractEntityWrapperPtr
Typedef of AbstractEntityWrapperPtr as IceUtil::Handle<AbstractEntityWrapper> for convenience.
VirtualRobot headers.
std::shared_ptr< GridFileManager > GridFileManagerPtr