GL Studio SCECpp Runtime Library
gls_util.h
Go to the documentation of this file.
1 #ifndef _GLS_UTIL_H
2 #define _GLS_UTIL_H
3 
4 /*! \file gls_util.h
5 
6 \brief This header defines general utility classes, functions and macros
7  in the GL Studio DO-178B Runtime Library.
8 
9 \par Copyright Information
10 Copyright (C) 1999-2012 The DiSTI Corporation<br>
11 Orlando, FL USA<br>
12 All rights reserved.<br>
13 
14  This file is copyrighted software and contains proprietary trade secrets of
15 DiSTI, and embodies substantial creative efforts as well as confidential
16 information, ideas, and expressions.
17 
18  Permission to use, and copy this software and its documentation for any
19 purpose is hereby granted per the Distribution Agreement and/or the Licensing
20 Agreement signed with DiSTI. This permission is granted provided that:
21  1. The above copyright notice appears in all copies.
22  2. That both the copyright notice and this permission notice appear in
23  the supporting documentation.
24  3. That the names DiSTI and GL Studio not be used in advertising or
25  publicity pertaining to distribution of the software without specific,
26  written prior permission of DiSTI.
27 
28  Permission to modify the software is granted, but not the right to
29 distribute the source code whether modified, or non-modified. Modifying the
30 software might invalidate the DO-178B certification package.
31 
32  Permission to distribute binaries produced by compiling source code, or
33 modified source code is granted, provided you:
34  1. Provide your name and address as the primary contact for the support
35  of your modified version.
36  2. Retain our contact information in regard to use of the base software.
37 
38  DiSTI does not provide warranty for this software or guarantee that it
39 satisfies any specification or requirement unless otherwise stated in a
40 specific contractual arrangement between the customer and DiSTI.
41 
42 */
43 
44 #include "gls_include.h"
45 #include "gls_types.h"
46 #include "gls_color.h"
47 #include "gls_vertex.h"
48 #include "gls_class_invariant.h"
49 
50 // forward refs
51 struct GlsVector3D;
52 
53 /** maximum value macro */
54 #define GLS_MAX( _a, _b ) ( ( (_a) > (_b) ) ? (_a) : (_b) )
55 
56 /** A collection of utility classes and functions
57  * \invariant NA (all static members)
58  */
59 class GlsUtil
60 {
61 public:
62  /** PI constant */
63  static const GlsFloat64 PI;
64  /** degrees to radians conversion factor */
66 
67  /** black GlsColor constant */
68  static const GlsColor BLACK_GLS_COLOR;
69 
70  /** 3D vector of all zeroes */
72  /** 3D vector of all ones */
73  static const GlsVector3D ONE_VECTOR_3D;
74 
75  /** helper class for reading data in inline format
76  * \invariant _inlineData != GLS_NULL, _inlineDataLength > 0u,
77  * _lineLength > 0u, _curLineIndex < _lineLength,
78  * _numBytesRead <= _inlineDataLength
79  */
81  {
82  public:
84 
85  /** Constructor
86  * \param inlineData inline data
87  * \param inlineDataLength number of bytes in inline data (not including NULL terminators)
88  * \param lineLength length (in bytes) of one line of data in the inline data (not including NULL terminator)
89  * \pre inlineData != GLS_NULL, inlineDataLength > 0, lineLength > 0
90  * \post instance constructed
91  */
92  InlineReader( const GlsUChar* const inlineData[], const GlsUInt32 inlineDataLength,
93  const GlsUInt32 lineLength );
94 
95  /** Destructor
96  * \pre none
97  * \post instance destroyed
98  */
99  ~InlineReader();
100 
101  /** Read a byte from the inline data
102  * \return one byte read from inline data
103  * \pre there must be at least one byte of inline data left to read
104  * \post one byte is read from the inline data
105  */
106  GlsUChar ReadByte( void );
107 
108  /** Determine if the reader has read all of its inline data
109  * \return GLS_TRUE if reader has read all of its inline data else GLS_FALSE
110  * \pre none
111  * \post none
112  */
113  GlsBool IsDone( void ) const;
114 
115  protected:
116  const GlsUChar* const *_inlineData; /**< inline data to read */
117  const GlsUInt32 _inlineDataLength; /**< number of bytes in inline data
118  * (not including NULL terminators) */
119  const GlsUInt32 _lineLength; /**< length (in bytes) of one line of data in the inline data
120  * (not including NULL terminator) */
121 
122  GlsUInt32 _curLine; /**< index to current line of inline data */
123  GlsUInt32 _curLineIndex; /**< index to current byte of current line */
124  GlsUInt32 _numBytesRead; /**< number of bytes read from inline data */
125 
126  private:
127  // Disable implicit generated Members
128  InlineReader& operator=( const InlineReader &rhs );
129  InlineReader( const InlineReader &src );
130  };
131 
132  /** Determine if the given value is very close (< 10E-4) to 0.0
133  * \param val value in question
134  * \return GLS_TRUE if very close to zero else GLS_FALSE
135  * \pre GlsFloatIsValid( val );
136  * \post none
137  */
138  static GlsBool VeryCloseToZero( const GlsFloat32 val );
139 
140  /** Determine if the two given floats are within precision amount of each other
141  * \param x first float in question
142  * \param y second float in question
143  * \param precision precision amount indicating equal floats
144  * \return GLS_TRUE if the two floats are within precision of each other else GLS_FALSE
145  * \pre GlsFloatIsValid( x ), GlsFloatIsValid( y ), GlsFloatIsValid( precision ), precision > 0.0
146  * \post none
147  */
148  static GlsBool EqualFloat32( const GlsFloat32 x, const GlsFloat32 y, const GlsFloat32 precision );
149 
150  /** Get the gloating point modulus ( x mod y )
151  * \param x number to mod
152  * \param y number to mod by
153  * \return x mod y
154  * \pre GlsFloatIsValid( x ), GlsFloatIsValid( y )
155  * \post none
156  */
157  static GlsFloat64 Float64Mod( const GlsFloat64 x, const GlsFloat64 y );
158 
159  /** Determine if the two given colors are equal
160  * \param a first color in question
161  * \param b second color in question
162  * \return GLS_TRUE if the colors are equal else GLS_FALSE
163  * \pre a.IsValid(), b.IsValid()
164  * \post none
165  */
166  static GlsBool EqualColor( const GlsColor &a, const GlsColor &b );
167 
168  /** Normalize the given vector
169  * \param v [in/out] vector to normalize
170  * \pre v.IsValid(), the magnitide of v > 0.0
171  * \post v is normalized
172  */
173  static void NormalizeVector3D( GlsVector3D &v );
174 
175  /** Compute the 3D vector cross product of the the two vectors, assigning
176  * the result to v.
177  * \param v [in/out] vector on left side of cross product, receives result of cross product computation
178  * \param w right side of cross product
179  * \pre v.IsValid(), w.IsValid();
180  * \post v = v X w
181  */
182  static void CrossProductVector3D( GlsVector3D &v, const GlsVector3D &w );
183 
184  /** Compute the distance between the two given 3D points
185  * \param v first 3D point
186  * \param w second 3D point
187  * \return distance from v to w
188  * \pre v.IsValid(), w.IsValid()
189  * \post none
190  */
191  static GlsFloat32 DistanceVector3D( const GlsVector3D &v, const GlsVector3D &w );
192 
193 protected:
194  /** value used to determine if a value is close to 0.0 */
195  static const GlsFloat32 CLOSE_TO_ZERO;
196 };
197 
198 #endif // GLS_UTIL_H
static GlsBool VeryCloseToZero(const GlsFloat32 val)
unsigned char GlsUChar
Definition: gls_types.h:61
const GlsUInt32 _lineLength
Definition: gls_util.h:119
Definition: gls_color.h:47
bool GlsBool
Definition: gls_types.h:96
#define GLS_CLASS_INVARIANT_DECLARATION(ClassName)
Definition: gls_class_invariant.h:80
Definition: gls_vertex.h:65
static const GlsVector3D ONE_VECTOR_3D
Definition: gls_util.h:73
const GlsUChar *const * _inlineData
Definition: gls_util.h:116
static void NormalizeVector3D(GlsVector3D &v)
static const GlsFloat64 PI
Definition: gls_util.h:63
GlsUInt32 _curLine
Definition: gls_util.h:122
static const GlsFloat32 CLOSE_TO_ZERO
Definition: gls_util.h:195
unsigned int GlsUInt32
Definition: gls_types.h:73
static const GlsVector3D ZERO_VECTOR_3D
Definition: gls_util.h:71
This header defines a 4 component RGBA color for use in the GL Studio DO-178B Runtime Library...
static GlsFloat64 Float64Mod(const GlsFloat64 x, const GlsFloat64 y)
const GlsUInt32 _inlineDataLength
Definition: gls_util.h:117
This header defines the basic types used by the GL Studio DO-178B Runtime Library.
This header defines any preprocessor defines needed to configure the GL Studio DO-178B Runtime Librar...
InlineReader(const GlsUChar *const inlineData[], const GlsUInt32 inlineDataLength, const GlsUInt32 lineLength)
static void CrossProductVector3D(GlsVector3D &v, const GlsVector3D &w)
GlsUInt32 _numBytesRead
Definition: gls_util.h:124
Definition: gls_util.h:80
static GlsBool EqualColor(const GlsColor &a, const GlsColor &b)
static GlsBool EqualFloat32(const GlsFloat32 x, const GlsFloat32 y, const GlsFloat32 precision)
float GlsFloat32
Definition: gls_types.h:78
This header defines a GLS_DEBUG only macro for facilitating evaluating class invariants in the GL Stu...
GlsUInt32 _curLineIndex
Definition: gls_util.h:123
GlsBool IsDone(void) const
double GlsFloat64
Definition: gls_types.h:87
GlsUChar ReadByte(void)
This header defines classes for working with 2D and 3D vectors, vertices and textured vertices in the...
static GlsFloat32 DistanceVector3D(const GlsVector3D &v, const GlsVector3D &w)
static const GlsFloat64 DEGREES_TO_RADIANS
Definition: gls_util.h:65
Definition: gls_util.h:59
static const GlsColor BLACK_GLS_COLOR
Definition: gls_util.h:68