Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

KoduGenerators.h

Go to the documentation of this file.
00001 #ifndef KODU_GENERATORS_H_
00002 #define KODU_GENERATORS_H_
00003 
00004 #include <cstdlib>
00005 #include <ctime>
00006 #include <iostream>
00007 #include <string>
00008 #include <vector>
00009 
00010 namespace Kodu {
00011     
00012     class LiteralGenerator {
00013     public:
00014         //! A enumeration of ways a literal string can be returned
00015         enum ReturnOrder_t {
00016             RO_SEQUENTIAL = 0,
00017             RO_RANDOM
00018         };
00019 
00020         //! Constructor #1
00021         LiteralGenerator(const std::string& kLiteralString, ReturnOrder_t returnOrder)
00022           : literalStrings(),
00023             order(returnOrder),
00024             vecIndex(0)
00025         {
00026             if (!kLiteralString.empty())
00027                 literalStrings.push_back(kLiteralString);
00028         }
00029 
00030         //! Constructor #2
00031         LiteralGenerator(const std::vector<std::string>& kLiteralStrVector, ReturnOrder_t returnOrder)
00032           : literalStrings(kLiteralStrVector),
00033             order(returnOrder),
00034             vecIndex(literalStrings.size() - 1)
00035         { }
00036 
00037         //! Copy constructor
00038         LiteralGenerator(const LiteralGenerator& kGenerator)
00039           : literalStrings(kGenerator.literalStrings),
00040             order(kGenerator.order),
00041             vecIndex(kGenerator.vecIndex)
00042         { }
00043 
00044         //! Destructor
00045         ~LiteralGenerator() {
00046             // no explicit implementation
00047         }
00048 
00049         //! Assignment operator
00050         LiteralGenerator& operator=(const LiteralGenerator& kGenerator) {
00051             if (this != &kGenerator) {
00052                 literalStrings = kGenerator.literalStrings;
00053                 order = kGenerator.order;
00054                 vecIndex = kGenerator.vecIndex;
00055             }
00056             return *this;
00057         }
00058 
00059         //! Adds a literal string
00060         void addLiteralString(const std::string&);
00061 
00062         //! Returns a literal string
00063         const std::string& getLiteralString();
00064 
00065         //! Prints the attributes
00066         void printAttrs() const;
00067 
00068         //! Sets the literal string vector
00069         void setLiteralStrings(const std::vector<std::string>&);
00070 
00071     private:
00072         std::vector<std::string> literalStrings;    //!< A vector of literal strings
00073         ReturnOrder_t order;        //!< Used to control what order the strings will be returned in
00074         unsigned int vecIndex;      //!< Used to return the "next" string (mostly used for sequential order)
00075     };
00076 
00077     class NumericGenerator {
00078     public:
00079         //! Constructor
00080         NumericGenerator(float constantVal, float moduloDivisorVal)
00081           : constant(constantVal),
00082             moduloDivisor(moduloDivisorVal)
00083         {
00084             srand(time(NULL));
00085         }
00086 
00087         //! Copy constructor
00088         NumericGenerator(const NumericGenerator& kGenerator)
00089           : constant(kGenerator.constant),
00090             moduloDivisor(kGenerator.moduloDivisor)
00091         {
00092             srand(time(NULL));
00093         }
00094 
00095         //! Destructor
00096         virtual ~NumericGenerator() {
00097             // no explicit implementation
00098         }
00099 
00100         //! Assignment operator
00101         NumericGenerator& operator=(const NumericGenerator& kGenerator) {
00102             if (this != &kGenerator) {
00103                 constant = kGenerator.constant;
00104                 moduloDivisor = kGenerator.moduloDivisor;
00105                 srand(time(NULL));
00106             }
00107             return *this;
00108         }
00109 
00110         //! Returns a constant or random value
00111         virtual float getNumericValue();
00112 
00113         //! Prints info about the attributes
00114         void printAttrs() const;
00115 
00116         //! Sets the constant and upper bound values
00117         void setNumericValues(float, float);
00118 
00119     private:
00120         float constant;         //!< The constant value that is added to modulo operation's result
00121         float moduloDivisor;    //!< The divisor in the modulo operation
00122     };
00123     
00124     // class TimerGenerator : public NumericGenerator {
00125     // public:
00126     //  //! Constructor
00127     //  TimerGenerator(float constantVal, float upperBoundVal)
00128     //    : NumericGenerator(constantVal, upperBoundVal)
00129     //  { }
00130 
00131     //  //! Copy constructor
00132     //  TimerGenerator(const TimerGenerator& kGenerator)
00133     //    : NumericGenerator(kGenerator)
00134     //  { }
00135 
00136     //  //! Destructor
00137     //  ~TimerGenerator() { /* no explicit implementation */ }
00138 
00139     //  //! Assignment operator
00140     //  TimerGenerator& operator=(const TimerGenerator& kGenerator) {
00141     //      if (this != &kGenerator) {
00142     //          NumericGenerator::operator=(kGenerator);
00143     //      }
00144     //      return *this;
00145     //  }
00146 
00147     //  //! Prints info about the attributes
00148     //  void printAttrs() const;
00149     // };
00150 }
00151 
00152 #endif // KODU_GENERATORS_H_

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:43 2016 by Doxygen 1.6.3