NCBI C++ ToolKit
object_list.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_OBJECT_LIST___OBJECT_LIST__HPP
2 #define GUI_WIDGETS_OBJECT_LIST___OBJECT_LIST__HPP
3 
4 /* $Id: object_list.hpp 29715 2014-02-03 14:08:58Z voronov $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Andrey Yazhuk, Yury Voronov
30  *
31  * File Description:
32  *
33  */
34 
35 #include <gui/gui_export.h>
36 #include <corelib/ncbiobj.hpp>
37 
38 #include <objmgr/scope.hpp>
39 
40 #include <gui/objutils/objects.hpp>
41 #include <gui/objutils/label.hpp>
42 
44 
45 /////////////////////////////////////////////////////////////////
46 /// CObjectListException
47 ///
50 {
51 public:
53 };
54 
55 
56 /////////////////////////////////////////////////////////////////
57 /// CObjectList
58 /// Data structure representing a list of CObjects with associated
59 /// Scopes and other optional attributes (strings and numbers)
60 ///
62  : public CObject
63 {
64 public:
65  enum EColumnType {
66  eInvalid = -1,
71  eDouble
72  };
73  struct _CColumn {
74 
75  _CColumn( EColumnType type, const string& name )
76  : m_Name( name ), m_Type( type )
77  {}
78 
79  //-------
80 
81  string m_Name;
82  /// actually column can be of types eString, eInteger, eDouble
84 
85  /// actually it is a reference to wxArrayString, wxArrayInt, or wxArrayDouble
87 
88  const vector<int>& IntVector() const;
89  vector<int>& IntVector();
90  void IntVector( int size );
91 
92  const vector<double>& DoubleVector() const;
93  vector<double>& DoubleVector();
94  void DoubleVector( int size );
95 
96  const vector<string>& StringVector() const;
97  vector<string>& StringVector();
98  void StringVector( int size );
99 
100  /*
101  vector< CRef<CObject> >& GetVectorObject();
102  const vector< CRef<CObject> >& GetVectorObject() const;
103  */
104  };
105 
106 
107 public:
108  CObjectList();
109  CObjectList( const CObjectList& ob_list );
110 
111  virtual ~CObjectList();
112 
113  /// initializers
115 
116  /// adds rows from the given list, the lists must have identical sets of columns
117  void Append( const CObjectList& list );
118  int AddRow( CObject* obj, objects::CScope* scope );
119 
120  int AddColumn( EColumnType type, const string& name, int col = -1 );
121  void DeleteColumn( int col );
122 
123  /// access to columns (attribute, indexes)
124  int GetNumColumns() const;
125  EColumnType GetColumnType( int col ) const;
126  const string& GetColumnName( int col ) const;
127 
128  int GetColStartIx() const { return m_StartIx; }
129  void SetColStartIx( int ix ){ m_StartIx = ix; }
130  void ClearColStartIx(){ m_StartIx = -1; }
131 
132  int GetNumRows() const;
133 
134  /// access to values (row, column)
135  CObject* GetObject( int row );
136  const CObject* GetObject( int row ) const;
137  void SetObject( int row, CObject& obj );
138 
139  objects::CScope* GetScope( int row );
140  const objects::CScope* GetScope(int row ) const;
141  void SetScope( int row, objects::CScope& sc );
142 
143  const string& GetString( int col, int row ) const;
144  void SetString( int col, int row, const string& val );
145 
146  int GetInteger( int col, int row ) const;
147  void SetInteger( int col, int row, int val );
148 
149  double GetDouble( int col, int row ) const;
150  void SetDouble( int col, int row, double val );
151 
152  /// access to a set of extra columns
153  int GetNumObjectLabels() const { return (int)m_ExtraColName.size(); }
154  string GetObjectLabelName( int col ) const;
155  CLabel::ELabelType GetObjectLabelType( int col ) const;
156  void SetObjectLabel( int col, const string& name, CLabel::ELabelType type );
157  void AddObjectLabel( const string& name, CLabel::ELabelType type ){
158  SetObjectLabel( -1, name, type );
159  }
160  void RemoveObjectLabel( int col );
161 
162 
163  void ClearRows(); /// removes all data rows (i.e. objects)
164  void ClearColumns() { m_Columns.clear(); } // remove all extra columns
166  m_ExtraColName.clear();
167  m_ExtraColType.clear();
168  }
169  void Clear(); /// removes all rows and non-standard columns
170 
171 protected:
172  void x_Init();
173  void x_Clear();
174 
175  inline void x_AssertValidLabel( int col ) const;
176  inline void x_AssertValidColumn( int col ) const;
177  inline void x_AssertValidRow( int row ) const;
178  inline void x_AssertValid( int col, int row ) const;
179 
180 protected:
181  /// all columns must be of the same size
182  vector< CRef<CObject> > m_Objects; /// Objects column
183  vector< CRef<objects::CScope> > m_Scopes; /// Scopes column, may contain NULLs
184 
185  typedef vector<_CColumn> TColumns;
186  TColumns m_Columns; /// all columns
187 
188 protected:
189  vector<string> m_ExtraColName;
190  vector<CLabel::ELabelType> m_ExtraColType;
192 };
193 
195 
196 #endif // GUI_WIDGETS_OBJECT_LIST___OBJECT_LIST__HPP
CObjectListException.
Definition: object_list.hpp:50
NCBI_EXCEPTION_DEFAULT(CObjectListException, CException)
CObjectList Data structure representing a list of CObjects with associated Scopes and other optional ...
Definition: object_list.hpp:63
int GetColStartIx() const
void AddObjectLabel(const string &name, CLabel::ELabelType type)
vector< CRef< objects::CScope > > m_Scopes
Objects column.
void ClearObjectLabels()
void ClearColumns()
removes all data rows (i.e. objects)
vector< CRef< CObject > > m_Objects
all columns must be of the same size
vector< string > m_ExtraColName
all columns
int GetNumObjectLabels() const
access to a set of extra columns
void ClearColStartIx()
vector< _CColumn > TColumns
Scopes column, may contain NULLs.
vector< CLabel::ELabelType > m_ExtraColType
TColumns m_Columns
void SetColStartIx(int ix)
CObject –.
Definition: ncbiobj.hpp:180
static void Init(void)
Definition: cursor6.c:76
virtual void x_Init(const CDiagCompileInfo &info, const string &message, const CException *prev_exception, EDiagSev severity)
Helper method for initializing exception data.
Definition: ncbiexpt.cpp:509
#define EXCEPTION_VIRTUAL_BASE
Do not use virtual base classes in exception declaration at all, because in this case derived class s...
Definition: ncbiexpt.hpp:1388
ELabelType
Definition: label.hpp:60
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIOBJUTILS_EXPORT
Definition: gui_export.h:512
Defines to provide correct exporting from DLLs in Windows.
const struct ncbi::grid::netcache::search::fields::SIZE size
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
#define row(bind, expected)
Definition: string_bind.c:73
CRef< CObject > m_ValuesRef
actually it is a reference to wxArrayString, wxArrayInt, or wxArrayDouble
Definition: object_list.hpp:86
EColumnType m_Type
actually column can be of types eString, eInteger, eDouble
Definition: object_list.hpp:83
_CColumn(EColumnType type, const string &name)
Definition: object_list.hpp:75
Definition: type.c:6
static bool SetInteger(wxSpinCtrl *spinctrl, int value)
static bool GetInteger(wxSpinCtrl *spinctrl, int *value)
CScope & GetScope()
Modified on Wed Jul 24 17:15:10 2024 by modify_doxy.py rev. 669887