typeValidators.h
Engine/source/console/typeValidators.h
Classes:
class
Floating point min/max range validator.
class
Signed integer min/max range validator.
class
Scaled integer field validator.
class
Vector normalization validator.
class
Namespaces:
namespace
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _TYPEVALIDATORS_H_ 25#define _TYPEVALIDATORS_H_ 26 27class TypeValidator 28{ 29 public: 30 S32 fieldIndex; 31 TypeValidator() : fieldIndex(0) {} 32 ~TypeValidator() {} 33 /// Prints a console error message for the validator. 34 /// 35 /// The message is prefaced with with: 36 /// @code 37 /// className objectName (objectId) - invalid value for fieldName: msg 38 /// @endcode 39 void consoleError(SimObject *object, const char *format, ...); 40 41 /// validateType is called for each assigned value on the field this 42 /// validator is attached to. 43 virtual void validateType(SimObject *object, void *typePtr) = 0; 44}; 45 46 47/// Floating point min/max range validator 48class FRangeValidator : public TypeValidator 49{ 50 F32 minV, maxV; 51public: 52 FRangeValidator(F32 minValue, F32 maxValue) 53 { 54 minV = minValue; 55 maxV = maxValue; 56 } 57 void validateType(SimObject *object, void *typePtr); 58 F32 getMin() { return minV; }; 59 F32 getMax() { return maxV; }; 60}; 61 62/// Signed integer min/max range validator 63class IRangeValidator : public TypeValidator 64{ 65 S32 minV, maxV; 66public: 67 IRangeValidator(S32 minValue, S32 maxValue) 68 { 69 minV = minValue; 70 maxV = maxValue; 71 } 72 void validateType(SimObject *object, void *typePtr); 73 F32 getMin() { return minV; }; 74 F32 getMax() { return maxV; }; 75}; 76 77/// Scaled integer field validator 78/// 79/// @note This should NOT be used on a field that gets exported - 80/// the field is only validated once on initial assignment 81class IRangeValidatorScaled : public TypeValidator 82{ 83 S32 minV, maxV; 84 S32 factor; 85public: 86 IRangeValidatorScaled(S32 scaleFactor, S32 minValueScaled, S32 maxValueScaled) 87 { 88 minV = minValueScaled; 89 maxV = maxValueScaled; 90 factor = scaleFactor; 91 } 92 void validateType(SimObject *object, void *typePtr); 93}; 94 95/// Vector normalization validator 96class Point3NormalizeValidator : public TypeValidator 97{ 98 F32 length; 99public: 100 Point3NormalizeValidator(F32 normalizeLength = 1.0f) : length(normalizeLength) { } 101 void validateType(SimObject *object, void *typePtr); 102 F32 getLength() { return length; }; 103}; 104 105namespace CommonValidators 106{ 107 // Floats 108 extern FRangeValidator PositiveFloat; 109 extern FRangeValidator PositiveNonZeroFloat; 110 extern FRangeValidator NormalizedFloat; 111 112 // Other Math Types 113 extern Point3NormalizeValidator NormalizedPoint3; 114}; 115 116#endif 117