equal
deleted
inserted
replaced
18 #include "cxutils.h" |
18 #include "cxutils.h" |
19 #include "cxeerrormappingsymbian.h" |
19 #include "cxeerrormappingsymbian.h" |
20 #include "cxestate.h" |
20 #include "cxestate.h" |
21 |
21 |
22 CxeStateMachineBase::CxeStateMachineBase( const char* stateMachineName ) : |
22 CxeStateMachineBase::CxeStateMachineBase( const char* stateMachineName ) : |
23 mStateId(0), mName(stateMachineName) |
23 mStateBitsUsed(0), mStateId(0), mName(stateMachineName) |
24 { |
24 { |
25 } |
25 } |
26 |
26 |
27 CxeStateMachineBase::~CxeStateMachineBase() |
27 CxeStateMachineBase::~CxeStateMachineBase() |
28 { |
28 { |
30 mStates.clear(); |
30 mStates.clear(); |
31 } |
31 } |
32 |
32 |
33 bool CxeStateMachineBase::addState( CxeState* state ) |
33 bool CxeStateMachineBase::addState( CxeState* state ) |
34 { |
34 { |
35 bool success = true; |
35 bool success( state // non-null state object |
36 |
36 && state->stateId() // state id is not zero |
37 if (!state) { |
37 && !(mStateBitsUsed & state->stateId()) // no overlapping bits |
38 // given parameter is null pointer |
38 ); |
39 success = false; |
|
40 } else { |
|
41 // Make sure any of the existing stateId don't have overlapping bits. |
|
42 // We need to be able to use bitwise AND operator for stateIds. |
|
43 QList<int> stateIds = mStates.keys(); |
|
44 foreach(int i, stateIds) { |
|
45 if ((i & state->stateId()) != 0) { |
|
46 success = false; |
|
47 break; |
|
48 } |
|
49 } |
|
50 } |
|
51 |
39 |
52 // if no errors |
40 // if no errors |
53 if (success) { |
41 if (success) { |
|
42 mStateBitsUsed |= state->stateId(); |
54 mStates[state->stateId()] = state; // state is now owned by the state machine |
43 mStates[state->stateId()] = state; // state is now owned by the state machine |
55 } |
44 } |
56 |
45 |
57 return success; |
46 return success; |
58 } |
47 } |