RMF
external.h
Go to the documentation of this file.
1/**
2 * \file RMF/decorator/external.h
3 * \brief Helper functions for manipulating RMF files.
4 *
5 * Copyright 2007-2022 IMP Inventors. All rights reserved.
6 *
7 */
8
9#ifndef RMF_EXTERNAL_DECORATORS_H
10#define RMF_EXTERNAL_DECORATORS_H
11
12#include <RMF/config.h>
14#include <RMF/NodeHandle.h>
15#include <RMF/FileHandle.h>
16#include <RMF/Decorator.h>
17#include <RMF/constants.h>
18#include <RMF/Vector.h>
19#include <RMF/internal/paths.h>
20#include <array>
21#include <boost/lexical_cast.hpp>
22
23RMF_ENABLE_WARNINGS
24namespace RMF {
25namespace decorator {
26
27
28 /** See also External and ExternalFactory.
29 */
30 class ExternalConst: public Decorator {
31 friend class ExternalFactory;
32 protected:
33 StringKey path_;
34 ExternalConst(NodeConstHandle nh,
35 StringKey path):
36 Decorator(nh),
37path_(path) {
38 }
39 public:
40
41 String get_path() const {
42 try {
43 String relpath = get_node().get_value(path_);
44 String filename = get_node().get_file().get_path();
45 return internal::get_absolute_path(filename, relpath);
46 } RMF_DECORATOR_CATCH( );
47 }
48
49 static std::string get_decorator_type_name() {
50 return "ExternalConst";
51 }
52 RMF_SHOWABLE(ExternalConst, "External: " << get_node());
53 };
54 /** See also ExternalFactory.
55 */
56 class External: public ExternalConst {
57 friend class ExternalFactory;
58 External(NodeHandle nh,
59 StringKey path):
60 ExternalConst(nh, path) {
61 }
62 public:
63
64 void set_path(String path) {
65 try {
66 String filename = get_node().get_file().get_path();
67 String relpath = internal::get_relative_path(filename, path);
68 get_node().set_value(path_, relpath);
69 } RMF_DECORATOR_CATCH( );
70 }
71
72 static std::string get_decorator_type_name() {
73 return "External";
74 }
75 };
76
77
78 /** Create decorators of type External.
79 */
80 class ExternalFactory: public Factory {
81 Category cat_;
82StringKey path_;
83
84 public:
85 ExternalFactory(FileConstHandle fh):
86 cat_(fh.get_category("external")),
87 path_(fh.get_key<StringTag>(cat_, "path")) {
88 }
89 ExternalFactory(FileHandle fh):
90 cat_(fh.get_category("external")),
91 path_(fh.get_key<StringTag>(cat_, "path")) {
92 }
93 /** Get a ExternalConst for nh.*/
95 RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
96 + boost::lexical_cast<std::string>(nh.get_type())
97 + "\" in decorator type External");
98 return ExternalConst(nh, path_);
99 }
100 /** Get a External for nh.*/
102 RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
103 + boost::lexical_cast<std::string>(nh.get_type())
104 + "\" in decorator type External");
105 return External(nh, path_);
106 }
107 /** Check whether nh has all the attributes required to be a
108 ExternalConst.*/
109 bool get_is(NodeConstHandle nh) const {
110 return (nh.get_type() == RMF::REPRESENTATION)
111 && !nh.get_value(path_).get_is_null();
112 }
113 bool get_is_static(NodeConstHandle nh) const {
114 return (nh.get_type() == RMF::REPRESENTATION)
115 && !nh.get_static_value(path_).get_is_null();
116 }
117 RMF_SHOWABLE(ExternalFactory, "ExternalFactory");
118 };
119 #ifndef RMF_DOXYGEN
120struct ExternalConstFactory: public ExternalFactory {
121 ExternalConstFactory(FileConstHandle fh):
122 ExternalFactory(fh) {
123 }
124 ExternalConstFactory(FileHandle fh):
125 ExternalFactory(fh) {
126 }
127
128};
129 #endif
130
131
132
133} /* namespace decorator */
134} /* namespace RMF */
135RMF_DISABLE_WARNINGS
136
137#endif /* RMF_EXTERNAL_DECORATORS_H */
Mostly empty base classes for decorators and factories.
Declaration for RMF::FileHandle.
Declaration of NodeHandle.
Represent coordinates.
The base class for Factories.
Definition Decorator.h:46
A handle for a read-only RMF file.
A handle for an RMF file.
Definition FileHandle.h:54
A handle for a particular node in a read-only hierarchy.
NodeType get_type() const
get the type of this node
A handle for a particular node in the hierarchy.
Definition NodeHandle.h:60
ExternalConst get(NodeConstHandle nh) const
Definition external.h:94
bool get_is(NodeConstHandle nh) const
Definition external.h:109
External get(NodeHandle nh) const
Definition external.h:101
Various constants.
Various general useful macros for IMP.
See Decorators and Attributes for more information.
The namespace for all functionality in the library.
std::string String
Definition types.h:39
ID< StringTag > StringKey
Definition keys.h:41
ID< CategoryTag > Category
Definition ID.h:110
const NodeType REPRESENTATION
Represent part of a molecule.