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 
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_;
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;
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:
86  cat_(fh.get_category("external")),
87  path_(fh.get_key<StringTag>(cat_, "path")) {
88  }
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.*/
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 */
Mostly empty base classes for decorators and factories.
const NodeType REPRESENTATION
Represent part of a molecule.
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.
bool get_is(NodeConstHandle nh) const
Definition: external.h:109
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.
std::string String
Definition: types.h:39
ID< Tag > get_key(Category category, std::string name) const
Various general useful macros for IMP.