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 
26 namespace RMF {
27 namespace internal {
28 class SharedData;
29 } // namespace internal
30 } // namespace RMF
31 
32 RMF_ENABLE_WARNINGS
33 
34 namespace RMF {
35 
36 class FileHandle;
37 
38 //! Pass a list of them
39 typedef std::vector<FileHandle> FileHandles;
40 
41 class 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  */
54 class 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.
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>
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  */
128 RMFEXPORT 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  */
133 RMFEXPORT FileHandle create_rmf_buffer(BufferHandle buffer);
134 
135 } /* namespace RMF */
136 
137 RMF_DISABLE_WARNINGS
138 
139 #endif /* RMF_FILE_HANDLE_H */
Declaration of RMF::ID.
Default implementation for types.h.
NodeHandle get_node_from_association(const T &d) const
Definition: FileHandle.h:83
A handle for a particular node in the hierarchy.
Definition: NodeHandle.h:60
FileHandle create_rmf_buffer(BufferHandle buffer)
Create an RMF in a buffer.
const FrameType FRAME
A frame in a sequence of frames.
A handle for a read-only RMF file.
FileHandle create_rmf_file(std::string path)
Create an RMF from a file system path.
A handle for an RMF file.
Definition: FileHandle.h:54
ID< NodeTag > NodeID
Definition: ID.h:106
Declaration of NodeHandle.
A strong enum with an associated string name for each value.
Definition: Enum.h:46
std::vector< FileHandle > FileHandles
Pass a list of them.
Definition: FileHandle.h:36
The various enums used in RMF.
Manage a shared buffer for storing a RMF.
Definition: BufferHandle.h:22
Various compiler workarounds.
Handle read/write of Model data from/to files.
NodeHandle get_root_node() const
Return the root of the hierarchy stored in the file.
Definition: FileHandle.h:66