| GL Studio C++ Runtime API

Classes | Namespaces | Macros | Typedefs | Enumerations | Functions | Variables
util.h File Reference

Generally useful defines, macros, enumerations and function prototypes. More...

`#include "ConvertUTF.h"`
`#include "disti_assert.h"`
`#include "dynamic_array.h"`
`#include "gls_cpp_lang_support.h"`
`#include "gls_include.h"`
`#include "gls_matrix_affine.h"`
`#include "scoped_ptr.h"`
`#include "unhide_globals.h"`
`#include "vertex.h"`
`#include <algorithm>`
`#include <cmath>`
`#include <iostream>`
`#include <sstream>`
`#include <string>`
`#include <typeinfo>`
`#include <vector>`
`#include <unistd.h>`
`#include <cstdio>`

Go to the source code of this file.

## Classes
struct | CharTraitsUnsignedShort
class | OpenGLMatrices
| Class to contain current OpenGL view, projection and draw matrices. More...
struct | InlinePixmap
class | glsCommandLine
class | InterfaceDescriptionClass
class | GlsMultiValBase
class | GlsMultiVal< T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 >
class | GlsPropString
class | GlsPropStringQuoted
class | GlsGlobals
| Hold global objects so we can control order of destruction. More...

## Namespaces
namespace | disti

## Macros
#define | GLS_DEBUG_CODE(x) x
| Wrap code that should only be compiled in debug in GLS_DEBUG_CODE().
#define | TRUE 1
| True macro, for backward compatibility purposes.
#define | FALSE 0
| False macro, for backward compatibility purposes.
#define | MIN(A, B) ( ( A ) < ( B ) ? ( A ) : ( B ) )
#define | MAX(A, B) ( ( A ) > ( B ) ? ( A ) : ( B ) )
#define | GLSTUDIO_CLAMP_TO_EDGE GL_CLAMP_TO_EDGE
| From glext.h Available at http://oss.sgi.com/projects/ogl-sample/registry/.

## Typedefs
typedef std::basic_string< unsigned short, CharTraitsUnsignedShort > | UTF16String
| A cross platform UTF-16 encoded string.
typedef std::ofstream | UTF16Outfilestream
| A cross platform UTF-16 encoded ofstream.
typedef std::ostream | UTF16Outstream
| A cross platform UTF-16 encoded ostream.
typedef std::string | UnicodeString
| A cross platform UTF-8 encoded string.
typedef std::ofstream | UnicodeOutfilestream
| A cross platform UTF-8 encoded ofstream.
typedef std::ostream | UnicodeOutstream
| A cross platform UTF-8 encoded string.
typedef DynamicArray< InterfaceDescriptionClass > | InterfaceListType
| Typedef for a list of interface description objects.

## Enumerations
enum | GlsDefinedColorEnum { GLS_COLOR_WHITE , GLS_COLOR_CYAN , GLS_COLOR_RED , GLS_COLOR_AMBER , GLS_COLOR_GREEN , GLS_COLOR_YELLOW , GLS_COLOR_MAGENTA , GLS_COLOR_BLACK , GLS_COLOR_BLUE , GLS_COLOR_MAX }

## Functions
template<class X , class X1 , class X2 >
bool | BETWEEN (const X &x, const X1 &x1, const X2 &x2)
template<class X >
bool | IS_NEGATIVE (const X &x)
template<class X >
bool | IS_POSITIVE (const X &x)
template<class X >
bool | CloseToZero (const X x, const X threshold=X(1e-1))
template<class X >
bool | VeryCloseToZero (X x)
template<class X >
bool | IsNearZero (X x)
template<class X >
bool | IS_ZERO (X x)
float | OpenGLVersion ()
bool | gltIsExtSupported (const char *extension)
unsigned char * | GlsDefinedColor (GlsDefinedColorEnum index)
void | ChangeGlsDefinedColor (GlsDefinedColorEnum index, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
UTF16String | ConvertUTF8ToWide (const std::string &src)
template<class T1 , class T2 >
bool | Equal (T1 x, T2 y, float precision=0.001f)
template<class T >
const T & | Min (const T &x, const T &y)
template<class T >
const T & | Max (const T &x, const T &y)
template<class T , class Pred >
const T & | Min (const T &x, const T &y, Pred pr)
template<class T , class Pred >
const T & | Max (const T &x, const T &y, Pred pr)
template<class T >
GlsMatrixAffine< T > | FindCoordinateTransformation (const Vector &new_origin, const Vector &new_i, const Vector &new_j, const Vector &new_k)
template<class T >
void | FindCoordinateTransformation (const Vector &new_origin, const Vector &new_i, const Vector &new_j, const Vector &new_k, GlsMatrixAffine< T > &result)
bool | GetObjectCoordinatesTransformSameView (DisplayObject *from, DisplayObject *to, GlsMatrixType *outTransform)
DisplayFrame * | GetTopLevelDisplayFrame (DisplayFrame *frame)
bool | GetObjectCoordinatesTransform (DisplayObject *from, DisplayObject *to, GlsMatrixType *outTransform)
bool | NotColinear (const Vector &a, const Vector &b, const Vector &c)
bool | FindNonColinearVertices (int arraySize, Vector array[], int &index1, int &index2, int &index3, bool isVectorArray=true)
bool | FindNonColinearVertices (int arraySize, Vertex array[], int &index1, int &index2, int &index3)
bool | CalculateTexPointsFromTexCoords (DisplayObject *object)
int | EncodeString (char *dest, const char *src, const int dest_str_length)
std::string | EncodeString (const std::string &src)
int | EncodedStringMinLength ()
int | C_EncodeString (char *dest, const char *src, const int dest_str_length)
std::string | C_EncodeString (const std::string &src)
int | DecodeString (char *dest, const char *src, const int dest_str_length)
std::string | DecodeString (const std::string &src)
char * | MakeRelativePath (const char *originalPath, const char *relativePath)
void | ConvertBackslashToSlash (char *str)
void | ConvertBackslashToSlash (std::string &str)
int | range_check (int num, double val,...)
int | Safe_fopen (const char *filename, char *flags, FILE **f)
int | Safe_fopen (const char *filename, char *flags, std::fstream &outstr)
void | PushResourcePath (const char *resourcePath)
void | PopResourcePath ()
void | PushResourceFinder (std::string(*finder)(const std::string &))
std::string | ResolvePath (const char *path)
std::string | ResolvePath (const std::string &path)
FILE * | gls_fopen (const char *filename, const char *flags)
int | gls_unlink (const char *filename)
std::string | ResolveRuntimeResourcePath (const char *fileName)
bool | FileExists (const char *filename)
bool | FileExists (const std::string &filename)
bool | IsDirectory (const char *filename)
bool | IsDirectory (const std::string &filename)
std::string | FileExtension (const std::string &filepath)
std::string | FileName (const std::string &filepath)
std::string | FilePath (const std::string &filepath)
const char * | GetFilePath (const char *name)
char * | GetFileName (const char *name)
void | AppendTrailingSlash (char *s)
void | AppendTrailingSlash (std::string &s)
char * | PathToOS (const char *path)
std::string | GetExtension (const std::string &filename)
const char * | GetBaseName (const char *path)
char * | GetBaseName (char *path)
void | RemoveDoubleSlashes (char *path, char slash='/')
void | RemoveSpaces (std::string &entry)
void | TrimSpaces (std::string &entry)
float | AngularDistanceDeg (float angle1, float angle2)
float | AngularDistanceRad (float angle1, float angle2)
bool | ContainsNonBlank (const std::string &val)
bool | GetNoSpaces (FILE *f, char *result, int maxLen)
bool | GetToEnd (std::istream &instr, std::string &result, bool decode)
bool | GetVertex (std::istream &instr, Vertex *vert, bool getColor)
bool | GetComponentClassNames (const char *dllFileName, DynamicArray< std::string > &nameList, const char *createClassTag="CreateComponent_")
std::string | GetDefaultComponentClassName (const char *dllFileName)
std::string | GetQualifiedInstanceName (const DisplayFrame *topFrame, const DisplayObject *obj)
void | CheckGLError ()
| Checks the OpenGL error state, and prints to stdout if there was an error.
std::string | Uppercase (const std::string &str)
std::string | ReplaceEnvironmentVariables (const char *originalPath)
std::ostream & | operator<< (std::ostream &outstr, const GlsMultiValBase &multiVal)
std::istream & | operator>> (std::istream &instr, GlsMultiValBase &multiVal)
std::ostream & | operator<< (std::ostream &outstr, const GlsPropString &str)
std::istream & | operator>> (std::istream &instr, GlsPropString &str)
std::ostream & | operator<< (std::ostream &outstr, const GlsPropStringQuoted &str)
std::istream & | operator>> (std::istream &instr, GlsPropStringQuoted &str)
GlsPropString | operator+ (const GlsPropString &a, GlsPropString &b)
GlsPropString | operator+ (const GlsPropString &a, const GlsPropStringQuoted &b)
GlsPropStringQuoted | operator+ (const GlsPropStringQuoted &a, GlsPropStringQuoted &b)
GlsPropStringQuoted | operator+ (const GlsPropStringQuoted &a, const GlsPropString &b)
std::string | operator+ (const std::string &a, const GlsPropString &b)
std::string | operator+ (const std::string &a, const GlsPropStringQuoted &b)
GlsPropString & | operator+= (GlsPropString &a, const GlsPropString &b)
GlsPropString & | operator+= (GlsPropString &a, const GlsPropStringQuoted &b)
GlsPropString & | operator+= (GlsPropString &a, const char *b)
GlsPropString & | operator+= (GlsPropString &a, const std::string &b)
GlsPropStringQuoted & | operator+= (GlsPropStringQuoted &a, const GlsPropStringQuoted &b)
GlsPropStringQuoted & | operator+= (GlsPropStringQuoted &a, const GlsPropString &b)
GlsPropStringQuoted & | operator+= (GlsPropStringQuoted &a, const char *b)
GlsPropStringQuoted & | operator+= (GlsPropStringQuoted &a, const std::string &b)
std::string & | operator+= (std::string &a, const GlsPropString &b)
std::string & | operator+= (std::string &a, const GlsPropStringQuoted &b)
void | SpawnBrowser (const char *url)
bool | CheckDistiLicense (const char *licenseGroupName, const char *feature, const char *version, bool quiet)
void | GlsGetOrtho (GlsMatrixType &m, double left, double right, double bottom, double top, double zNear, double zFar)
void | GlsGetPerspective (GlsMatrixType &m, double fovy, double aspect, double zNear, double zFar)
template<class T >
T | Clamp (const T &val, const T &min, const T &max)
void | Split (const std::string &s, const char delim, std::vector< std::string > &elems, const std::size_t maxElems=0)
std::vector< std::string > | Split (const std::string &s, const char delim, const std::size_t maxElems=0)
std::string | MakeString (const char *const cStr)
void | _checkPointerSize ()
| We need this function because 'static_assert' replacements for pre-C++11 compilers cannot be at file scope.
void | glsPerspective (double fovy, double aspect, double zNear, double zFar)
bool | glsProject (double objx, double objy, double objz, const double modelMatrix[16], const double projMatrix[16], const int viewport[4], double *winx, double *winy, double *winz)
bool | glsUnProject (double winx, double winy, double winz, const double modelMatrix[16], const double projMatrix[16], const int viewport[4], double *objx, double *objy, double *objz)

## Variables
const int | DIALOG_MAX_DIRECTORY_LENGTH = 1024
| Limited by FLTK FileBrowser.
const int | INLINE_TEXTURE_LINE_LENGTH = 240
const char | PARSER_CLEARSTRING_DELIMETER_START [] = "#$STRING_START$#"
| Used for parsing lines of clear (multiline otherwise unencoded) text.
const char | PARSER_CLEARSTRING_DELIMETER_END [] = "#$STRING_END$#"
| Used for parsing lines of clear (multiline otherwise unencoded) text.
const double | HIT_TOLERANCE = 5.0
| The hit tolerance in logical units for selecting objects in the editor.
unsigned char | glsDefinedColors [GLS_COLOR_MAX][4]

## Detailed Description

Generally useful defines, macros, enumerations and function prototypes.

Copyright Information

Copyright (c) 2017 by The DiSTI Corporation.
11301 Corporate Blvd; Suite 100
Orlando, Florida 32817
USA
All rights reserved.

This Software contains proprietary trade secrets of DiSTI and may not be reproduced, in whole or part, in any form, or by any means of electronic, mechanical, or otherwise, without the written permission of DiSTI. Said permission may be derived through the purchase of applicable DiSTI product licenses which detail the distribution rights of this content and any Derivative Works based on this or other copyrighted DiSTI Software.

NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND, AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.

LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT EXCEED FIVE DOLLARS (US$5.00).

The aforementioned terms and restrictions are governed by the laws of the State of Florida and the United States of America.

## Macro Definition Documentation

## ◆ MAX

#define MAX | ( |  | A,
|  |  | B
| ) |  | ( ( A ) > ( B ) ? ( A ) : ( B ) )

Determines which argument is larger

Deprecated:
  Use disti::Min() instead.

## ◆ MIN

#define MIN | ( |  | A,
|  |  | B
| ) |  | ( ( A ) < ( B ) ? ( A ) : ( B ) )

Determines which argument is smaller

Deprecated:
  Use disti::Min() instead.

## Function Documentation

## ◆ Clamp()

T Clamp | ( | const T & | val,
|  | const T & | min,
|  | const T & | max
| ) |  |

Clamps a value to the range [min, max].

Parameters

  val | The value to clamp.
  min | The minimum value in the range.
  max | The maximum value in the range.

Returns
  The value clamped between min and max.

## ◆ glsPerspective()

void glsPerspective | ( | double | fovy,
|  | double | aspect,
|  | double | zNear,
|  | double | zFar
| ) |  |

Set up a perspective projection. Functions the same as gluPerspective().

Parameters

  fovy | The vertical FOV in degrees.
  aspect | The aspect ratio.
  zNear | The near clipping distance.
  zFar | The far clipping distance.

## ◆ glsProject()

bool glsProject | ( | double | objx,
|  | double | objy,
|  | double | objz,
|  | const double | modelMatrix[16],
|  | const double | projMatrix[16],
|  | const int | viewport[4],
|  | double * | winx,
|  | double * | winy,
|  | double * | winz
| ) |  |

Projects a point from object space into window space. Functions the same as gluProject().

Parameters

  objx | The X coordinate to project.
  objy | The Y coordinate to project.
  objz | The Z coordinate to project.
  modelMatrix | The modelview matrix to project with.
  projMatrix | The projection matrix to project with.
  viewport | The viewport to project with.
  winx | The returned projected X coordinate.
  winy | The returned projected Y coordinate.
  winz | The returned projected Z coordinate.

Returns
  True if the operation was successful.

## ◆ glsUnProject()

bool glsUnProject | ( | double | winx,
|  | double | winy,
|  | double | winz,
|  | const double | modelMatrix[16],
|  | const double | projMatrix[16],
|  | const int | viewport[4],
|  | double * | objx,
|  | double * | objy,
|  | double * | objz
| ) |  |

Unprojects a point from window space into object space. Functions the same as gluUnproject().

Parameters

  winx | The X coordinate to unproject.
  winy | The Y coordinate to unproject.
  winz | The Z coordinate to unproject.
  modelMatrix | The modelview matrix to project with.
  projMatrix | The projection matrix to project with.
  viewport | The viewport to project with.
  objx | The returned unprojected X coordinate.
  objy | The returned unprojected Y coordinate.
  objz | The returned unprojected Z coordinate.

Returns
  True if the operation was successful.

## ◆ MakeString()

std::string MakeString | ( | const char *const | cStr | ) |
| inline

Passing null to std::string is not well-defined. Creates a string safely.

Parameters

  cStr | The string to create a std::string from.

Returns
  A std::string created from the incoming C string.

## ◆ Split() [1/2]

std::vector< std::string > Split | ( | const std::string & | s,
|  | const char | delim,
|  | const std::size_t | maxElems = `0`
| ) |  |
| inline

Split a string return a vector of the elements with delimeters removed.

Parameters

  s | The string to split
  delim | The delimiter to split the string on.
  maxElems | The maximum number of elements to split. Remaining elements are appended unsplit as the last value. If 0, it does not have a maximum.

Returns
  The vector of split elements.

Note
  Adapted from http://stackoverflow.com/questions/236129/split-a-string-in-c

## ◆ Split() [2/2]

void Split | ( | const std::string & | s,
|  | const char | delim,
|  | std::vector< std::string > & | elems,
|  | const std::size_t | maxElems = `0`
| ) |  |
| inline

Split a string and add to existing vector of elements with delimeters removed.

Parameters

  s | The string to split
  delim | The delimiter to split the string on.
  elems | The vector of elements to append each split string to.
  maxElems | The maximum number of elements to split. Remaining elements are appended unsplit as the last value. If 0, it does not have a maximum.

Note
  Adapted from http://stackoverflow.com/questions/236129/split-a-string-in-c