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

Go to the SVN repository for this file.

1 #ifndef GUI_GRAPH___IGRAPH_DATA__HPP
2 #define GUI_GRAPH___IGRAPH_DATA__HPP
3 
4 /* $Id: igraph_data.hpp 23960 2011-06-24 15:46:45Z wuliangs $
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
30  *
31  * File Description:
32  *
33  */
34 
35 #include <corelib/ncbistl.hpp>
36 
37 #include <gui/graph/igraph.hpp>
38 
39 /** @addtogroup GUI_GRAPH
40  *
41  * @{
42  */
43 
45 
46 ///////////////////////////////////////////////////////////////////////////////
47 /// interface IDataArray
48 
50 {
51 public:
52  enum EDataType {
56  ePointer
57  };
58 
59  virtual ~IDataArray();
60  virtual EDataType GetType() = 0;
61  virtual size_t GetSize() = 0;
62 };
63 
64 ///////////////////////////////////////////////////////////////////////////////
65 /// class STypeSelector
66 // this class is used to define TValueType based on EDataType
67 
68 template <IDataArray::EDataType Type>
69 struct STypeSelector {
70 };
71 
72 template<> struct STypeSelector<IDataArray::eNumeric> {
74 };
75 template<> struct STypeSelector<IDataArray::eString> {
76  typedef string TValueType;
77 };
78 template<> struct STypeSelector<IDataArray::eColor> {
80 };
81 template<> struct STypeSelector<IDataArray::ePointer> {
82  typedef void* TValueType;
83 };
84 
85 ///////////////////////////////////////////////////////////////////////////////
86 /// class ITypedDataArray<Type>
87 
88 template <IDataArray::EDataType Type>
90 {
91 public:
93 
94  virtual EDataType GetType() { return Type; }
95  virtual size_t GetSize() = 0;
96  virtual TValueType GetElem(size_t i) = 0; // returns value of specialized type
97 };
98 
99 // specializations for various EDataTypes
100 
105 
106 ///////////////////////////////////////////////////////////////////////////////
107 /// class CTypedArrayAdapter<Type, TBase>
108 
109 template <IDataArray::EDataType Type,
110  typename TBase =
111 #ifndef NCBI_COMPILER_MSVC
112  typename
113 #endif
115  class CTypedArrayAdapter : public ITypedDataArray<Type>
116 {
117 public:
119  typedef vector<TBase> TCont;
120 
122  CTypedArrayAdapter(int Length) { m_vValues.resize(Length); }
123 
124  // ITypedDataArray<Type> implementation
125  virtual size_t GetSize() { return m_vValues.size(); }
126  virtual TValueType GetElem(size_t i)
127  {
128  _ASSERT(i < m_vValues.size());
129  return (TValueType) m_vValues[i];
130  };
131 
132  TCont& GetContainer() { return m_vValues; }
133  const TCont& GetContainer() const { return m_vValues; }
134 
135 protected:
137 };
138 
139 ///////////////////////////////////////////////////////////////////////////////
140 /// class CSeriesBase
141 /// CSeries represents a set of colinear IDataArrays and provides basic access and management.
142 /// All arrays must have the same length.
144 {
145 public:
147 
148  virtual ~CSeriesBase();
149 
150  // user interface for accessing data
151  int GetLength() const;
152  size_t GetArraysCount() const;
153 
154  EDataType GetArrayType(size_t iArray) const;
155  IDataArray* GetArray(size_t iArray) const;
156 
157  //string GetArrayName(int iArray) const;
158  //int GetIndexByName(const string& Name);
159 protected:
160  // DataArray management interface provided for derived classes
161  CSeriesBase();
162  CSeriesBase(int Length);
163 
164  virtual void CreateArrays();
165  virtual void CreateArrays(int Length);
166 
167  // CSeriesBase owns IDataArray-s added to series, destructor will destroy them
168  void AddArray(/*const string& Name,*/ IDataArray* pArray);
169  void InsertArray(size_t iArray,/*const string& Name,*/ IDataArray* pArray);
170  //void RemoveArray(int iArray);
171  void RemoveAllArrays();
172 
173  // type-safe functions returning specialized arrays
174  INumericArray* x_GetNumericArray(size_t iArray);
175  IStringArray* x_GetStringArray(size_t iArray);
176  IColorArray* x_GetColorArray(size_t iArray);
177  IPointerArray* x_GetPointerArray(size_t iArray);
178 
179 protected:
180  vector<IDataArray*> m_vpArrays;
182  int m_Length;
183 };
184 
185 
187 
188 #endif
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
class CSeriesBase CSeries represents a set of colinear IDataArrays and provides basic access and mana...
class CTypedArrayAdapter<Type, TBase>
interface IDataArray
Definition: igraph_data.hpp:50
class ITypedDataArray<Type>
Definition: igraph_data.hpp:90
ITypedDataArray< Type >::TValueType TValueType
virtual size_t GetSize()
ITypedDataArray< IDataArray::eString > IStringArray
IDataArray::EDataType EDataType
const TCont & GetContainer() const
ITypedDataArray< IDataArray::eColor > IColorArray
vector< TBase > TCont
virtual size_t GetSize()=0
virtual size_t GetSize()=0
virtual EDataType GetType()=0
vector< IDataArray * > m_vpArrays
virtual EDataType GetType()
Definition: igraph_data.hpp:94
ITypedDataArray< IDataArray::eNumeric > INumericArray
virtual TValueType GetElem(size_t i)
STypeSelector< Type >::TValueType TValueType
Definition: igraph_data.hpp:92
CTypedArrayAdapter(int Length)
ITypedDataArray< IDataArray::ePointer > IPointerArray
TCont & GetContainer()
virtual TValueType GetElem(size_t i)=0
map< string, int > m_mpNameToIndex
GLdouble TModelUnit
Definition: gltypes.hpp:48
TSeqPos GetLength(const CSeq_id &id, CScope *scope)
Get sequence length if scope not null, else return max possible TSeqPos.
#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_GUIGRAPH_EXPORT
Definition: gui_export.h:510
int i
The NCBI C++/STL use hints.
class STypeSelector
Definition: igraph_data.hpp:69
#define _ASSERT
#define Type
@ eNumeric
Definition: text_util.cpp:53
Modified on Wed Jun 19 17:03:35 2024 by modify_doxy.py rev. 669887