RMF
FileHandle.h
Go to the documentation of this file.
1/**
2 * \file RMF/FileHandle.h
3 * \brief Declaration for RMF::FileHandle.
4 *
5 * Copyright 2007-2022 IMP Inventors. All rights reserved.
6 *
7 */
8
9#ifndef RMF_FILE_HANDLE_H
10#define RMF_FILE_HANDLE_H
11
12#include <memory>
13#include <string>
14#include <vector>
15
16#include "FileConstHandle.h"
17#include "ID.h"
18#include "NodeHandle.h"
19#include "RMF/config.h"
20#include "RMF/internal/SharedData.h"
21#include "compiler_macros.h"
22#include "enums.h"
23#include "internal/SharedData.h"
24#include "types.h"
25
26namespace RMF {
27namespace internal {
28class SharedData;
29} // namespace internal
30} // namespace RMF
31
32RMF_ENABLE_WARNINGS
33
34namespace RMF {
35
36class FileHandle;
37
38//! Pass a list of them
39typedef std::vector<FileHandle> FileHandles;
40
41class BufferHandle;
42
43//! A handle for an RMF file
44/** Use this handle to perform operations relevant to the
45 whole RMF hierarchy as well as to start traversal of the
46 hierarchy.
47
48 Make sure to check out the base class documentation
49 for the non-modifying methods.
50
51 \see create_rmf_file
52 \see create_rmf_buffer
53 */
54class RMFEXPORT FileHandle : public FileConstHandle {
55 friend class NodeHandle;
56 friend class std::shared_ptr<internal::SharedData>;
57
58 public:
59 //! Empty file handle, no open file.
61#if !defined(RMF_DOXYGEN) && !defined(SWIG)
62 FileHandle(std::shared_ptr<internal::SharedData> shared_);
63#endif
64
65 //! Return the root of the hierarchy stored in the file.
66 NodeHandle get_root_node() const {
67 RMF_USAGE_CHECK(!get_is_closed(), "Operation on closed file.");
68 return NodeHandle(NodeID(0), shared_);
69 }
70
71 //! Add a frame and make it the current frame.
72 FrameID add_frame(std::string name, FrameType t = FRAME) const;
73
74 //! Add a frame and make it the current frame.
75 /** It will be the child of the passed frame. */
76 FrameID add_frame(std::string name, FrameID parent,
77 FrameType t = FRAME) const;
78#ifndef SWIG
79 /** Each node in the hierarchy can be associated with some arbitrary bit
80 of external data. Nodes can be extracted using these bits of data.
81 */
82 template <class T>
83 NodeHandle get_node_from_association(const T& d) const {
84 if (!shared_->get_has_associated_node(d)) {
85 return NodeHandle();
86 } else {
87 return NodeHandle(shared_->get_associated_node(d), shared_);
88 }
89 }
90#else
91 NodeHandle get_node_from_association(void* d) const;
92#endif
93 /* @} */
94
95 //! Return a NodeHandle from a NodeID.
96 /** The NodeID must refer to a valid NodeHandle. */
97 NodeHandle get_node(NodeID id) const;
98
99 //! Add a node with no parents.
100 /** This node will not be accessible in the
101 hierarchy unless you add it as a child of something. */
102 NodeHandle add_node(std::string name, NodeType t) const;
103
104 /** Each RMF structure has an associated description. This should
105 consist of unstructured text describing the contents of the RMF
106 data. Conventionally. this description can consist of multiple
107 paragraphs, each separated by a newline character and should end
108 in a newline.
109 */
110 void set_description(std::string descr) const;
111
112 /** Each RMF structure has an associated field that the code that
113 produced the file can use to describe itself.
114 */
115 void set_producer(std::string) const;
116
117 //! Make sure all data gets written to disk.
118 /** Once flush is called, it should be safe to open the file in
119 another process for reading.
120 */
121 void flush() const;
122};
123
124//! Create an RMF from a file system path.
125/** \param path the system path to the rmf file
126 \exception RMF::IOException couldn't create file, or unsupported file format
127 */
128RMFEXPORT FileHandle create_rmf_file(std::string path);
129
130//! Create an RMF in a buffer.
131/** \param buffer The buffer to place the contents in.
132 */
134
135} /* namespace RMF */
136
137RMF_DISABLE_WARNINGS
138
139#endif /* RMF_FILE_HANDLE_H */
Handle read/write of Model data from/to files.
Declaration of RMF::ID.
Declaration of NodeHandle.
Manage a shared buffer for storing a RMF.
FileConstHandle()
Empty root handle, no open file.
bool get_is_closed() const
Return True iff the file is closed.
A handle for an RMF file.
Definition FileHandle.h:54
void flush() const
Make sure all data gets written to disk.
void set_description(std::string descr) const
NodeHandle get_root_node() const
Return the root of the hierarchy stored in the file.
Definition FileHandle.h:66
FileHandle()
Empty file handle, no open file.
Definition FileHandle.h:60
FrameID add_frame(std::string name, FrameID parent, FrameType t=FRAME) const
Add a frame and make it the current frame.
NodeHandle get_node_from_association(const T &d) const
Definition FileHandle.h:83
NodeHandle add_node(std::string name, NodeType t) const
Add a node with no parents.
void set_producer(std::string) const
NodeHandle get_node(NodeID id) const
Return a NodeHandle from a NodeID.
FrameID add_frame(std::string name, FrameType t=FRAME) const
Add a frame and make it the current frame.
A handle for a particular node in the hierarchy.
Definition NodeHandle.h:60
Various compiler workarounds.
The various enums used in RMF.
The namespace for all functionality in the library.
std::vector< FileHandle > FileHandles
Pass a list of them.
Definition FileHandle.h:39
Enum< NodeTypeTag > NodeType
Definition Enum.h:121
const FrameType FRAME
A frame in a sequence of frames.
ID< NodeTag > NodeID
Definition ID.h:106
ID< FrameTag > FrameID
Definition ID.h:108
FileHandle create_rmf_file(std::string path)
Create an RMF from a file system path.
Enum< FrameTypeTag > FrameType
Definition Enum.h:116
FileHandle create_rmf_buffer(BufferHandle buffer)
Create an RMF in a buffer.
Default implementation for types.h.