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 32 /// Prints a console error message for the validator. 33 /// 34 /// The message is prefaced with with: 35 /// @code 36 /// className objectName (objectId) - invalid value for fieldName: msg 37 /// @endcode 38 void consoleError(SimObject *object, const char *format, ...); 39 40 /// validateType is called for each assigned value on the field this 41 /// validator is attached to. 42 virtual void validateType(SimObject *object, void *typePtr) = 0; 43}; 44 45 46/// Floating point min/max range validator 47class FRangeValidator : public TypeValidator 48{ 49 F32 minV, maxV; 50public: 51 FRangeValidator(F32 minValue, F32 maxValue) 52 { 53 minV = minValue; 54 maxV = maxValue; 55 } 56 void validateType(SimObject *object, void *typePtr); 57}; 58 59/// Signed integer min/max range validator 60class IRangeValidator : public TypeValidator 61{ 62 S32 minV, maxV; 63public: 64 IRangeValidator(S32 minValue, S32 maxValue) 65 { 66 minV = minValue; 67 maxV = maxValue; 68 } 69 void validateType(SimObject *object, void *typePtr); 70}; 71 72/// Scaled integer field validator 73/// 74/// @note This should NOT be used on a field that gets exported - 75/// the field is only validated once on initial assignment 76class IRangeValidatorScaled : public TypeValidator 77{ 78 S32 minV, maxV; 79 S32 factor; 80public: 81 IRangeValidatorScaled(S32 scaleFactor, S32 minValueScaled, S32 maxValueScaled) 82 { 83 minV = minValueScaled; 84 maxV = maxValueScaled; 85 factor = scaleFactor; 86 } 87 void validateType(SimObject *object, void *typePtr); 88}; 89 90/// Vector normalization validator 91class Point3NormalizeValidator : public TypeValidator 92{ 93 F32 length; 94public: 95 Point3NormalizeValidator(F32 normalizeLength = 1.0f) : length(normalizeLength) { } 96 void validateType(SimObject *object, void *typePtr); 97}; 98 99namespace CommonValidators 100{ 101 // Floats 102 extern FRangeValidator PositiveFloat; 103 extern FRangeValidator PositiveNonZeroFloat; 104 extern FRangeValidator NormalizedFloat; 105 106 // Other Math Types 107 extern Point3NormalizeValidator NormalizedPoint3; 108}; 109 110#endif 111
