openmbvcppinterface  3.1.0
OpenMBV C++ Interface
group.h
1/*
2 OpenMBV - Open Multi Body Viewer.
3 Copyright (C) 2009 Markus Friedrich
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20#ifndef _OPENMBV_GROUP_H_
21#define _OPENMBV_GROUP_H_
22
23#include "hdf5serie/simpledataset.h"
24#include <openmbvcppinterface/objectfactory.h>
25#include <openmbvcppinterface/object.h>
26#include <vector>
27#include <map>
28
29namespace OpenMBV {
30
32 class Group : public Object
33#ifndef SWIG
34 , public std::enable_shared_from_this<Group>
35#endif
36 {
37 friend class Body;
38 friend class Object;
39 friend class ObjectFactory;
40 protected:
41 std::vector<std::shared_ptr<Object> > object;
42 std::string expandStr;
43 boost::filesystem::path fileName; // the file name of the .ombvx file including the absolute or relatvie path
44 std::shared_ptr<H5::File> hdf5File;
45 H5::SimpleDataset<int> *rowSize { nullptr };
46 std::function<void()> closeRequestCallback;
47 std::function<void()> refreshCallback;
48 void createHDF5File() override;
49 void openHDF5File() override;
50
51 Group();
52 ~Group() override = default;
53
54 std::shared_ptr<xercesc::DOMDocument> writeXMLDoc();
58 void writeXML();
59
63 void readXML();
64
65 public:
67 void setExpand(bool expand) { expandStr=(expand)?"true":"false"; }
68
69 bool getExpand() { return expandStr=="true"?true:false; }
70
72 void addObject(const std::shared_ptr<Object>& newObject);
73
74 std::vector<std::shared_ptr<Object> >& getObjects() {
75 return object;
76 }
77
78 std::shared_ptr<H5::File> getHDF5File() const { return hdf5File; }
79
81 std::string getFileName() { return fileName.string(); }
82
83 std::string getFullName() override;
84
86 void setFileName(const boost::filesystem::path &fn) { fileName=fn; }
87
92 void write(bool writeXMLFile=true, bool writeH5File=true, bool embedXMLInH5=false);
93
95 void read();
96
98 void enableSWMR();
99
101 void setRowSize(int rs);
102
105 int getRowSize();
106
107 /* This function should be called periodically for a file opened for writing.
108 * It flush's the file (the dataset) of a writer if such a flush was requested by a reader.
109 * Does nothing if no reader has requested a flush.
110 * If a flush happens postFlushFunc is called immediately after the flush (a shared_ptr of "this" is passed as argument)
111 * and than the readers are notified about the flush. */
112 void flushIfRequested(const std::function<void(const std::shared_ptr<Group> &)> &postFlushFunc={});
113
115 void flush();
116
118 void refresh();
119
120 /* Called by a reader to request a flush of the writer.
121 * This is not blocking. If the writer has flushed the setRefreshCallback is called.
122 * If a writer process currently exists true is returned else false. Note that this returned flag cannot change
123 * while the calling process has opened the file for reading. */
124 bool requestFlush();
125
127 void setCloseRequestCallback(const std::function<void()> &closeRequestCallback_) { closeRequestCallback=closeRequestCallback_; }
128
131 void setRefreshCallback(const std::function<void()> &refreshCallback_) { refreshCallback=refreshCallback_; }
132
134 void initializeUsingXML(xercesc::DOMElement *element) override;
135
136 xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *parent) override;
137
139 std::shared_ptr<Group> getTopLevelGroup() {
140 std::shared_ptr<Group> p=parent.lock();
141 return !p?shared_from_this():p->getTopLevelGroup();
142 }
143 };
144
145}
146
147#endif
Definition: body.h:32
Definition: group.h:36
void setRowSize(int rs)
Definition: group.cc:206
void setCloseRequestCallback(const std::function< void()> &closeRequestCallback_)
Definition: group.h:127
void readXML()
Definition: group.cc:142
void addObject(const std::shared_ptr< Object > &newObject)
Definition: group.cc:50
void refresh()
Definition: group.cc:229
void write(bool writeXMLFile=true, bool writeH5File=true, bool embedXMLInH5=false)
Definition: group.cc:160
int getRowSize()
Definition: group.cc:211
void initializeUsingXML(xercesc::DOMElement *element) override
Definition: group.cc:119
void writeXML()
Definition: group.cc:115
void setExpand(bool expand)
Definition: group.h:67
void setFileName(const boost::filesystem::path &fn)
Definition: group.h:86
std::string getFullName() override
Definition: group.cc:59
std::shared_ptr< Group > getTopLevelGroup()
Definition: group.h:139
void setRefreshCallback(const std::function< void()> &refreshCallback_)
Definition: group.h:131
void flush()
Definition: group.cc:225
void read()
Definition: group.cc:239
void enableSWMR()
Definition: group.cc:201
std::string getFileName()
Definition: group.h:81
Definition: objectfactory.h:38
Definition: object.h:50