RMF
publication.h
Go to the documentation of this file.
1/**
2 * \file RMF/decorator/publication.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_PUBLICATION_DECORATORS_H
10#define RMF_PUBLICATION_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 JournalArticle and JournalArticleFactory.
29 */
30 class JournalArticleConst: public Decorator {
31 friend class JournalArticleFactory;
32 protected:
33 StringKey title_;
34StringKey journal_;
35StringKey pubmed_id_;
36IntKey year_;
37StringsKey authors_;
38 JournalArticleConst(NodeConstHandle nh,
39 StringKey title,
40StringKey journal,
41StringKey pubmed_id,
42IntKey year,
43StringsKey authors):
44 Decorator(nh),
45title_(title),
46journal_(journal),
47pubmed_id_(pubmed_id),
48year_(year),
49authors_(authors) {
50 }
51 public:
52
53 String get_title() const {
54 try {
55 return get_node().get_value(title_);
56 } RMF_DECORATOR_CATCH( );
57 }
58 String get_frame_title() const {
59 try {
60 return get_node().get_frame_value(title_);
61 } RMF_DECORATOR_CATCH( );
62 }
63 String get_static_title() const {
64 try {
65 return get_node().get_static_value(title_);
66 } RMF_DECORATOR_CATCH( );
67 }
68
69
70 String get_journal() const {
71 try {
72 return get_node().get_value(journal_);
73 } RMF_DECORATOR_CATCH( );
74 }
75 String get_frame_journal() const {
76 try {
77 return get_node().get_frame_value(journal_);
78 } RMF_DECORATOR_CATCH( );
79 }
80 String get_static_journal() const {
81 try {
82 return get_node().get_static_value(journal_);
83 } RMF_DECORATOR_CATCH( );
84 }
85
86
87 String get_pubmed_id() const {
88 try {
89 return get_node().get_value(pubmed_id_);
90 } RMF_DECORATOR_CATCH( );
91 }
92 String get_frame_pubmed_id() const {
93 try {
94 return get_node().get_frame_value(pubmed_id_);
95 } RMF_DECORATOR_CATCH( );
96 }
97 String get_static_pubmed_id() const {
98 try {
99 return get_node().get_static_value(pubmed_id_);
100 } RMF_DECORATOR_CATCH( );
101 }
102
103
104 Int get_year() const {
105 try {
106 return get_node().get_value(year_);
107 } RMF_DECORATOR_CATCH( );
108 }
109 Int get_frame_year() const {
110 try {
111 return get_node().get_frame_value(year_);
112 } RMF_DECORATOR_CATCH( );
113 }
114 Int get_static_year() const {
115 try {
116 return get_node().get_static_value(year_);
117 } RMF_DECORATOR_CATCH( );
118 }
119
120
121 Strings get_authors() const {
122 try {
123 return get_node().get_value(authors_);
124 } RMF_DECORATOR_CATCH( );
125 }
126 Strings get_frame_authors() const {
127 try {
128 return get_node().get_frame_value(authors_);
129 } RMF_DECORATOR_CATCH( );
130 }
131 Strings get_static_authors() const {
132 try {
133 return get_node().get_static_value(authors_);
134 } RMF_DECORATOR_CATCH( );
135 }
136
137 static std::string get_decorator_type_name() {
138 return "JournalArticleConst";
139 }
140 RMF_SHOWABLE(JournalArticleConst, "JournalArticle: " << get_node());
141 };
142 /** See also JournalArticleFactory.
143 */
144 class JournalArticle: public JournalArticleConst {
145 friend class JournalArticleFactory;
146 JournalArticle(NodeHandle nh,
147 StringKey title,
148StringKey journal,
149StringKey pubmed_id,
150IntKey year,
151StringsKey authors):
152 JournalArticleConst(nh, title,
153journal,
154pubmed_id,
155year,
156authors) {
157 }
158 public:
159
160 void set_title(String v) {
161 try {
162 get_node().set_value(title_, v);
163 } RMF_DECORATOR_CATCH( );
164 }
165 void set_frame_title(String v) {
166 try {
167 get_node().set_frame_value(title_, v);
168 } RMF_DECORATOR_CATCH( );
169 }
170 void set_static_title(String v) {
171 try {
172 get_node().set_static_value(title_, v);
173 } RMF_DECORATOR_CATCH( );
174 }
175
176
177 void set_journal(String v) {
178 try {
179 get_node().set_value(journal_, v);
180 } RMF_DECORATOR_CATCH( );
181 }
182 void set_frame_journal(String v) {
183 try {
184 get_node().set_frame_value(journal_, v);
185 } RMF_DECORATOR_CATCH( );
186 }
187 void set_static_journal(String v) {
188 try {
189 get_node().set_static_value(journal_, v);
190 } RMF_DECORATOR_CATCH( );
191 }
192
193
194 void set_pubmed_id(String v) {
195 try {
196 get_node().set_value(pubmed_id_, v);
197 } RMF_DECORATOR_CATCH( );
198 }
199 void set_frame_pubmed_id(String v) {
200 try {
201 get_node().set_frame_value(pubmed_id_, v);
202 } RMF_DECORATOR_CATCH( );
203 }
204 void set_static_pubmed_id(String v) {
205 try {
206 get_node().set_static_value(pubmed_id_, v);
207 } RMF_DECORATOR_CATCH( );
208 }
209
210
211 void set_year(Int v) {
212 try {
213 get_node().set_value(year_, v);
214 } RMF_DECORATOR_CATCH( );
215 }
216 void set_frame_year(Int v) {
217 try {
218 get_node().set_frame_value(year_, v);
219 } RMF_DECORATOR_CATCH( );
220 }
221 void set_static_year(Int v) {
222 try {
223 get_node().set_static_value(year_, v);
224 } RMF_DECORATOR_CATCH( );
225 }
226
227
228 void set_authors(Strings v) {
229 try {
230 get_node().set_value(authors_, v);
231 } RMF_DECORATOR_CATCH( );
232 }
233 void set_frame_authors(Strings v) {
234 try {
235 get_node().set_frame_value(authors_, v);
236 } RMF_DECORATOR_CATCH( );
237 }
238 void set_static_authors(Strings v) {
239 try {
240 get_node().set_static_value(authors_, v);
241 } RMF_DECORATOR_CATCH( );
242 }
243
244 static std::string get_decorator_type_name() {
245 return "JournalArticle";
246 }
247 };
248
249
250 /** Create decorators of type JournalArticle.
251 */
252 class JournalArticleFactory: public Factory {
253 Category cat_;
254StringKey title_;
255StringKey journal_;
256StringKey pubmed_id_;
257IntKey year_;
258StringsKey authors_;
259
260
261
262
263
264 public:
265 JournalArticleFactory(FileConstHandle fh):
266 cat_(fh.get_category("publication")),
267 title_(fh.get_key<StringTag>(cat_, "title")), journal_(fh.get_key<StringTag>(cat_, "journal")), pubmed_id_(fh.get_key<StringTag>(cat_, "pubmed id")), year_(fh.get_key<IntTag>(cat_, "year")), authors_(fh.get_key<StringsTag>(cat_, "authors")) {
268 }
269 JournalArticleFactory(FileHandle fh):
270 cat_(fh.get_category("publication")),
271 title_(fh.get_key<StringTag>(cat_, "title")), journal_(fh.get_key<StringTag>(cat_, "journal")), pubmed_id_(fh.get_key<StringTag>(cat_, "pubmed id")), year_(fh.get_key<IntTag>(cat_, "year")), authors_(fh.get_key<StringsTag>(cat_, "authors")) {
272 }
273 /** Get a JournalArticleConst for nh.*/
275 RMF_USAGE_CHECK((nh.get_type() == RMF::ORGANIZATIONAL), std::string("Bad node type. Got \"")
276 + boost::lexical_cast<std::string>(nh.get_type())
277 + "\" in decorator type JournalArticle");
278 return JournalArticleConst(nh, title_,
279journal_,
280pubmed_id_,
281year_,
282authors_);
283 }
284 /** Get a JournalArticle for nh.*/
286 RMF_USAGE_CHECK((nh.get_type() == RMF::ORGANIZATIONAL), std::string("Bad node type. Got \"")
287 + boost::lexical_cast<std::string>(nh.get_type())
288 + "\" in decorator type JournalArticle");
289 return JournalArticle(nh, title_,
290journal_,
291pubmed_id_,
292year_,
293authors_);
294 }
295 /** Check whether nh has all the attributes required to be a
296 JournalArticleConst.*/
297 bool get_is(NodeConstHandle nh) const {
298 return (nh.get_type() == RMF::ORGANIZATIONAL)
299 && !nh.get_value(title_).get_is_null();
300 }
301 bool get_is_static(NodeConstHandle nh) const {
302 return (nh.get_type() == RMF::ORGANIZATIONAL)
303 && !nh.get_static_value(title_).get_is_null()
304 && !nh.get_static_value(journal_).get_is_null()
305 && !nh.get_static_value(pubmed_id_).get_is_null()
306 && !nh.get_static_value(year_).get_is_null()
307 && !nh.get_static_value(authors_).get_is_null();
308 }
309 RMF_SHOWABLE(JournalArticleFactory, "JournalArticleFactory");
310 };
311 #ifndef RMF_DOXYGEN
312struct JournalArticleConstFactory: public JournalArticleFactory {
313 JournalArticleConstFactory(FileConstHandle fh):
314 JournalArticleFactory(fh) {
315 }
316 JournalArticleConstFactory(FileHandle fh):
317 JournalArticleFactory(fh) {
318 }
319
320};
321 #endif
322
323
324
325} /* namespace decorator */
326} /* namespace RMF */
327RMF_DISABLE_WARNINGS
328
329#endif /* RMF_PUBLICATION_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
JournalArticleConst get(NodeConstHandle nh) const
bool get_is(NodeConstHandle nh) const
JournalArticle get(NodeHandle nh) const
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
int Int
Definition types.h:29
ID< CategoryTag > Category
Definition ID.h:110
ID< StringsTag > StringsKey
Definition keys.h:41
const NodeType ORGANIZATIONAL
A node that is purely there for organizational purposes.
std::vector< String > Strings
Definition types.h:41
ID< IntTag > IntKey
Definition keys.h:41