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-2011 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 #include <ost/mol/atom_handle.hh>
23 #include <ost/mol/chain_handle.hh>
25 
26 namespace ost { namespace conop {
27 
28 typedef enum {
34 } DiagArgType;
35 
36 typedef enum {
41 } DiagType;
42 
44 public:
45  Diag(DiagType typ, const char* fmt): type_(typ), format_(fmt) {}
46  DiagType GetType() const { return type_; }
47  Diag& AddAtom(mol::AtomHandle atom)
48  {
49  atoms_.push_back(atom);
50  args_.push_back(ArgDesc(atoms_.size()-1, DIAG_ARG_TYPE_ATOM));
51  return *this;
52  }
53 
54  Diag& AddResidue(mol::ResidueHandle res)
55  {
56  residues_.push_back(res);
57  args_.push_back(ArgDesc(residues_.size()-1, DIAG_ARG_TYPE_RESIDUE));
58  return *this;
59  }
60  Diag& AddChain(mol::ChainHandle chain)
61  {
62  chains_.push_back(chain);
63  args_.push_back(ArgDesc(chains_.size()-1, DIAG_ARG_TYPE_CHAIN));
64  return *this;
65  }
66  Diag& AddInt(int int_val)
67  {
68  ints_.push_back(int_val);
69  args_.push_back(ArgDesc(ints_.size()-1, DIAG_ARG_TYPE_INT));
70  return *this;
71  }
72  Diag& AddString(const String& str)
73  {
74  strings_.push_back(str);
75  args_.push_back(ArgDesc(strings_.size()-1, DIAG_ARG_TYPE_STRING));
76  return *this;
77  }
78  mol::AtomHandle GetAtom(size_t index) const
79  {
80  assert(index<args_.size());
81  return atoms_[args_[index].index];
82  }
83  mol::ResidueHandle GetResidue(size_t index) const
84  {
85  assert(index<args_.size());
86  return residues_[args_[index].index];
87  }
88  mol::ChainHandle GetChain(size_t index) const
89  {
90  assert(index<args_.size());
91  return chains_[args_[index].index];
92  }
93  String Format(bool colored=true) const;
94 private:
95  struct ArgDesc {
96  ArgDesc(size_t i, DiagArgType t): index(i), type(t) { }
97  size_t index;
98  DiagArgType type;
99  };
100  DiagType type_;
101  String format_;
102  mol::AtomHandleList atoms_;
103  mol::ResidueHandleList residues_;
104  mol::ChainHandleList chains_;
105  std::vector<String> strings_;
106  std::vector<int> ints_;
107  std::vector<ArgDesc> args_;
108 };
109 
111 public:
113 
115  {
116  for(std::vector<Diag*>::iterator
117  i=diags_.begin(), e=diags_.end(); i!=e;++i) {
118  delete *i;
119  }
120  }
121 
122  Diag& AddDiag(DiagType type, const char* fmt)
123  {
124  diags_.push_back(new Diag(type, fmt));
125  return *diags_.back();
126  }
127 
128  const std::vector<Diag*>& GetDiags() const { return diags_; }
129 private:
130  std::vector<Diag*> diags_;
131 };
132 
133 }} /* ost::conop */
134 #endif