RMF
Toggle main menu visibility
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>
13
#include <
RMF/infrastructure_macros.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
23
RMF_ENABLE_WARNINGS
24
namespace
RMF
{
25
namespace
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),
37
path_(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_;
82
StringKey
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.*/
94
ExternalConst
get
(
NodeConstHandle
nh)
const
{
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.*/
101
External
get
(
NodeHandle
nh)
const
{
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
120
struct
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 */
135
RMF_DISABLE_WARNINGS
136
137
#endif
/* RMF_EXTERNAL_DECORATORS_H */
Decorator.h
Mostly empty base classes for decorators and factories.
FileHandle.h
Declaration for RMF::FileHandle.
NodeHandle.h
Declaration of NodeHandle.
Vector.h
Represent coordinates.
RMF::Factory
The base class for Factories.
Definition
Decorator.h:46
RMF::FileConstHandle
A handle for a read-only RMF file.
Definition
FileConstHandle.h:78
RMF::FileHandle
A handle for an RMF file.
Definition
FileHandle.h:54
RMF::NodeConstHandle
A handle for a particular node in a read-only hierarchy.
Definition
NodeConstHandle.h:86
RMF::NodeConstHandle::get_type
NodeType get_type() const
get the type of this node
Definition
NodeConstHandle.h:203
RMF::NodeHandle
A handle for a particular node in the hierarchy.
Definition
NodeHandle.h:60
RMF::decorator::ExternalConst
Definition
external.h:30
RMF::decorator::ExternalFactory::get
ExternalConst get(NodeConstHandle nh) const
Definition
external.h:94
RMF::decorator::ExternalFactory::get_is
bool get_is(NodeConstHandle nh) const
Definition
external.h:109
RMF::decorator::ExternalFactory::get
External get(NodeHandle nh) const
Definition
external.h:101
RMF::decorator::External
Definition
external.h:56
constants.h
Various constants.
infrastructure_macros.h
Various general useful macros for IMP.
RMF::decorator
See Decorators and Attributes for more information.
Definition
CoordinateTransformer.h:22
RMF
The namespace for all functionality in the library.
Definition
BufferConstHandle.h:21
RMF::String
std::string String
Definition
types.h:39
RMF::StringKey
ID< StringTag > StringKey
Definition
keys.h:41
RMF::Category
ID< CategoryTag > Category
Definition
ID.h:110
RMF::REPRESENTATION
const NodeType REPRESENTATION
Represent part of a molecule.