OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
diag.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_CONOP_DIAG_HH
20 #define OST_CONOP_DIAG_HH
21 
22 #include <ost/mol/atom_handle.hh>
24 #include <ost/mol/chain_handle.hh>
26 
27 namespace ost { namespace conop {
28 
29 typedef enum {
35 } DiagArgType;
36 
37 typedef enum {
42 } DiagType;
43 
45 public:
46  Diag(DiagType typ, const char* fmt): type_(typ), format_(fmt) {}
47  DiagType GetType() const { return type_; }
49  {
50  atoms_.push_back(atom);
51  args_.push_back(ArgDesc(atoms_.size()-1, DIAG_ARG_TYPE_ATOM));
52  return *this;
53  }
54 
56  {
57  residues_.push_back(res);
58  args_.push_back(ArgDesc(residues_.size()-1, DIAG_ARG_TYPE_RESIDUE));
59  return *this;
60  }
62  {
63  chains_.push_back(chain);
64  args_.push_back(ArgDesc(chains_.size()-1, DIAG_ARG_TYPE_CHAIN));
65  return *this;
66  }
67  Diag& AddInt(int int_val)
68  {
69  ints_.push_back(int_val);
70  args_.push_back(ArgDesc(ints_.size()-1, DIAG_ARG_TYPE_INT));
71  return *this;
72  }
73  Diag& AddString(const String& str)
74  {
75  strings_.push_back(str);
76  args_.push_back(ArgDesc(strings_.size()-1, DIAG_ARG_TYPE_STRING));
77  return *this;
78  }
79  mol::AtomHandle GetAtom(size_t index) const
80  {
81  assert(index<args_.size());
82  return atoms_[args_[index].index];
83  }
84  mol::ResidueHandle GetResidue(size_t index) const
85  {
86  assert(index<args_.size());
87  return residues_[args_[index].index];
88  }
89  mol::ChainHandle GetChain(size_t index) const
90  {
91  assert(index<args_.size());
92  return chains_[args_[index].index];
93  }
94  String Format(bool colored=true) const;
95 private:
96  struct ArgDesc {
97  ArgDesc(size_t i, DiagArgType t): index(i), type(t) { }
98  size_t index;
99  DiagArgType type;
100  };
101  DiagType type_;
102  String format_;
103  mol::AtomHandleList atoms_;
104  mol::ResidueHandleList residues_;
105  mol::ChainHandleList chains_;
106  std::vector<String> strings_;
107  std::vector<int> ints_;
108  std::vector<ArgDesc> args_;
109 };
110 
112 
113 typedef boost::shared_ptr<Diagnostics> DiagnosticsPtr;
114 
115 
116 class DLLEXPORT DiagError : public Error {
117 public:
118  DiagError(const Diag& diag) : Error(diag.Format(false)) {}
119 };
120 
122 public:
123  typedef std::vector<Diag*>::iterator diag_iterator;
124  typedef std::vector<Diag*>::const_iterator const_diag_iterator;
126 
128  {
129  for(std::vector<Diag*>::iterator
130  i=diags_.begin(), e=diags_.end(); i!=e;++i) {
131  delete *i;
132  }
133  }
134 
135  Diag& AddDiag(DiagType type, const char* fmt)
136  {
137  diags_.push_back(new Diag(type, fmt));
138  return *diags_.back();
139  }
140  diag_iterator diags_begin() { return diags_.begin(); }
141  diag_iterator diags_end() { return diags_.end(); }
142  const_diag_iterator diags_begin() const { return diags_.begin(); }
143  const_diag_iterator diags_end() const { return diags_.end(); }
144  size_t diag_count() const { return diags_.size(); }
145 private:
146  std::vector<Diag*> diags_;
147 };
148 
149 }} /* ost::conop */
150 #endif
Diag & AddDiag(DiagType type, const char *fmt)
Definition: diag.hh:135
std::vector< Diag * >::const_iterator const_diag_iterator
Definition: diag.hh:124
DiagType
Definition: diag.hh:37
Diag & AddAtom(mol::AtomHandle atom)
Definition: diag.hh:48
std::string String
Definition: base.hh:54
Handle to atom datatype.
Definition: atom_handle.hh:37
size_t diag_count() const
Definition: diag.hh:144
#define DLLEXPORT_OST_CONOP
const_diag_iterator diags_end() const
Definition: diag.hh:143
diag_iterator diags_begin()
Definition: diag.hh:140
boost::shared_ptr< Diagnostics > DiagnosticsPtr
Definition: diag.hh:111
DiagError(const Diag &diag)
Definition: diag.hh:118
std::vector< ResidueHandle > ResidueHandleList
Diag & AddString(const String &str)
Definition: diag.hh:73
std::vector< Diag * >::iterator diag_iterator
Definition: diag.hh:123
const_diag_iterator diags_begin() const
Definition: diag.hh:142
Diag & AddInt(int int_val)
Definition: diag.hh:67
linear chain of residues
Definition: chain_handle.hh:52
DiagType GetType() const
Definition: diag.hh:47
Diag(DiagType typ, const char *fmt)
Definition: diag.hh:46
DiagArgType
Definition: diag.hh:29
Diag & AddResidue(mol::ResidueHandle res)
Definition: diag.hh:55
std::vector< AtomHandle > AtomHandleList
mol::ChainHandle GetChain(size_t index) const
Definition: diag.hh:89
mol::ResidueHandle GetResidue(size_t index) const
Definition: diag.hh:84
Diag & AddChain(mol::ChainHandle chain)
Definition: diag.hh:61
mol::AtomHandle GetAtom(size_t index) const
Definition: diag.hh:79
std::vector< ChainHandle > ChainHandleList
diag_iterator diags_end()
Definition: diag.hh:141