2 * Copyright 1999-2009 Jeremy Friesner
3 * Copyright 2009 Haiku, Inc. All rights reserved.
4 * Distributed under the terms of the MIT License.
11 #include "MetaKeyStateMap.h"
18 #include "BitFieldTesters.h"
21 MetaKeyStateMap::MetaKeyStateMap()
25 // User MUST call SetInfo() before using!
29 MetaKeyStateMap::MetaKeyStateMap(const char* name
)
36 MetaKeyStateMap::SetInfo(const char* keyName
)
38 fKeyName
= new char[strlen(keyName
) + 1];
39 strcpy(fKeyName
, keyName
);
43 MetaKeyStateMap::~MetaKeyStateMap()
46 int nr
= fStateDescs
.CountItems();
47 for (int i
= 0; i
< nr
; i
++)
48 delete [] ((const char*) fStateDescs
.ItemAt(i
));
50 nr
= fStateTesters
.CountItems();
51 for (int j
= 0; j
< nr
; j
++)
52 delete ((BitFieldTester
*) fStateTesters
.ItemAt(j
));
53 // _stateBits are stored in-line, no need to delete them
58 MetaKeyStateMap::AddState(const char* d
, const BitFieldTester
* t
)
60 char* copy
= new char[strlen(d
) + 1];
62 fStateDescs
.AddItem(copy
);
63 fStateTesters
.AddItem((void *)t
);
68 MetaKeyStateMap::GetNumStates() const
70 return fStateTesters
.CountItems();
75 MetaKeyStateMap::GetNthStateTester(int stateNum
) const
77 return ((const BitFieldTester
*) fStateTesters
.ItemAt(stateNum
));
82 MetaKeyStateMap::GetNthStateDesc(int stateNum
) const
84 return ((const char*) fStateDescs
.ItemAt(stateNum
));
89 MetaKeyStateMap::GetName() const