Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
kome::core::Selector Class Referenceabstract

selector class More...

#include <Selector.h>

Inheritance diagram for kome::core::Selector:
Inheritance graph
[legend]

Public Member Functions

 Selector ()
 constructor
 
virtual ~Selector ()
 destructor
 
void clearItems ()
 clear items
 
void addItem (const char *name)
 adds item More...
 
void addItem (const char *name, const char *value)
 adds item More...
 
unsigned int getNumberOfItems ()
 gets the number of items More...
 
const char * getItemName (const unsigned int index)
 gets item name More...
 
const char * getItemValue (const unsigned int index)
 gets item value More...
 
bool isSelected (const unsigned int index)
 gets selection flag value More...
 
int getSelection ()
 [in] gets selected item More...
 
bool select ()
 selects item More...
 

Protected Member Functions

virtual bool onSelect (const unsigned int num, const char **items, const char **values, bool *selected)=0
 This method is called by select method. (abstract method) More...
 

Protected Attributes

std::vector< std::pair
< std::string, std::string > > 
m_items
 
std::vector< bool > m_selected
 
int m_sel
 

Detailed Description

selector class

Definition at line 28 of file Selector.h.

Member Function Documentation

void kome::core::Selector::addItem ( const char *  name)

adds item

Parameters
[in]nameitem name

Definition at line 43 of file Selector.cpp.

43  {
44  addItem( name, name );
45 }
void addItem(const char *name)
adds item
Definition: Selector.cpp:43
void kome::core::Selector::addItem ( const char *  name,
const char *  value 
)

adds item

Parameters
[in]nameitem name
[in]valueitem value

Definition at line 48 of file Selector.cpp.

48  {
49  m_items.push_back( std::make_pair( NVL( name, "" ), NVL( value, "" ) ) );
50  m_selected.push_back( false );
51 }
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
std::vector< bool > m_selected
Definition: Selector.h:47
std::vector< std::pair< std::string, std::string > > m_items
Definition: Selector.h:44
const char * kome::core::Selector::getItemName ( const unsigned int  index)

gets item name

Parameters
[in]indexitem index
Returns
item name (If NULL, item index is illegal.)

Definition at line 59 of file Selector.cpp.

59  {
60  if( index >= m_items.size() ) {
61  return NULL;
62  }
63  return m_items[ index ].first.c_str();
64 }
#define NULL
Definition: CoreMacros.h:18
std::vector< std::pair< std::string, std::string > > m_items
Definition: Selector.h:44
const char * kome::core::Selector::getItemValue ( const unsigned int  index)

gets item value

Parameters
[in]indexitem index
Returns
item value (If NULL, item index is illegal.)

Definition at line 67 of file Selector.cpp.

67  {
68  if( index >= m_items.size() ) {
69  return NULL;
70  }
71  return m_items[ index ].second.c_str();
72 }
#define NULL
Definition: CoreMacros.h:18
std::vector< std::pair< std::string, std::string > > m_items
Definition: Selector.h:44
unsigned int kome::core::Selector::getNumberOfItems ( )

gets the number of items

Returns
the number of items

Definition at line 54 of file Selector.cpp.

54  {
55  return m_items.size();
56 }
std::vector< std::pair< std::string, std::string > > m_items
Definition: Selector.h:44
int kome::core::Selector::getSelection ( )

[in] gets selected item

Returns
selected item

Definition at line 83 of file Selector.cpp.

83  {
84  if( m_sel < 0 ) {
85  for( unsigned int i = 0; i < m_selected.size() && m_sel < 0; i++ ) {
86  if( m_selected[ i ] ) {
87  m_sel = i;
88  }
89  }
90  }
91 
92  return m_sel;
93 }
std::vector< bool > m_selected
Definition: Selector.h:47
bool kome::core::Selector::isSelected ( const unsigned int  index)

gets selection flag value

Parameters
[in]indexitem index
Returns
selectin flag value

Definition at line 75 of file Selector.cpp.

75  {
76  if( index >= m_selected.size() ) {
77  return false;
78  }
79  return m_selected[ index ];
80 }
std::vector< bool > m_selected
Definition: Selector.h:47
bool kome::core::Selector::onSelect ( const unsigned int  num,
const char **  items,
const char **  values,
bool *  selected 
)
protectedpure virtual

This method is called by select method. (abstract method)

Parameters
[in]numthe number of items
[in]itemsthe array of item names
[in]valuesthe array of item values
[out]selectedthe array to store selected flags
Returns
If true, the selection was normally done.

Implemented in kome::core::RangeListSelector, and kome::core::ManualSelector.

bool kome::core::Selector::select ( )

selects item

Returns
If true, the selection was normally done.

Definition at line 96 of file Selector.cpp.

96  {
97  // initialize
98  m_sel = -1;
99 
100  // create array
101  const char** items = NULL;
102  const char** values = NULL;
103  bool* selected = NULL;
104  unsigned int num = m_items.size();
105  if( num > 0 ) {
106  items = new const char*[ num ];
107  values = new const char*[ num ];
108  selected = new bool[ num ];
109 
110  for( unsigned int i = 0; i < num; i++ ) {
111  items[ i ] = m_items[ i ].first.c_str();
112  values[ i ] = m_items[ i ].second.c_str();
113  selected[ i ] = m_selected[ i ];
114  }
115  }
116 
117  // select
118  bool ret = onSelect( num, items, values, selected );
119  for( unsigned int i = 0; i < num; i++ ) {
120  m_selected[ i ] = selected[ i ];
121  }
122 
123  // delete
124  if( items != NULL ) {
125  delete[] items;
126  }
127  if( values != NULL ) {
128  delete[] values;
129  }
130  if( selected != NULL ) {
131  delete[] selected;
132  }
133 
134  return ret;
135 }
virtual bool onSelect(const unsigned int num, const char **items, const char **values, bool *selected)=0
This method is called by select method. (abstract method)
#define NULL
Definition: CoreMacros.h:18
std::vector< bool > m_selected
Definition: Selector.h:47
std::vector< std::pair< std::string, std::string > > m_items
Definition: Selector.h:44

Here is the call graph for this function:

Member Data Documentation

std::vector< std::pair< std::string, std::string > > kome::core::Selector::m_items
protected

item value

Definition at line 44 of file Selector.h.

int kome::core::Selector::m_sel
protected

selected item

Definition at line 50 of file Selector.h.

std::vector< bool > kome::core::Selector::m_selected
protected

selected flags

Definition at line 47 of file Selector.h.


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