ckb-next  beta-v0.2.8 at branch testing
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ColorMap Class Reference

#include <src/ckb/colormap.h>

+ Collaboration diagram for ColorMap:

Public Member Functions

 ColorMap ()
 
 ~ColorMap ()
 
 ColorMap (const ColorMap &rhs)
 
const ColorMapoperator= (const ColorMap &rhs)
 
void init (const KeyMap &map)
 
void clear ()
 
int count () const
 
const char *const * keyNames () const
 
QRgb * colors ()
 
const QRgb * colors () const
 
QRgb * colorForName (const char *name)
 
const QRgb * colorForName (const char *name) const
 

Private Member Functions

void alloc (int count)
 
void deAlloc ()
 

Private Attributes

const char ** _keyNames
 
QRgb * _colors
 
int _count
 
int _mapCount
 

Detailed Description

Definition at line 15 of file colormap.h.

Constructor & Destructor Documentation

ColorMap::ColorMap ( )

Definition at line 3 of file colormap.cpp.

3  :
4  _keyNames(0), _colors(0), _count(0), _mapCount(0)
5 {
6 }
int _count
Definition: colormap.h:45
const char ** _keyNames
Definition: colormap.h:43
int _mapCount
Definition: colormap.h:45
QRgb * _colors
Definition: colormap.h:44
ColorMap::~ColorMap ( )

Definition at line 8 of file colormap.cpp.

References deAlloc().

8  {
9  deAlloc();
10 }
void deAlloc()
Definition: colormap.cpp:39

+ Here is the call graph for this function:

ColorMap::ColorMap ( const ColorMap rhs)

Definition at line 12 of file colormap.cpp.

12  :
13  _keyNames(0), _colors(0), _count(0), _mapCount(0)
14 {
15  *this = rhs;
16 }
int _count
Definition: colormap.h:45
const char ** _keyNames
Definition: colormap.h:43
int _mapCount
Definition: colormap.h:45
QRgb * _colors
Definition: colormap.h:44

Member Function Documentation

void ColorMap::alloc ( int  count)
private

Definition at line 27 of file colormap.cpp.

References _colors, _count, _keyNames, _mapCount, clear(), and deAlloc().

Referenced by init(), and operator=().

27  {
28  if(newCount > _mapCount){
29  // ^ map never shrinks, only expands
30  deAlloc();
31  _mapCount = newCount;
32  _keyNames = new const char*[_mapCount];
33  _colors = new QRgb[_mapCount];
34  }
35  _count = newCount;
36  clear();
37 }
int _count
Definition: colormap.h:45
void deAlloc()
Definition: colormap.cpp:39
const char ** _keyNames
Definition: colormap.h:43
int _mapCount
Definition: colormap.h:45
QRgb * _colors
Definition: colormap.h:44
void clear()
Definition: colormap.cpp:45

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ColorMap::clear ( )

Definition at line 45 of file colormap.cpp.

References _colors, and _count.

Referenced by alloc(), AnimScript::end(), and KbLight::resetIndicators().

45  {
46  memset(_colors, 0, _count * sizeof(QRgb));
47 }
int _count
Definition: colormap.h:45
QRgb * _colors
Definition: colormap.h:44

+ Here is the caller graph for this function:

QRgb * ColorMap::colorForName ( const char *  name)

Definition at line 72 of file colormap.cpp.

References _colors, _count, _keyNames, and qs_strcmp().

Referenced by KbLight::base(), KbLight::color(), KeyWidget::paintEvent(), AnimScript::readProcess(), KbLight::rebuildBaseMap(), and KbLight::setIndicator().

72  {
73  if(!_keyNames)
74  return 0;
75  const char** namePtr = (const char**)bsearch(&name, _keyNames, _count, sizeof(const char*), qs_strcmp);
76  if(!namePtr)
77  return 0;
78  ptrdiff_t position = namePtr - _keyNames;
79  return _colors + position;
80 }
int _count
Definition: colormap.h:45
static int qs_strcmp(const void *lhs, const void *rhs)
Definition: colormap.cpp:49
const char ** _keyNames
Definition: colormap.h:43
QRgb * _colors
Definition: colormap.h:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const QRgb * ColorMap::colorForName ( const char *  name) const

Definition at line 82 of file colormap.cpp.

References _colors, _count, _keyNames, and qs_strcmp().

82  {
83  if(!_keyNames)
84  return 0;
85  const char** namePtr = (const char**)bsearch(&name, _keyNames, _count, sizeof(const char*), qs_strcmp);
86  if(!namePtr)
87  return 0;
88  ptrdiff_t position = namePtr - _keyNames;
89  return _colors + position;
90 }
int _count
Definition: colormap.h:45
static int qs_strcmp(const void *lhs, const void *rhs)
Definition: colormap.cpp:49
const char ** _keyNames
Definition: colormap.h:43
QRgb * _colors
Definition: colormap.h:44

+ Here is the call graph for this function:

QRgb* ColorMap::colors ( )
inline

Definition at line 32 of file colormap.h.

References _colors.

Referenced by KbLight::base(), KbAnim::blend(), KbLight::color(), KbLight::frameUpdate(), KbLight::printRGB(), and AnimScript::readProcess().

32 { return _colors; }
QRgb * _colors
Definition: colormap.h:44

+ Here is the caller graph for this function:

const QRgb* ColorMap::colors ( ) const
inline

Definition at line 33 of file colormap.h.

References _colors.

33 { return _colors; }
QRgb * _colors
Definition: colormap.h:44
int ColorMap::count ( ) const
inline

Definition at line 30 of file colormap.h.

References _count.

Referenced by KbLight::base(), KbAnim::blend(), KbLight::color(), KbLight::frameUpdate(), KbLight::printRGB(), and AnimScript::readProcess().

30 { return _count; }
int _count
Definition: colormap.h:45

+ Here is the caller graph for this function:

void ColorMap::deAlloc ( )
private

Definition at line 39 of file colormap.cpp.

References _colors, _count, _keyNames, and _mapCount.

Referenced by alloc(), and ~ColorMap().

39  {
40  _count = _mapCount = 0;
41  if(_keyNames) delete[] _keyNames;
42  if(_colors) delete[] _colors;
43 }
int _count
Definition: colormap.h:45
const char ** _keyNames
Definition: colormap.h:43
int _mapCount
Definition: colormap.h:45
QRgb * _colors
Definition: colormap.h:44

+ Here is the caller graph for this function:

void ColorMap::init ( const KeyMap map)

Definition at line 53 of file colormap.cpp.

References _count, _keyNames, alloc(), Key::hasLed, Key::name, KeyMap::positions(), and qs_strcmp().

Referenced by AnimScript::init(), and KbLight::map().

53  {
54  QList<Key> newKeys = map.positions();
55  // There's no point including keys that don't have LEDs, so remove them now
56  QMutableListIterator<Key> i(newKeys);
57  while(i.hasNext()){
58  Key key = i.next();
59  if(!key.hasLed)
60  i.remove();
61  }
62  // Now that we know how many keys we'll have, check memory
63  alloc(newKeys.count());
64  // Copy key names
65  int keyPos = 0;
66  foreach(const Key& key, newKeys)
67  _keyNames[keyPos++] = key.name; // as above, it's safe to copy these since the strings are constants
68  // Sort names for quick access
69  qsort(_keyNames, _count, sizeof(const char*), qs_strcmp);
70 }
int _count
Definition: colormap.h:45
static int qs_strcmp(const void *lhs, const void *rhs)
Definition: colormap.cpp:49
bool hasLed
Definition: keymap.h:19
Definition: keymap.h:49
const char * name
Definition: keymap.h:14
Definition: keymap.h:8
const char ** _keyNames
Definition: colormap.h:43
QList< Key > positions() const
Definition: keymap.h:132
void alloc(int count)
Definition: colormap.cpp:27

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const char* const* ColorMap::keyNames ( ) const
inline

Definition at line 31 of file colormap.h.

References _keyNames.

Referenced by KbLight::printRGB().

31 { return _keyNames; }
const char ** _keyNames
Definition: colormap.h:43

+ Here is the caller graph for this function:

const ColorMap & ColorMap::operator= ( const ColorMap rhs)

Definition at line 18 of file colormap.cpp.

References _colors, _count, _keyNames, and alloc().

18  {
19  alloc(rhs._count);
20  // Copy key names and colors
21  // (Note: it's safe to copy the const char*'s because key names are constants and will never move or be deleted)
22  memcpy(_keyNames, rhs._keyNames, sizeof(const char*) * _count);
23  memcpy(_colors, rhs._colors, sizeof(QRgb) * _count);
24  return rhs;
25 }
int _count
Definition: colormap.h:45
const char ** _keyNames
Definition: colormap.h:43
QRgb * _colors
Definition: colormap.h:44
void alloc(int count)
Definition: colormap.cpp:27

+ Here is the call graph for this function:

Field Documentation

QRgb* ColorMap::_colors
private

Definition at line 44 of file colormap.h.

Referenced by alloc(), clear(), colorForName(), colors(), deAlloc(), and operator=().

int ColorMap::_count
private

Definition at line 45 of file colormap.h.

Referenced by alloc(), clear(), colorForName(), count(), deAlloc(), init(), and operator=().

const char** ColorMap::_keyNames
private

Definition at line 43 of file colormap.h.

Referenced by alloc(), colorForName(), deAlloc(), init(), keyNames(), and operator=().

int ColorMap::_mapCount
private

Definition at line 45 of file colormap.h.

Referenced by alloc(), and deAlloc().


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