9 #ifndef RMF_FILE_CONST_HANDLE_H
10 #define RMF_FILE_CONST_HANDLE_H
12 #include <boost/current_function.hpp>
13 #include <boost/functional/hash.hpp>
23 #include "RMF/config.h"
28 #include "RMF/internal/SharedData.h"
29 #include "RMF/internal/errors.h"
30 #include "RMF/internal/shared_data_ranges.h"
31 #include "internal/SharedData.h"
32 #include "internal/shared_data_ranges.h"
36 class BufferConstHandle;
37 class FileConstHandle;
42 #define RMF_FILE_CATCH(extra_info) \
43 catch (Exception& e) { \
45 File(get_path()) << Frame(get_current_frame()) \
46 << Operation(BOOST_CURRENT_FUNCTION) extra_info, \
51 #define RMF_HDF5_ROOT_CONST_KEY_TYPE_METHODS(Traits, UCName)
53 #define RMF_HDF5_ROOT_CONST_KEY_TYPE_METHODS(Traits, UCName) \
54 UCName##Key get_key(Category category_id, std::string nm, \
56 std::string get_name(UCName##Key k) const; \
57 Category get_category(UCName##Key k) const; \
60 UCName##Key##s get_keys(Category category_id, UCName##Tag);
65 class FileConstHandle;
80 std::string path)
const;
82 friend class RMFEXPORT NodeConstHandle;
93 if (get_name() < o.get_name())
95 else if (get_name() > o.get_name())
102 std::shared_ptr<internal::SharedData> shared_;
110 #if !defined(RMF_DOXYGEN) && !defined(SWIG)
116 RMF_USAGE_CHECK(!get_is_closed(),
"Operation on closed file.");
117 return NodeConstHandle(
NodeID(0), shared_);
131 if (!get_is_closed()) {
136 std::string get_name()
const {
138 return shared_->get_file_name();
140 return "(closed RMF file handle)";
144 std::string get_path()
const {
145 RMF_USAGE_CHECK(!get_is_closed(),
"File is closed, no path.");
146 return shared_->get_file_path();
161 return shared_->get_key(category, name, Tag());
163 RMF_FILE_CATCH(<<
Category(get_name(category)) << Key(name));
167 std::vector<ID<Tag> > get_keys(
Category category_id,
170 std::vector<ID<Tag> > ret(names.size());
171 for (
unsigned int i = 0; i < names.size(); ++i) {
172 ret[i] = get_key<Tag>(category_id, names[i]);
180 RMF_FILE_CATCH(<<
Category(get_name(category_id)));
188 if (category ==
Category())
return std::vector<ID<Tag> >();
189 return shared_->get_keys(category, Tag());
191 RMF_FILE_CATCH(<<
Category(get_name(category)));
196 return get_key<Tag>(category_id, nm);
199 std::string get_name(ID<Tag> k)
const {
201 return shared_->get_name(k);
206 Category get_category(ID<Tag> k)
const {
207 return shared_->get_category(k);
213 return get_keys<Tag>(category_id);
223 RMF_USAGE_CHECK(!get_is_closed(),
"Operation on closed file.");
224 return shared_->get_loaded_frame();
228 RMF_USAGE_CHECK(!get_is_closed(),
"Operation on closed file.");
229 return shared_->get_frame_data(fr).type;
231 std::string get_name(
FrameID fr)
const {
232 RMF_USAGE_CHECK(!get_is_closed(),
"Operation on closed file.");
233 return shared_->get_frame_data(fr).name;
236 RMF_USAGE_CHECK(!get_is_closed(),
"Operation on closed file.");
237 const internal::FrameData& fd = shared_->get_frame_data(
id);
238 return FrameIDs(fd.children.begin(), fd.children.end());
241 RMF_USAGE_CHECK(!get_is_closed(),
"Operation on closed file.");
242 const internal::FrameData& fd = shared_->get_frame_data(
id);
243 return FrameIDs(fd.parents.begin(), fd.parents.end());
245 void set_current_frame(
FrameID frame)
const {
246 RMF_USAGE_CHECK(!get_is_closed(),
"Operation on closed file.");
247 RMF_USAGE_CHECK(frame !=
FrameID(),
"Invalid frame passed.");
249 "Use set_static_value() and get_static_value() to "
250 "manipulate the static frame.");
252 shared_->set_loaded_frame(frame);
254 RMF_FILE_CATCH(<< Frame(frame));
260 RMF_USAGE_CHECK(!get_is_closed(),
"Operation on closed file.");
262 return shared_->get_number_of_frames();
270 RMF_USAGE_CHECK(!get_is_closed(),
"Operation on closed file.");
272 return shared_->get_number_of_nodes();
280 RMF_USAGE_CHECK(!get_is_closed(),
"Operation on closed file.");
281 return shared_->get_file_type();
288 boost::iterator_range<internal::integer_iterator<FrameID> > get_frames()
290 return internal::get_frames(shared_.get());
293 boost::iterator_range<internal::integer_iterator<NodeID> > get_node_ids()
295 return internal::get_nodes(shared_.get());
313 PythonList get_keys(
Category c)
const;
323 if (!shared_->get_has_associated_node(d)) {
324 return NodeConstHandle();
326 return NodeConstHandle(shared_->get_associated_node(d), shared_);
330 NodeConstHandle get_node_from_association(
void* v)
const;
332 NodeConstHandle get_node(
NodeID id)
const;
339 shared_->set_user_data(index, t);
344 return shared_->get_user_data<T>(index);
349 return shared_->get_has_user_data(index);
358 std::string get_description()
const;
363 std::string get_producer()
const;
369 Category get_category(std::string name) {
371 return shared_->get_category(name);
379 return shared_->get_categories();
383 std::string get_name(
Category kc)
const {
385 return shared_->get_name(kc);
430 Float missing_value = std::numeric_limits<float>::max());
std::vector< ID< Tag > > get_keys(Category category_id, Tag)
std::size_t hash_value(const FileConstHandle &t)
Produce hash values for boost hash tables.
FileConstHandle open_rmf_buffer_read_only(BufferConstHandle buffer)
Default implementation for types.h.
void clone_static_frame(FileConstHandle input, FileHandle output)
FileConstHandle()
Empty root handle, no open file.
NodeConstHandle get_node_from_association(const T &d) const
void clone_hierarchy(FileConstHandle input, FileHandle output)
A handle for a particular node in a read-only hierarchy.
T get_associated_data(int index)
unsigned int get_number_of_frames() const
std::vector< Category > Categories
A handle for a read-only RMF file.
std::size_t hash_value(const BufferConstHandle &t)
Produce hash values for boost hash tables.
FrameID get_current_frame() const
FileConstHandle open_rmf_file_read_only(std::string path)
std::vector< FileConstHandle > FileConstHandles
Pass a list of them.
void clone_file_info(FileConstHandle input, FileHandle output)
void clone_loaded_frame(FileConstHandle input, FileHandle output)
A general purpose ID in RMF used, with different tags, to identify things.
ID< CategoryTag > Category
std::vector< String > Strings
Declarations of the various exception types.
Categories get_categories() const
A handle for an RMF file.
#define RMF_COMPARISONS(Name)
Implement comparison in a class using field as the variable to compare.
Declaration of NodeConstHandle.
A strong enum with an associated string name for each value.
The various enums used in RMF.
unsigned int get_number_of_nodes() const
#define RMF_HASHABLE(name, hashret)
Implement a hash function for the class.
std::vector< NodeConstHandle > NodeConstHandles
Pass a list of them.
bool get_equal_current_values(FileConstHandle input, FileConstHandle out)
void add_associated_data(int index, const T &t)
NodeConstHandle get_root_node() const
Return the root of the hierarchy.
#define RMF_FOREACH_TYPE(macroname)
bool get_is_closed() const
Return True iff the file is closed.
std::vector< ID< Tag > > get_keys(Category category) const
std::vector< Float > Floats
void close()
Explicitly close the file handle.
ID< Tag > get_key(Category category, std::string name) const
std::vector< FrameID > FrameIDs
Various general useful macros for IMP.
bool get_has_associated_data(int index)
bool get_equal_static_values(FileConstHandle input, FileConstHandle out)
static const FrameID ALL_FRAMES
Declare RMF::BufferHandle.
std::string get_file_type() const