MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sequencecontainer.h
1 // © Copyright 2010 - 2012 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 StopWatchTimer;
49  namespace Input
50  {
51  ///////////////////////////////////////////////////////////////////////////////
52  /// @class SequenceContainer
53  /// @headerfile sequencecontainer.h
54  /// @brief This class stores and provides utilities for sequenced inputs and their operations.
55  /// @details
56  ///////////////////////////////////////
58  {
59  public:
61  typedef SequencedInputContainer::iterator SequencedInputIterator;
62  protected:
63  UInt16 MaxSequenceSize;
64  const UInt32 DeviceIndex;
65  StopWatchTimer* SequenceTimer;
66  MetaCodeContainer CurrSequenceCache;
67  SequencedInputContainer SequencedInputs;
68  /// @internal
69  /// @brief Verify's a sequence of MetaCode's is terminated with a null MetaCode.
70  /// @param Codes The vector of MetaCode's to verify.
71  virtual void VerifyInputSequence(const MetaCodeContainer& Codes) const;
72  /// @internal
73  /// @brief Verify's a numer is valid to be used as an ID for an input sequence being inserted.
74  /// @param ID The identification number to verify.
75  void VerifyInputID(const Int32& ID) const;
76  /// @internal
77  /// @brief Processes a sequence(as defined by an iterator range) to see if any action needs to be taken.
78  /// @param First An iterator to the first metacode in the sequence.
79  /// @param OneAfterLast An iterator to the space after the last metacode in the sequence.
80  /// @return Returns a new metacode for a completed sequence, or a "Null" metacode if no sequence was completed.
81  MetaCode ProcessSequence(MetaCodeIterator First, MetaCodeIterator OneAfterLast);
82  public:
83  /// @brief Class constructor.
85  /// @brief Controller constructor.
86  /// @param Device The index of the controller device this container belongs to.
88  /// @brief Class destructor.
89  virtual ~SequenceContainer();
90 
91  ///////////////////////////////////////////////////////////////////////////////
92  // Sequenced Input Management
93 
94  /// @brief Adds a custom sequence of inputs that this system will look for and generate MetaCode's for when they occur.
95  /// @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.
96  /// @param Codes A vector containing the sequence of MetaCode's to be added.
97  /// @param SequenceID A unique UInt32 to be used as the identifier for this sequence when a MetaCode is generated.
98  void AddInputSequence(const MetaCodeContainer& Codes, const Int32& SequenceID);
99  /// @brief Checks to see if the provided sequence of MetaCode's is already being checked for.
100  /// @exception If the vector of MetaCode's doesn't end with a null MetaCode, an exception will be thrown.
101  /// @param Codes A vector containing the sequence of MetaCode's to check for.
102  /// @return Returns true if the sequence already exists, false otherwise.
103  bool InputSequenceExists(const MetaCodeContainer& Codes);
104  /// @brief Gets the ID of the provided sequence of MetaCode's.
105  /// @exception If the vector of MetaCode's doesn't end with a null MetaCode, an exception will be thrown.
106  /// @param Codes A vector containing the sequence of MetaCode's to get the ID for.
107  /// @return Returns the ID of the provided sequence, or the max value of an Int32 if the sequence does not exist.
108  Int32 GetIDofInputSequence(const MetaCodeContainer& Codes);
109  /// @brief Removes the specified custom sequence of MetaCode's.
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 be removed.
112  void RemoveInputSequence(const MetaCodeContainer& Codes);
113  /// @brief Removes all stored input sequences.
114  void RemoveAllInputSequences();
115 
116  ///////////////////////////////////////////////////////////////////////////////
117  // Utility
118 
119  /// @brief Gets the number of input sequences stored in this sequence container.
120  /// @return Returns a UInt32 containing the number of sequences stored.
121  UInt32 GetNumInputSequences() const;
122  /// @brief Adds provided codes to the cache if necessary and checks for sequences that have been met.
123  /// @param NormalCodes A vector of the codes to add and/or check as a part of another sequence.
124  /// @param SequenceCodes A vector to which generated sequence codes will be added if they are generated.
125  void Update(const MetaCodeContainer& NormalCodes, MetaCodeContainer& SequenceCodes);
126  };//SequenceContainer
127  }//Input
128 }//Mezzanine
129 
130 #endif