RMF
Toggle main menu visibility
reference.h
Go to the documentation of this file.
1
/**
2
* \file RMF/decorator/reference.h
3
* \brief Add a pointer from a node to another reference node.
4
*
5
* Copyright 2007-2022 IMP Inventors. All rights reserved.
6
*
7
*/
8
9
#ifndef RMF_DECORATOR_REFERENCE_H
10
#define RMF_DECORATOR_REFERENCE_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 <array>
20
#include <boost/lexical_cast.hpp>
21
22
RMF_ENABLE_WARNINGS
23
namespace
RMF
{
24
namespace
decorator
{
25
26
/** See also Reference and ReferenceFactory.
27
*/
28
class
ReferenceConst :
public
Decorator {
29
friend
class
ReferenceFactory;
30
friend
class
Reference;
31
IntKey
reference_;
32
ReferenceConst(
NodeConstHandle
nh,
IntKey
reference)
33
: Decorator(nh), reference_(reference) {}
34
35
public
:
36
NodeConstHandle
get_reference()
const
{
37
try
{
38
return
get_node().get_file().get_node(
39
NodeID
(get_node().get_value(reference_)));
40
}
41
RMF_DECORATOR_CATCH();
42
}
43
NodeConstHandle
get_frame_reference()
const
{
44
try
{
45
return
get_node().get_file().get_node(
46
NodeID
(get_node().get_frame_value(reference_)));
47
}
48
RMF_DECORATOR_CATCH();
49
}
50
NodeConstHandle
get_static_reference()
const
{
51
try
{
52
return
get_node().get_file().get_node(
53
NodeID
(get_node().get_static_value(reference_)));
54
}
55
RMF_DECORATOR_CATCH();
56
}
57
58
static
std::string get_decorator_type_name() {
return
"ReferenceConst"
; }
59
RMF_SHOWABLE(ReferenceConst,
"Reference: "
<< get_node());
60
};
61
/** See also ReferenceFactory.
62
*/
63
class
Reference :
public
ReferenceConst {
64
friend
class
ReferenceFactory;
65
Reference(
NodeHandle
nh,
IntKey
reference)
66
: ReferenceConst(nh, reference) {}
67
68
public
:
69
70
NodeHandle
get_reference()
const
{
71
try
{
72
return
get_node().get_file().get_node(
73
NodeID
(get_node().get_value(reference_)));
74
}
75
RMF_DECORATOR_CATCH();
76
}
77
NodeHandle
get_frame_reference()
const
{
78
try
{
79
return
get_node().get_file().get_node(
80
NodeID
(get_node().get_frame_value(reference_)));
81
}
82
RMF_DECORATOR_CATCH();
83
}
84
NodeHandle
get_static_reference()
const
{
85
try
{
86
return
get_node().get_file().get_node(
87
NodeID
(get_node().get_static_value(reference_)));
88
}
89
RMF_DECORATOR_CATCH();
90
}
91
92
void
set_reference(
NodeConstHandle
v) {
93
try
{
94
get_node().set_value(reference_, v.get_id().get_index());
95
}
96
RMF_DECORATOR_CATCH();
97
}
98
void
set_frame_reference(
NodeConstHandle
v) {
99
try
{
100
get_node().set_frame_value(reference_, v.get_id().get_index());
101
}
102
RMF_DECORATOR_CATCH();
103
}
104
void
set_static_reference(
NodeConstHandle
v) {
105
try
{
106
get_node().set_static_value(reference_, v.get_id().get_index());
107
}
108
RMF_DECORATOR_CATCH();
109
}
110
111
static
std::string get_decorator_type_name() {
return
"Reference"
; }
112
};
113
114
/** Create decorators of type Reference.
115
*/
116
class
ReferenceFactory :
public
Factory
{
117
Category
cat_;
118
IntKey
reference_;
119
120
public
:
121
ReferenceFactory(
FileConstHandle
fh)
122
: cat_(fh.get_category(
"sequence"
)),
123
reference_(fh.get_key<IntTag>(cat_,
"reference"
)) {}
124
ReferenceFactory(
FileHandle
fh)
125
: cat_(fh.get_category(
"sequence"
)),
126
reference_(fh.get_key<IntTag>(cat_,
"reference"
)) {}
127
/** Get a ReferenceConst for nh.*/
128
ReferenceConst
get
(
NodeConstHandle
nh)
const
{
129
RMF_USAGE_CHECK((nh.
get_type
() ==
RMF::REPRESENTATION
),
130
std::string(
"Bad node type. Got \""
) +
131
boost::lexical_cast<std::string>(nh.
get_type
()) +
132
"\" in decorator type Reference"
);
133
return
ReferenceConst
(nh, reference_);
134
}
135
/** Get a Reference for nh.*/
136
Reference
get
(
NodeHandle
nh)
const
{
137
RMF_USAGE_CHECK((nh.
get_type
() ==
RMF::REPRESENTATION
),
138
std::string(
"Bad node type. Got \""
) +
139
boost::lexical_cast<std::string>(nh.
get_type
()) +
140
"\" in decorator type Reference"
);
141
return
Reference
(nh, reference_);
142
}
143
/** Check whether nh has all the attributes required to be a
144
ReferenceConst.*/
145
bool
get_is
(
NodeConstHandle
nh)
const
{
146
return
(nh.
get_type
() ==
RMF::REPRESENTATION
) &&
147
!nh.get_value(reference_).get_is_null();
148
}
149
bool
get_is_static(
NodeConstHandle
nh)
const
{
150
return
(nh.
get_type
() ==
RMF::REPRESENTATION
) &&
151
!nh.get_static_value(reference_).get_is_null();
152
}
153
RMF_SHOWABLE(ReferenceFactory,
"ReferenceFactory"
);
154
};
155
156
}
/* namespace decorator */
157
}
/* namespace RMF */
158
RMF_DISABLE_WARNINGS
159
160
#endif
/* RMF_DECORATOR_REFERENCE_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::ReferenceConst
Definition
reference.h:28
RMF::decorator::ReferenceFactory::get
ReferenceConst get(NodeConstHandle nh) const
Definition
reference.h:128
RMF::decorator::ReferenceFactory::get
Reference get(NodeHandle nh) const
Definition
reference.h:136
RMF::decorator::ReferenceFactory::get_is
bool get_is(NodeConstHandle nh) const
Definition
reference.h:145
RMF::decorator::Reference
Definition
reference.h:63
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::Category
ID< CategoryTag > Category
Definition
ID.h:110
RMF::NodeID
ID< NodeTag > NodeID
Definition
ID.h:106
RMF::IntKey
ID< IntTag > IntKey
Definition
keys.h:41
RMF::REPRESENTATION
const NodeType REPRESENTATION
Represent part of a molecule.