Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Classes | Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
kome::objects::Variant Class Reference

class that treats data of various types More...

#include <Variant.h>

Collaboration diagram for kome::objects::Variant:
Collaboration graph
[legend]

Classes

union  PrimitiveType
 

Public Types

enum  DataType {
  UNKNOWN, BOOL, INTEGER, DOUBLE,
  STRING, ARRAY, PAIR, SAMPLE_SET,
  SAMPLE, SAMPLE_GETTER, SPECTRUM, DATA_SET,
  DATA_GROUP_NODE, CHROMATOGRAM, XY_DATA, PEAKS,
  PEAKS_2D, DRAWING_DATA, GRAPHICS, FONT,
  PROGRESS, MOUSE_EVT, KEY_EVT, DATA_MAP,
  SIZE_EVT, MOVE_EVT, WINDOW, SETTING_VALUES,
  SCRIPT, FILE_READER, OTHER
}
 

Public Member Functions

 Variant ()
 constructor
 
 Variant (const Variant &v)
 copy constructor More...
 
virtual ~Variant ()
 destructor
 
Variant & operator= (const Variant &other)
 substitution operator More...
 
void setString (const char *s)
 sets character string More...
 
char * getString ()
 gets character string More...
 
Variant * createArray (const unsigned int size)
 creates array More...
 
Variant * getArray ()
 gets array More...
 
Variant * getElement (const unsigned int index)
 gets element of the array More...
 
unsigned int getArraySize ()
 gets array size More...
 

Public Attributes

DataType type
 
union
kome::objects::Variant::PrimitiveType 
prim
 

Protected Member Functions

void deleteArray ()
 deletes array
 

Protected Attributes

void * arr
 

Detailed Description

class that treats data of various types

Definition at line 26 of file Variant.h.

Member Enumeration Documentation

data type

Definition at line 58 of file Variant.h.

58  {
59  UNKNOWN,
60  BOOL,
61  INTEGER,
62  DOUBLE,
63  STRING,
64  ARRAY,
65  PAIR,
66  SAMPLE_SET,
67  SAMPLE,
68  SAMPLE_GETTER,
69  SPECTRUM,
70  DATA_SET,
71  DATA_GROUP_NODE,
72  CHROMATOGRAM,
73  XY_DATA,
74  PEAKS,
75  PEAKS_2D,
76  DRAWING_DATA,
77  GRAPHICS,
78  FONT,
79  PROGRESS,
80  MOUSE_EVT,
81  KEY_EVT,
82  DATA_MAP,
83  SIZE_EVT,
84  MOVE_EVT,
85  WINDOW,
86  SETTING_VALUES,
87  SCRIPT,
88  FILE_READER,
89  OTHER
90  } DataType;

Constructor & Destructor Documentation

kome::objects::Variant::Variant ( const Variant &  v)

copy constructor

Parameters
[in]vvariant object to copy

Definition at line 37 of file Variant.cpp.

37  {
38  // copy member
39  prim = var.prim;
40  type = var.type;
41  arr = NULL;
42 
43  if( var.arr != NULL && var.prim.intVal > 0 ) {
44  int size = var.prim.intVal;
45  if( var.type == ARRAY ) {
46  arr = new Variant[ size ];
47  for( int i = 0; i < size; i++ ) {
48  ( (Variant*)arr )[ i ] = ( (Variant*)var.arr )[ i ];
49  }
50  }
51  else if( var.type == STRING ) {
52  arr = new char[ size ];
53  memcpy( arr, var.arr, size );
54  }
55 
56  prim.intVal = size;
57  }
58 }
#define NULL
Definition: CoreMacros.h:18
class that treats data of various types
Definition: Variant.h:26

Member Function Documentation

Variant * kome::objects::Variant::createArray ( const unsigned int  size)

creates array

Parameters
[in]sizearray size
Returns
new array

Definition at line 120 of file Variant.cpp.

120  {
121  // delete old array
122  deleteArray();
123 
124  // check parameter
125  if( size == 0 ) {
126  type = UNKNOWN;
127  return NULL;
128  }
129 
130  // type
131  type = ARRAY;
132 
133  // set size
134  prim.intVal = size;
135 
136  // create array
137  arr = new Variant[ size ];
138 
139  return getArray();
140 }
Variant * getArray()
gets array
Definition: Variant.cpp:143
void deleteArray()
deletes array
Definition: Variant.cpp:168
#define NULL
Definition: CoreMacros.h:18
class that treats data of various types
Definition: Variant.h:26

Here is the call graph for this function:

Variant * kome::objects::Variant::getArray ( )

gets array

Returns
the pointer to array

Definition at line 143 of file Variant.cpp.

143  {
144  return (Variant*)arr;
145 }
class that treats data of various types
Definition: Variant.h:26
unsigned int kome::objects::Variant::getArraySize ( )

gets array size

Returns
array size

Definition at line 158 of file Variant.cpp.

158  {
159  // check the member
160  if( arr == NULL ) {
161  return 0;
162  }
163 
164  return (unsigned int)prim.intVal;
165 }
#define NULL
Definition: CoreMacros.h:18
Variant * kome::objects::Variant::getElement ( const unsigned int  index)

gets element of the array

Parameters
[in]indexelement index
Returns
element of the array (If index is illegal, this method returns NULL.)

Definition at line 148 of file Variant.cpp.

148  {
149  // check parameter
150  if( index >= (unsigned int)prim.intVal ) {
151  return NULL;
152  }
153 
154  return ( getArray() + index );
155 }
Variant * getArray()
gets array
Definition: Variant.cpp:143
#define NULL
Definition: CoreMacros.h:18

Here is the call graph for this function:

char * kome::objects::Variant::getString ( )

gets character string

Returns
character string

Definition at line 115 of file Variant.cpp.

115  {
116  return (char*)arr;
117 }
Variant & kome::objects::Variant::operator= ( const Variant &  other)

substitution operator

Parameters
[in]othersource variant object
Returns
copied variant object

Definition at line 66 of file Variant.cpp.

66  {
67  // copy member
68  prim = other.prim;
69  type = other.type;
70  arr = NULL;
71 
72  if( other.arr != NULL && other.prim.intVal > 0 ) {
73  int size = other.prim.intVal;
74  if( other.type == ARRAY ) {
75  arr = new Variant[ size ];
76  for( int i = 0; i < size; i++ ) {
77  ( (Variant*)arr )[ i ] = ( (Variant*)other.arr )[ i ];
78  }
79  }
80  else if( other.type == STRING ) {
81  arr = new char[ size ];
82  memcpy( arr, other.arr, size );
83  }
84 
85  prim.intVal = size;
86  }
87 
88  return *this;
89 }
#define NULL
Definition: CoreMacros.h:18
class that treats data of various types
Definition: Variant.h:26
void kome::objects::Variant::setString ( const char *  s)

sets character string

Parameters
[in]scharacter string

Definition at line 92 of file Variant.cpp.

92  {
93  // delete old array
94  deleteArray();
95 
96  // check parameter
97  if( s == NULL ) {
98  type = UNKNOWN;
99  return;
100  }
101 
102  // set type
103  type = STRING;
104 
105  // create array
106  int size = strlen( s ) + 1;
107  arr = new char[ size ];
108  prim.intVal = size;
109 
110  // copy
111  memcpy( arr, s, size );
112 }
void deleteArray()
deletes array
Definition: Variant.cpp:168
#define NULL
Definition: CoreMacros.h:18

Here is the call graph for this function:

Member Data Documentation

void* kome::objects::Variant::arr
protected

array

Definition at line 105 of file Variant.h.

DataType kome::objects::Variant::type

data type

Definition at line 93 of file Variant.h.


The documentation for this class was generated from the following files: