Spinning Topp Logo BlackTopp Studios
inc
sequencecontainer.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _inputsequencecontainer_h
41 #define _inputsequencecontainer_h
42 
43 #include "trie.h"
44 #include "Input/metacode.h"
45 
46 namespace Mezzanine
47 {
48  class Timer;
49  namespace Input
50  {
51  ///////////////////////////////////////////////////////////////////////////////
52  /// @brief This class stores and provides utilities for sequenced inputs and their operations.
53  ///////////////////////////////////////
55  {
56  public:
57  /// @brief Container type for recognized input sequences.
58  typedef Trie<Input::MetaCode,Int32> SequencedInputContainer;
59  /// @brief Iterator type for recognized input sequences.
60  typedef SequencedInputContainer::iterator SequencedInputIterator;
61  protected:
62  /// @internal
63  /// @brief Container storing all the recognized input sequences.
64  SequencedInputContainer SequencedInputs;
65  /// @internal
66  /// @brief Container storing the current input sequence.
68  /// @internal
69  /// @brief Timer used to help detect input sequences.
71  /// @internal
72  /// @brief The index of the device to detect sequenced inputs for.
74  /// @internal
75  /// @brief The maximum number of inputs to keep cached for detecting sequenced inputs.
77 
78  /// @internal
79  /// @brief Verify's a sequence of MetaCode's is terminated with a null MetaCode.
80  /// @param Codes The vector of MetaCode's to verify.
81  virtual void VerifyInputSequence(const MetaCodeContainer& Codes) const;
82  /// @internal
83  /// @brief Verify's a numer is valid to be used as an ID for an input sequence being inserted.
84  /// @param ID The identification number to verify.
85  void VerifyInputID(const Int32& ID) const;
86  /// @internal
87  /// @brief Processes a sequence(as defined by an iterator range) to see if any action needs to be taken.
88  /// @param First An iterator to the first metacode in the sequence.
89  /// @param OneAfterLast An iterator to the space after the last metacode in the sequence.
90  /// @return Returns a new metacode for a completed sequence, or a "Null" metacode if no sequence was completed.
91  MetaCode ProcessSequence(MetaCodeIterator First, MetaCodeIterator OneAfterLast);
92  public:
93  /// @brief Class constructor.
95  /// @brief Controller constructor.
96  /// @param Device The index of the controller device this container belongs to.
98  /// @brief Class destructor.
99  virtual ~SequenceContainer();
100 
101  ///////////////////////////////////////////////////////////////////////////////
102  // Sequenced Input Management
103 
104  /// @brief Adds a custom sequence of inputs that this system will look for and generate MetaCode's for when they occur.
105  /// @exception If the vector of MetaCode's doesn't end with a null MetaCode, an exception will be thrown. An exception can also be thrown if the ID provided is the max value of an Int32.
106  /// @param Codes A vector containing the sequence of MetaCode's to be added.
107  /// @param SequenceID A unique UInt32 to be used as the identifier for this sequence when a MetaCode is generated.
108  void AddInputSequence(const MetaCodeContainer& Codes, const Int32& SequenceID);
109  /// @brief Checks to see if the provided sequence of MetaCode's is already being checked for.
110  /// @exception If the vector of MetaCode's doesn't end with a null MetaCode, an exception will be thrown.
111  /// @param Codes A vector containing the sequence of MetaCode's to check for.
112  /// @return Returns true if the sequence already exists, false otherwise.
113  Boole InputSequenceExists(const MetaCodeContainer& Codes);
114  /// @brief Gets the ID of the provided sequence of MetaCode's.
115  /// @exception If the vector of MetaCode's doesn't end with a null MetaCode, an exception will be thrown.
116  /// @param Codes A vector containing the sequence of MetaCode's to get the ID for.
117  /// @return Returns the ID of the provided sequence, or the max value of an Int32 if the sequence does not exist.
118  Int32 GetIDofInputSequence(const MetaCodeContainer& Codes);
119  /// @brief Removes the specified custom sequence of MetaCode's.
120  /// @exception If the vector of MetaCode's doesn't end with a null MetaCode, an exception will be thrown.
121  /// @param Codes A vector containing the sequence of MetaCode's to be removed.
122  void RemoveInputSequence(const MetaCodeContainer& Codes);
123  /// @brief Removes all stored input sequences.
124  void RemoveAllInputSequences();
125 
126  ///////////////////////////////////////////////////////////////////////////////
127  // Utility
128 
129  /// @brief Gets the number of input sequences stored in this sequence container.
130  /// @return Returns a UInt32 containing the number of sequences stored.
131  UInt32 GetNumInputSequences() const;
132  /// @brief Adds provided codes to the cache if necessary and checks for sequences that have been met.
133  /// @param NormalCodes A vector of the codes to add and/or check as a part of another sequence.
134  /// @param SequenceCodes A vector to which generated sequence codes will be added if they are generated.
135  void Update(const MetaCodeContainer& NormalCodes, MetaCodeContainer& SequenceCodes);
136  };//SequenceContainer
137  }//Input
138 }//Mezzanine
139 
140 #endif
int32_t Int32
An 32-bit integer.
Definition: datatypes.h:124
Trie< Input::MetaCode, Int32 > SequencedInputContainer
Container type for recognized input sequences.
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
UInt16 MaxSequenceSize
The maximum number of inputs to keep cached for detecting sequenced inputs.
This is a base class for all input devices.
Definition: device.h:55
This class stores and provides utilities for sequenced inputs and their operations.
Input::MetaCode::MetaCodeIterator MetaCodeIterator
Iterator type for convenient MetaCode storage.
Definition: metacode.h:353
uint16_t UInt16
An 16-bit unsigned integer.
Definition: datatypes.h:122
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
Timer * SequenceTimer
Timer used to help detect input sequences.
This Determines the kind of user input.
Definition: metacode.h:93
Input::MetaCode::MetaCodeContainer MetaCodeContainer
Convenience datatype for storage of MetaCodes.
Definition: metacode.h:351
A basic timer class to assist in timed operations.
Definition: timer.h:67
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
SequencedInputContainer SequencedInputs
Container storing all the recognized input sequences.
const UInt32 DeviceIndex
The index of the device to detect sequenced inputs for.
SequencedInputContainer::iterator SequencedInputIterator
Iterator type for recognized input sequences.
MetaCodeContainer CurrSequenceCache
Container storing the current input sequence.