NCBI C++ ToolKit
structure_base.hpp

Search Toolkit Book for ure_base_8hpp_source

Go to the documentation of this file.
1 /* $Id: structure_base.hpp 33815 2007-05-04 17:18:18Z kazimird $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Authors: Paul Thiessen
27 *
28 * File Description:
29 * Base class for objects that will hold structure data
30 *
31 * ===========================================================================
32 */
33 
34 #ifndef CN3D_STRUCTUREBASE__HPP
35 #define CN3D_STRUCTUREBASE__HPP
36 
37 #include <corelib/ncbistl.hpp>
38 #include <corelib/ncbidiag.hpp>
39 
40 #include <list>
41 
42 
43 BEGIN_SCOPE(Cn3D)
44 
45 class StructureSet;
46 class AtomSet;
47 
49 {
50 public:
51  // will store StructureBase-derived children in parent upon construction
53 
54  // will automatically delete children upon destruction with this destructor.
55  // But note that derived classes can have their own constructors that will
56  // *also* be called upon deletion; derived class destructors should *not*
57  // delete any StructureBase-derived objects.
58  virtual ~StructureBase(void);
59 
60  // overridable default Draws the object and all its children; 'data' will
61  // be passed along to self and children's Draw methods
62  virtual bool DrawAll(const AtomSet *atomSet = NULL) const;
63 
64  // function to draw this object, called before children are Drawn. Return
65  // false to halt recursive drawing process. An AtomSet can be passed along
66  // for cases (e.g. NMR structures) where a graph can be applied to multiple
67  // sets of atom coordinates
68  virtual bool Draw(const AtomSet *atomSet = NULL) const { return true; }
69 
70  // for convenience/efficiency accessing stuff attached to StructureSet
72 
73 private:
74  // no default construction
76  // keep track of StructureBase-derived children, so that top-down operations
77  // like drawing or deconstructing can trickle down automatically
78  typedef std::list < StructureBase * > _ChildList;
80  void _AddChild(StructureBase *child);
81  void _RemoveChild(const StructureBase *child);
82 
83  // also keep parent so we can move up the tree (see GetParentOfType())
85 
86 public:
87  // go up the hierarchy to find a parent of the desired type
88  template < class T >
89  bool GetParentOfType(const T* *ptr, bool warnIfNotFound = true) const
90  {
91  *ptr = NULL;
92  for (const StructureBase *parent=this->_parent; parent; parent=parent->_parent) {
93  if ((*ptr = dynamic_cast<const T*>(parent)) != NULL) {
94  return true;
95  }
96  }
97  if (warnIfNotFound)
98  ERR_POST(ncbi::Warning << "can't get parent of requested type");
99  return false;
100  }
101 };
102 
103 
104 // for convenience when passing around atom pointers
105 class AtomPntr
106 {
107 public:
108  static const int NO_ID;
109  int mID, rID, aID;
110 
111  AtomPntr(int m = NO_ID, int r = NO_ID, int a = NO_ID) : mID(m), rID(r), aID(a) { }
113  { mID = a.mID; rID = a.rID; aID = a.aID; return *this; }
114 };
115 
116 
117 END_SCOPE(Cn3D)
118 
119 #endif // CN3D_STRUCTUREBASE__HPP
AtomPntr & operator=(const AtomPntr &a)
static const int NO_ID
AtomPntr(int m=NO_ID, int r=NO_ID, int a=NO_ID)
virtual bool DrawAll(const AtomSet *atomSet=NULL) const
_ChildList _children
StructureBase * _parent
void _RemoveChild(const StructureBase *child)
StructureBase(void)
virtual bool Draw(const AtomSet *atomSet=NULL) const
StructureSet * parentSet
bool GetParentOfType(const T **ptr, bool warnIfNotFound=true) const
std::list< StructureBase * > _ChildList
virtual ~StructureBase(void)
void _AddChild(StructureBase *child)
#define T(s)
Definition: common.h:230
#define NULL
Definition: ncbistd.hpp:225
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
unsigned int a
Definition: ncbi_localip.c:102
Defines NCBI C++ diagnostic APIs, classes, and macros.
The NCBI C++/STL use hints.
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
Modified on Sat Dec 02 09:22:47 2023 by modify_doxy.py rev. 669887