00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef OST_CONOP_DIAG_HH
00020 #define OST_CONOP_DIAG_HH
00021
00022 #include <ost/mol/atom_handle.hh>
00023 #include <ost/mol/residue_handle.hh>
00024 #include <ost/mol/chain_handle.hh>
00025 #include <ost/conop/module_config.hh>
00026
00027 namespace ost { namespace conop {
00028
00029 typedef enum {
00030 DIAG_ARG_TYPE_ATOM,
00031 DIAG_ARG_TYPE_RESIDUE,
00032 DIAG_ARG_TYPE_CHAIN,
00033 DIAG_ARG_TYPE_STRING,
00034 DIAG_ARG_TYPE_INT
00035 } DiagArgType;
00036
00037 typedef enum {
00038 DIAG_UNK_ATOM,
00039 DIAG_UNK_RESIDUE,
00040 DIAG_MISSING_ATOM,
00041 DIAG_NONSTD_RESIDUE
00042 } DiagType;
00043
00044 class DLLEXPORT_OST_CONOP Diag {
00045 public:
00046 Diag(DiagType typ, const char* fmt): type_(typ), format_(fmt) {}
00047 DiagType GetType() const { return type_; }
00048 Diag& AddAtom(mol::AtomHandle atom)
00049 {
00050 atoms_.push_back(atom);
00051 args_.push_back(ArgDesc(atoms_.size()-1, DIAG_ARG_TYPE_ATOM));
00052 return *this;
00053 }
00054
00055 Diag& AddResidue(mol::ResidueHandle res)
00056 {
00057 residues_.push_back(res);
00058 args_.push_back(ArgDesc(residues_.size()-1, DIAG_ARG_TYPE_RESIDUE));
00059 return *this;
00060 }
00061 Diag& AddChain(mol::ChainHandle chain)
00062 {
00063 chains_.push_back(chain);
00064 args_.push_back(ArgDesc(chains_.size()-1, DIAG_ARG_TYPE_CHAIN));
00065 return *this;
00066 }
00067 Diag& AddInt(int int_val)
00068 {
00069 ints_.push_back(int_val);
00070 args_.push_back(ArgDesc(ints_.size()-1, DIAG_ARG_TYPE_INT));
00071 return *this;
00072 }
00073 Diag& AddString(const String& str)
00074 {
00075 strings_.push_back(str);
00076 args_.push_back(ArgDesc(strings_.size()-1, DIAG_ARG_TYPE_STRING));
00077 return *this;
00078 }
00079 mol::AtomHandle GetAtom(size_t index) const
00080 {
00081 assert(index<args_.size());
00082 return atoms_[args_[index].index];
00083 }
00084 mol::ResidueHandle GetResidue(size_t index) const
00085 {
00086 assert(index<args_.size());
00087 return residues_[args_[index].index];
00088 }
00089 mol::ChainHandle GetChain(size_t index) const
00090 {
00091 assert(index<args_.size());
00092 return chains_[args_[index].index];
00093 }
00094 String Format(bool colored=true) const;
00095 private:
00096 struct ArgDesc {
00097 ArgDesc(size_t i, DiagArgType t): index(i), type(t) { }
00098 size_t index;
00099 DiagArgType type;
00100 };
00101 DiagType type_;
00102 String format_;
00103 mol::AtomHandleList atoms_;
00104 mol::ResidueHandleList residues_;
00105 mol::ChainHandleList chains_;
00106 std::vector<String> strings_;
00107 std::vector<int> ints_;
00108 std::vector<ArgDesc> args_;
00109 };
00110
00111 class Diagnostics;
00112
00113 typedef boost::shared_ptr<Diagnostics> DiagnosticsPtr;
00114
00115
00116 class DLLEXPORT DiagError : public Error {
00117 public:
00118 DiagError(const Diag& diag) : Error(diag.Format(false)) {}
00119 };
00120
00121 class DLLEXPORT_OST_CONOP Diagnostics {
00122 public:
00123 typedef std::vector<Diag*>::iterator diag_iterator;
00124 typedef std::vector<Diag*>::const_iterator const_diag_iterator;
00125 Diagnostics() {}
00126
00127 ~Diagnostics()
00128 {
00129 for(std::vector<Diag*>::iterator
00130 i=diags_.begin(), e=diags_.end(); i!=e;++i) {
00131 delete *i;
00132 }
00133 }
00134
00135 Diag& AddDiag(DiagType type, const char* fmt)
00136 {
00137 diags_.push_back(new Diag(type, fmt));
00138 return *diags_.back();
00139 }
00140 diag_iterator diags_begin() { return diags_.begin(); }
00141 diag_iterator diags_end() { return diags_.end(); }
00142 const_diag_iterator diags_begin() const { return diags_.begin(); }
00143 const_diag_iterator diags_end() const { return diags_.end(); }
00144 size_t diag_count() const { return diags_.size(); }
00145 private:
00146 std::vector<Diag*> diags_;
00147 };
00148
00149 }}
00150 #endif