RMF
alias.h
Go to the documentation of this file.
1 /**
2  * \file RMF/decorator/alias.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_ALIAS_DECORATORS_H
10 #define RMF_ALIAS_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 Alias and AliasFactory.
29  */
30  class AliasConst: public Decorator {
31  friend class AliasFactory;
32  protected:
33  IntKey aliased_;
35  IntKey aliased):
36  Decorator(nh),
37 aliased_(aliased) {
38  }
39  public:
40 
41  NodeConstHandle get_aliased() const {
42  try {
43  int id = get_node().get_value(aliased_);
44  return get_node().get_file().get_node(NodeID(id));
45  } RMF_DECORATOR_CATCH( );
46  }
47 
48  static std::string get_decorator_type_name() {
49  return "AliasConst";
50  }
51  RMF_SHOWABLE(AliasConst, "Alias: " << get_node());
52  };
53  /** See also AliasFactory.
54  */
55  class Alias: public AliasConst {
56  friend class AliasFactory;
57  Alias(NodeHandle nh,
58  IntKey aliased):
59  AliasConst(nh, aliased) {
60  }
61  public:
62 
63  void set_aliased(NodeConstHandle v) {
64  try {
65  get_node().set_value(aliased_, v.get_id().get_index());
66  } RMF_DECORATOR_CATCH( );
67  }
68 
69  static std::string get_decorator_type_name() {
70  return "Alias";
71  }
72  };
73 
74 
75  /** Create decorators of type Alias.
76  */
77  class AliasFactory: public Factory {
78  Category cat_;
79 IntKey aliased_;
80 
81  public:
83  cat_(fh.get_category("alias")),
84  aliased_(fh.get_key<IntTag>(cat_, "aliased")) {
85  }
87  cat_(fh.get_category("alias")),
88  aliased_(fh.get_key<IntTag>(cat_, "aliased")) {
89  }
90  /** Get a AliasConst for nh.*/
91  AliasConst get(NodeConstHandle nh) const {
92  RMF_USAGE_CHECK((nh.get_type() == RMF::ALIAS), std::string("Bad node type. Got \"")
93  + boost::lexical_cast<std::string>(nh.get_type())
94  + "\" in decorator type Alias");
95  return AliasConst(nh, aliased_);
96  }
97  /** Get a Alias for nh.*/
98  Alias get(NodeHandle nh) const {
99  RMF_USAGE_CHECK((nh.get_type() == RMF::ALIAS), std::string("Bad node type. Got \"")
100  + boost::lexical_cast<std::string>(nh.get_type())
101  + "\" in decorator type Alias");
102  return Alias(nh, aliased_);
103  }
104  /** Check whether nh has all the attributes required to be a
105  AliasConst.*/
106  bool get_is(NodeConstHandle nh) const {
107  return (nh.get_type() == RMF::ALIAS)
108  && !nh.get_value(aliased_).get_is_null();
109  }
110  bool get_is_static(NodeConstHandle nh) const {
111  return (nh.get_type() == RMF::ALIAS)
112  && !nh.get_static_value(aliased_).get_is_null();
113  }
114  RMF_SHOWABLE(AliasFactory, "AliasFactory");
115  };
116  #ifndef RMF_DOXYGEN
117 struct AliasConstFactory: public AliasFactory {
118  AliasConstFactory(FileConstHandle fh):
119  AliasFactory(fh) {
120  }
121  AliasConstFactory(FileHandle fh):
122  AliasFactory(fh) {
123  }
124 
125 };
126  #endif
127 
128 
129 
130 } /* namespace decorator */
131 } /* namespace RMF */
132 RMF_DISABLE_WARNINGS
133 
134 #endif /* RMF_ALIAS_DECORATORS_H */
bool get_is(NodeConstHandle nh) const
Definition: alias.h:106
Mostly empty base classes for decorators and factories.
NodeID get_id() const
const NodeType ALIAS
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.
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
ID< NodeTag > NodeID
Definition: ID.h:106
Declaration for RMF::FileHandle.
Represent coordinates.
Declaration of NodeHandle.
ID< Tag > get_key(Category category, std::string name) const
Various general useful macros for IMP.
NodeHandle get_node(NodeID id) const
Return a NodeHandle from a NodeID.