PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
comparator.h
Go to the documentation of this file.
1 
26 #pragma once
27 
28 // FIXME: Replace C++ headers when GCCv5+ C++ headers are installed
29 #include <string.h>
31 
32 namespace PropWare {
33 
37 template<typename T>
38 class Comparator {
39  public:
43  virtual bool valid (const T *lhs) const = 0;
44 };
45 
54  public:
59  }
60 
61  bool valid (const int *lhs) const {
62  return 0 <= *lhs;
63  }
64 };
65 
71 class YesNoComparator : public Comparator<char> {
72  public:
77  }
78 
79  virtual bool valid (const char *userInput) const {
80  char buffer[16];
81  strcpy(buffer, userInput);
82  Utility::to_lower(buffer);
83  return 0 == strcmp("n", buffer) ||
84  0 == strcmp("no", buffer) ||
85  0 == strcmp("y", buffer) ||
86  0 == strcmp("yes", buffer);
87  }
88 };
89 
90 }
91 
96 
PropWare::YesNoComparator::YesNoComparator
YesNoComparator()
Required default constructor.
Definition: comparator.h:76
PropWare::YesNoComparator
Determine if the user answered positively or negatively.
Definition: comparator.h:71
YES_NO_COMP
const PropWare::YesNoComparator YES_NO_COMP
Global instance for shared use by PropWare applications.
Definition: comparator.cpp:29
utility.h
PropWare::NonNegativeIntegerComparator::valid
bool valid(const int *lhs) const
Determines if the given argument is valid.
Definition: comparator.h:61
NON_NEGATIVE_COMP
const PropWare::NonNegativeIntegerComparator NON_NEGATIVE_COMP
Global instance for shared use by PropWare applications.
Definition: comparator.cpp:28
PropWare::Comparator::valid
virtual bool valid(const T *lhs) const =0
Determines if the given argument is valid.
PropWare::NonNegativeIntegerComparator
Also known as whole numbers, this class will only allow numbers that are zero or greater with no frac...
Definition: comparator.h:53
PropWare::Utility::to_lower
static void to_lower(char string[])
Convert each alphabetical character in a null-terminated character array to lowercase letters.
Definition: utility.h:156
PropWare::Comparator
Provide a way for a PropWare::Scanner to sanitize user input.
Definition: comparator.h:38
PropWare::YesNoComparator::valid
virtual bool valid(const char *userInput) const
Determines if the given argument is valid.
Definition: comparator.h:79
PropWare::NonNegativeIntegerComparator::NonNegativeIntegerComparator
NonNegativeIntegerComparator()
Required default constructor.
Definition: comparator.h:58
PropWare
Generic definitions and functions for the Parallax Propeller.
Definition: runnable.h:33