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 
23 RMF_ENABLE_WARNINGS
24 namespace RMF {
25 namespace decorator {
26 
27 
28  /** See also JournalArticle and JournalArticleFactory.
29  */
31  friend class JournalArticleFactory;
32  protected:
33  StringKey title_;
34 StringKey journal_;
35 StringKey pubmed_id_;
36 IntKey year_;
37 StringsKey authors_;
39  StringKey title,
40 StringKey journal,
41 StringKey pubmed_id,
42 IntKey year,
43 StringsKey authors):
44  Decorator(nh),
45 title_(title),
46 journal_(journal),
47 pubmed_id_(pubmed_id),
48 year_(year),
49 authors_(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  */
145  friend class JournalArticleFactory;
147  StringKey title,
148 StringKey journal,
149 StringKey pubmed_id,
150 IntKey year,
151 StringsKey authors):
152  JournalArticleConst(nh, title,
153 journal,
154 pubmed_id,
155 year,
156 authors) {
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  */
253  Category cat_;
254 StringKey title_;
255 StringKey journal_;
256 StringKey pubmed_id_;
257 IntKey year_;
258 StringsKey authors_;
259 
260 
261 
262 
263 
264  public:
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  }
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_,
279 journal_,
280 pubmed_id_,
281 year_,
282 authors_);
283  }
284  /** Get a JournalArticle for nh.*/
285  JournalArticle get(NodeHandle nh) const {
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_,
290 journal_,
291 pubmed_id_,
292 year_,
293 authors_);
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
312 struct 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 */
327 RMF_DISABLE_WARNINGS
328 
329 #endif /* RMF_PUBLICATION_DECORATORS_H */
Mostly empty base classes for decorators and factories.
A handle for a particular node in the hierarchy.
Definition: NodeHandle.h:60
The base class for decorators.
Definition: Decorator.h:29
NodeType get_type() const
get the type of this node
Various constants.
A handle for a particular node in a read-only hierarchy.
A handle for a read-only RMF file.
std::vector< String > Strings
Definition: types.h:41
void set_value(ID< Tag > k, typename Tag::ArgumentType v) const
Definition: NodeHandle.h:115
A handle for an RMF file.
Definition: FileHandle.h:54
The base class for Factories.
Definition: Decorator.h:46
Declaration for RMF::FileHandle.
Represent coordinates.
Declaration of NodeHandle.
void set_static_value(ID< Tag > k, typename Tag::ArgumentType v) const
set the value of the attribute k for all frames.
Definition: NodeHandle.h:122
std::string String
Definition: types.h:39
ID< Tag > get_key(Category category, std::string name) const
int Int
Definition: types.h:29
bool get_is(NodeConstHandle nh) const
Definition: publication.h:297
Various general useful macros for IMP.
const NodeType ORGANIZATIONAL
A node that is purely there for organizational purposes.
void set_frame_value(ID< Tag > k, typename Tag::ArgumentType v) const
set the value of the attribute k for this node on the current frame.
Definition: NodeHandle.h:103