ckb-next  v0.2.8 at branch master
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)
 
bool operator== (const ColorMap &rhs) const
 
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:46
const char ** _keyNames
Definition: colormap.h:44
int _mapCount
Definition: colormap.h:46
QRgb * _colors
Definition: colormap.h:45
ColorMap::~ColorMap ( )

Definition at line 8 of file colormap.cpp.

References deAlloc().

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

+ 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:46
const char ** _keyNames
Definition: colormap.h:44
int _mapCount
Definition: colormap.h:46
QRgb * _colors
Definition: colormap.h:45

Member Function Documentation

void ColorMap::alloc ( int  count)
private

Definition at line 43 of file colormap.cpp.

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

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

43  {
44  if(newCount > _mapCount){
45  // ^ map never shrinks, only expands
46  deAlloc();
47  _mapCount = newCount;
48  _keyNames = new const char*[_mapCount];
49  _colors = new QRgb[_mapCount];
50  }
51  _count = newCount;
52  clear();
53 }
int _count
Definition: colormap.h:46
void deAlloc()
Definition: colormap.cpp:55
const char ** _keyNames
Definition: colormap.h:44
int _mapCount
Definition: colormap.h:46
QRgb * _colors
Definition: colormap.h:45
void clear()
Definition: colormap.cpp:61

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ColorMap::clear ( )

Definition at line 61 of file colormap.cpp.

References _colors, and _count.

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

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

+ Here is the caller graph for this function:

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

Definition at line 88 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().

88  {
89  if(!_keyNames)
90  return 0;
91  const char** namePtr = (const char**)bsearch(&name, _keyNames, _count, sizeof(const char*), qs_strcmp);
92  if(!namePtr)
93  return 0;
94  ptrdiff_t position = namePtr - _keyNames;
95  return _colors + position;
96 }
int _count
Definition: colormap.h:46
static int qs_strcmp(const void *lhs, const void *rhs)
Definition: colormap.cpp:65
const char ** _keyNames
Definition: colormap.h:44
QRgb * _colors
Definition: colormap.h:45

+ 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 98 of file colormap.cpp.

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

98  {
99  if(!_keyNames)
100  return 0;
101  const char** namePtr = (const char**)bsearch(&name, _keyNames, _count, sizeof(const char*), qs_strcmp);
102  if(!namePtr)
103  return 0;
104  ptrdiff_t position = namePtr - _keyNames;
105  return _colors + position;
106 }
int _count
Definition: colormap.h:46
static int qs_strcmp(const void *lhs, const void *rhs)
Definition: colormap.cpp:65
const char ** _keyNames
Definition: colormap.h:44
QRgb * _colors
Definition: colormap.h:45

+ Here is the call graph for this function:

QRgb* ColorMap::colors ( )
inline

Definition at line 33 of file colormap.h.

References _colors.

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

33 { return _colors; }
QRgb * _colors
Definition: colormap.h:45

+ Here is the caller graph for this function:

const QRgb* ColorMap::colors ( ) const
inline

Definition at line 34 of file colormap.h.

References _colors.

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

Definition at line 31 of file colormap.h.

References _count.

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

31 { return _count; }
int _count
Definition: colormap.h:46

+ Here is the caller graph for this function:

void ColorMap::deAlloc ( )
private

Definition at line 55 of file colormap.cpp.

References _colors, _count, _keyNames, and _mapCount.

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

55  {
56  _count = _mapCount = 0;
57  if(_keyNames) delete[] _keyNames;
58  if(_colors) delete[] _colors;
59 }
int _count
Definition: colormap.h:46
const char ** _keyNames
Definition: colormap.h:44
int _mapCount
Definition: colormap.h:46
QRgb * _colors
Definition: colormap.h:45

+ Here is the caller graph for this function:

void ColorMap::init ( const KeyMap map)

Definition at line 69 of file colormap.cpp.

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

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

69  {
70  QList<Key> newKeys = map.positions();
71  // There's no point including keys that don't have LEDs, so remove them now
72  QMutableListIterator<Key> i(newKeys);
73  while(i.hasNext()){
74  Key key = i.next();
75  if(!key.hasLed)
76  i.remove();
77  }
78  // Now that we know how many keys we'll have, check memory
79  alloc(newKeys.count());
80  // Copy key names
81  int keyPos = 0;
82  foreach(const Key& key, newKeys)
83  _keyNames[keyPos++] = key.name; // as above, it's safe to copy these since the strings are constants
84  // Sort names for quick access
85  qsort(_keyNames, _count, sizeof(const char*), qs_strcmp);
86 }
int _count
Definition: colormap.h:46
static int qs_strcmp(const void *lhs, const void *rhs)
Definition: colormap.cpp:65
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:44
QList< Key > positions() const
Definition: keymap.h:148
void alloc(int count)
Definition: colormap.cpp:43

+ 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 32 of file colormap.h.

References _keyNames.

Referenced by KbLight::printRGB().

32 { return _keyNames; }
const char ** _keyNames
Definition: colormap.h:44

+ 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:46
const char ** _keyNames
Definition: colormap.h:44
QRgb * _colors
Definition: colormap.h:45
void alloc(int count)
Definition: colormap.cpp:43

+ Here is the call graph for this function:

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

Definition at line 27 of file colormap.cpp.

References _colors, _count, _keyNames, and x.

27  {
28  if(_count != rhs._count)
29  return false;
30 
31  // Compare just the pointers because key names are sorted and the strings are constants.
32  if(memcmp(_keyNames, rhs._keyNames, sizeof(const char*) * _count) != 0)
33  return false;
34 
35  for(int x = 0;x < _count;x++){
36  if(_colors[x] != rhs._colors[x])
37  return false;
38  }
39 
40  return true;
41 }
int _count
Definition: colormap.h:46
float x
Definition: main.c:66
const char ** _keyNames
Definition: colormap.h:44
QRgb * _colors
Definition: colormap.h:45

Field Documentation

QRgb* ColorMap::_colors
private

Definition at line 45 of file colormap.h.

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

int ColorMap::_count
private

Definition at line 46 of file colormap.h.

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

const char** ColorMap::_keyNames
private

Definition at line 44 of file colormap.h.

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

int ColorMap::_mapCount
private

Definition at line 46 of file colormap.h.

Referenced by alloc(), and deAlloc().


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