1 /**
2 * \file RMF/validate.h
3 * \brief Support for validating the data in a file.
4 *
5 * Copyright 2007-2021 IMP Inventors. All rights reserved.
6 *
7 */
8
9 #include <ostream>
10 #include <string>
11 #include <utility>
12 #include <vector>
13
14 #include "RMF/FileConstHandle.h"
15 #include "RMF/NodeConstHandle.h"
16 #include "RMF/validate.h"
17 #include "RMF/compiler_macros.h"
18 #include "RMF/log.h"
19 #include "RMF/decorator/physics.h"
20 #include "RMF/decorator/shape.h"
21 #include "RMF/decorator/sequence.h"
22 RMF_ENABLE_WARNINGS
23 namespace RMF {
24 namespace {
validate_impl(NodeConstHandle cur,decorator::ParticleFactory pcf,decorator::ResidueFactory rcf,decorator::AtomFactory acf)25 bool validate_impl(NodeConstHandle cur, decorator::ParticleFactory pcf,
26 decorator::ResidueFactory rcf, decorator::AtomFactory acf) {
27 NodeConstHandles ch = cur.get_children();
28 bool ret = true;
29 if (ch.empty() && cur.get_type() == REPRESENTATION) {
30 if (!pcf.get_is(cur)) {
31 RMF_WARN("Leaf is not a particle at " << cur.get_name());
32 ret = false;
33 }
34 }
35 RMF_FOREACH(NodeConstHandle c, ch) {
36 ret = ret && validate_impl(c, pcf, rcf, acf);
37 }
38 return ret;
39 }
40 } // namespace
validate(FileConstHandle fh)41 void validate(FileConstHandle fh) {
42 decorator::ParticleFactory pcf(fh);
43 decorator::ResidueFactory rcf(fh);
44 decorator::AtomFactory acf(fh);
45 bool ok = validate_impl(fh.get_root_node(), pcf, rcf, acf);
46 if (!ok) {
47 RMF_THROW(Message("Invalid hierarchy"), IOException);
48 }
49 }
50
51 } /* namespace RMF */
52
53 RMF_DISABLE_WARNINGS
54