summaryrefslogtreecommitdiff
path: root/external/vpc/public/vstdlib
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /external/vpc/public/vstdlib
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'external/vpc/public/vstdlib')
-rw-r--r--external/vpc/public/vstdlib/cvar.h25
-rw-r--r--external/vpc/public/vstdlib/ikeyvaluessystem.h56
-rw-r--r--external/vpc/public/vstdlib/pch_vstdlib.h51
-rw-r--r--external/vpc/public/vstdlib/random.h111
-rw-r--r--external/vpc/public/vstdlib/vstdlib.h40
-rw-r--r--external/vpc/public/vstdlib/vstrtools.h275
6 files changed, 558 insertions, 0 deletions
diff --git a/external/vpc/public/vstdlib/cvar.h b/external/vpc/public/vstdlib/cvar.h
new file mode 100644
index 0000000..1f26e0d
--- /dev/null
+++ b/external/vpc/public/vstdlib/cvar.h
@@ -0,0 +1,25 @@
+//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//
+//=============================================================================//
+
+#if !defined( CVAR_H )
+#define CVAR_H
+#ifdef _WIN32
+#pragma once
+#endif
+
+#include "vstdlib/vstdlib.h"
+#include "icvar.h"
+
+
+//-----------------------------------------------------------------------------
+// Returns a CVar dictionary for tool usage
+//-----------------------------------------------------------------------------
+VSTDLIB_INTERFACE CreateInterfaceFn VStdLib_GetICVarFactory();
+
+
+#endif // CVAR_H
diff --git a/external/vpc/public/vstdlib/ikeyvaluessystem.h b/external/vpc/public/vstdlib/ikeyvaluessystem.h
new file mode 100644
index 0000000..3477ed3
--- /dev/null
+++ b/external/vpc/public/vstdlib/ikeyvaluessystem.h
@@ -0,0 +1,56 @@
+//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+#ifndef VSTDLIB_IKEYVALUESSYSTEM_H
+#define VSTDLIB_IKEYVALUESSYSTEM_H
+#ifdef _WIN32
+#pragma once
+#endif
+
+#include "vstdlib/vstdlib.h"
+
+// handle to a KeyValues key name symbol
+typedef int HKeySymbol;
+#define INVALID_KEY_SYMBOL (-1)
+
+//-----------------------------------------------------------------------------
+// Purpose: Interface to shared data repository for KeyValues (included in vgui_controls.lib)
+// allows for central data storage point of KeyValues symbol table
+//-----------------------------------------------------------------------------
+class IKeyValuesSystem
+{
+public:
+ // registers the size of the KeyValues in the specified instance
+ // so it can build a properly sized memory pool for the KeyValues objects
+ // the sizes will usually never differ but this is for versioning safety
+ virtual void RegisterSizeofKeyValues(int size) = 0;
+
+ // allocates/frees a KeyValues object from the shared mempool
+ virtual void *AllocKeyValuesMemory(int size) = 0;
+ virtual void FreeKeyValuesMemory(void *pMem) = 0;
+
+ // symbol table access (used for key names)
+ virtual HKeySymbol GetSymbolForString( const char *name, bool bCreate = true ) = 0;
+ virtual const char *GetStringForSymbol(HKeySymbol symbol) = 0;
+
+ // for debugging, adds KeyValues record into global list so we can track memory leaks
+ virtual void AddKeyValuesToMemoryLeakList(void *pMem, HKeySymbol name) = 0;
+ virtual void RemoveKeyValuesFromMemoryLeakList(void *pMem) = 0;
+
+ // set/get a value for keyvalues resolution symbol
+ // e.g.: SetKeyValuesExpressionSymbol( "LOWVIOLENCE", true ) - enables [$LOWVIOLENCE]
+ virtual void SetKeyValuesExpressionSymbol( const char *name, bool bValue ) = 0;
+ virtual bool GetKeyValuesExpressionSymbol( const char *name ) = 0;
+
+ // symbol table access from code with case-preserving requirements (used for key names)
+ virtual HKeySymbol GetSymbolForStringCaseSensitive( HKeySymbol &hCaseInsensitiveSymbol, const char *name, bool bCreate = true ) = 0;
+};
+
+VSTDLIB_INTERFACE IKeyValuesSystem *KeyValuesSystem();
+
+// #define KEYVALUESSYSTEM_INTERFACE_VERSION "KeyValuesSystem002"
+
+#endif // VSTDLIB_IKEYVALUESSYSTEM_H
diff --git a/external/vpc/public/vstdlib/pch_vstdlib.h b/external/vpc/public/vstdlib/pch_vstdlib.h
new file mode 100644
index 0000000..03754dd
--- /dev/null
+++ b/external/vpc/public/vstdlib/pch_vstdlib.h
@@ -0,0 +1,51 @@
+//======== (C) Copyright 1999, 2000 Valve, L.L.C. All rights reserved. ========
+//
+// The copyright to the contents herein is the property of Valve, L.L.C.
+// The contents may be used and/or copied only with the written permission of
+// Valve, L.L.C., or in accordance with the terms and conditions stipulated in
+// the agreement/contract under which the contents have been supplied.
+//
+// Purpose:
+//
+// $Workfile: $
+// $NoKeywords: $
+//=============================================================================
+
+
+#pragma warning(disable: 4514)
+
+// First include standard libraries
+#include <stdio.h>
+#include <ctype.h>
+#include <math.h>
+#include <malloc.h>
+#include <memory.h>
+#include <ctype.h>
+
+// Next, include public
+#include "tier0/basetypes.h"
+#include "tier0/dbg.h"
+#include "tier0/valobject.h"
+
+// Next, include vstdlib
+#include "vstdlib/vstdlib.h"
+#include "tier1/strtools.h"
+#include "vstdlib/random.h"
+#include "tier1/keyvalues.h"
+#include "tier1/utlmemory.h"
+#include "tier1/utlrbtree.h"
+#include "tier1/utlvector.h"
+#include "tier1/utllinkedlist.h"
+#include "tier1/utlmultilist.h"
+#include "tier1/utlsymbol.h"
+#include "tier0/icommandline.h"
+#include "tier1/netadr.h"
+#include "tier1/mempool.h"
+#include "tier1/utlbuffer.h"
+#include "tier1/utlstring.h"
+#include "tier1/utlmap.h"
+
+#include "tier0/memdbgon.h"
+
+
+
diff --git a/external/vpc/public/vstdlib/random.h b/external/vpc/public/vstdlib/random.h
new file mode 100644
index 0000000..3f05a1d
--- /dev/null
+++ b/external/vpc/public/vstdlib/random.h
@@ -0,0 +1,111 @@
+//===== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ======//
+//
+// Purpose: Random number generator
+//
+// $Workfile: $
+// $NoKeywords: $
+//===========================================================================//
+
+#ifndef VSTDLIB_RANDOM_H
+#define VSTDLIB_RANDOM_H
+
+#include "vstdlib/vstdlib.h"
+#include "tier0/basetypes.h"
+#include "tier0/threadtools.h"
+#include "tier1/interface.h"
+
+#define NTAB 32
+
+#pragma warning(push)
+#pragma warning( disable:4251 )
+
+//-----------------------------------------------------------------------------
+// A generator of uniformly distributed random numbers
+//-----------------------------------------------------------------------------
+class IUniformRandomStream
+{
+public:
+ // Sets the seed of the random number generator
+ virtual void SetSeed( int iSeed ) = 0;
+
+ // Generates random numbers
+ virtual float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f ) = 0;
+ virtual int RandomInt( int iMinVal, int iMaxVal ) = 0;
+ virtual float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f ) = 0;
+};
+
+
+//-----------------------------------------------------------------------------
+// The standard generator of uniformly distributed random numbers
+//-----------------------------------------------------------------------------
+class VSTDLIB_CLASS CUniformRandomStream : public IUniformRandomStream
+{
+public:
+ CUniformRandomStream();
+
+ // Sets the seed of the random number generator
+ virtual void SetSeed( int iSeed );
+
+ // Generates random numbers
+ virtual float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f );
+ virtual int RandomInt( int iMinVal, int iMaxVal );
+ virtual float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f );
+
+private:
+ int GenerateRandomNumber();
+
+ int m_idum;
+ int m_iy;
+ int m_iv[NTAB];
+
+ CThreadFastMutex m_mutex;
+};
+
+
+//-----------------------------------------------------------------------------
+// A generator of gaussian distributed random numbers
+//-----------------------------------------------------------------------------
+class VSTDLIB_CLASS CGaussianRandomStream
+{
+public:
+ // Passing in NULL will cause the gaussian stream to use the
+ // installed global random number generator
+ CGaussianRandomStream( IUniformRandomStream *pUniformStream = NULL );
+
+ // Attaches to a random uniform stream
+ void AttachToStream( IUniformRandomStream *pUniformStream = NULL );
+
+ // Generates random numbers
+ float RandomFloat( float flMean = 0.0f, float flStdDev = 1.0f );
+
+private:
+ IUniformRandomStream *m_pUniformStream;
+ bool m_bHaveValue;
+ float m_flRandomValue;
+
+ CThreadFastMutex m_mutex;
+};
+
+
+//-----------------------------------------------------------------------------
+// A couple of convenience functions to access the library's global uniform stream
+//-----------------------------------------------------------------------------
+VSTDLIB_INTERFACE void RandomSeed( int iSeed );
+VSTDLIB_INTERFACE float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f );
+VSTDLIB_INTERFACE float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f );
+VSTDLIB_INTERFACE int RandomInt( int iMinVal, int iMaxVal );
+VSTDLIB_INTERFACE float RandomGaussianFloat( float flMean = 0.0f, float flStdDev = 1.0f );
+
+
+//-----------------------------------------------------------------------------
+// Installs a global random number generator, which will affect the Random functions above
+//-----------------------------------------------------------------------------
+VSTDLIB_INTERFACE void InstallUniformRandomStream( IUniformRandomStream *pStream );
+
+
+#pragma warning(pop)
+
+#endif // VSTDLIB_RANDOM_H
+
+
+
diff --git a/external/vpc/public/vstdlib/vstdlib.h b/external/vpc/public/vstdlib/vstdlib.h
new file mode 100644
index 0000000..ffdb31a
--- /dev/null
+++ b/external/vpc/public/vstdlib/vstdlib.h
@@ -0,0 +1,40 @@
+//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//
+//=============================================================================//
+
+#ifndef VSTDLIB_H
+#define VSTDLIB_H
+
+#ifdef _WIN32
+#pragma once
+#endif
+
+#include "tier0/platform.h"
+
+//-----------------------------------------------------------------------------
+// dll export stuff
+//-----------------------------------------------------------------------------
+#ifdef STATIC_VSTDLIB
+#define VSTDLIB_INTERFACE
+#define VSTDLIB_OVERLOAD
+#define VSTDLIB_CLASS
+#define VSTDLIB_GLOBAL
+#else
+#ifdef VSTDLIB_DLL_EXPORT
+#define VSTDLIB_INTERFACE DLL_EXPORT
+#define VSTDLIB_OVERLOAD DLL_GLOBAL_EXPORT
+#define VSTDLIB_CLASS DLL_CLASS_EXPORT
+#define VSTDLIB_GLOBAL DLL_GLOBAL_EXPORT
+#else
+#define VSTDLIB_INTERFACE DLL_IMPORT
+#define VSTDLIB_OVERLOAD DLL_GLOBAL_IMPORT
+#define VSTDLIB_CLASS DLL_CLASS_IMPORT
+#define VSTDLIB_GLOBAL DLL_GLOBAL_IMPORT
+#endif
+#endif
+
+#endif // VSTDLIB_H
diff --git a/external/vpc/public/vstdlib/vstrtools.h b/external/vpc/public/vstdlib/vstrtools.h
new file mode 100644
index 0000000..04b351c
--- /dev/null
+++ b/external/vpc/public/vstdlib/vstrtools.h
@@ -0,0 +1,275 @@
+//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
+//
+// Functions for UCS/UTF/Unicode string operations. These functions are in vstdlib
+// instead of tier1, because on PS/3 they need to load and initialize a system module,
+// which is more frugal to do from a single place rather than multiple times in different PRX'es.
+// The functions themselves aren't supposed to be called frequently enough for the DLL/PRX boundary
+// marshalling, if any, to have any measureable impact on performance.
+//
+#ifndef VSTRTOOLS_HDR
+#define VSTRTOOLS_HDR
+
+#include "tier0/platform.h"
+#include "tier0/basetypes.h"
+#include "tier1/strtools.h"
+
+#ifdef STATIC_VSTDLIB
+#define VSTRTOOLS_INTERFACE
+#else
+#ifdef VSTDLIB_DLL_EXPORT
+#define VSTRTOOLS_INTERFACE DLL_EXPORT
+#else
+#define VSTRTOOLS_INTERFACE DLL_IMPORT
+#endif
+#endif
+
+// conversion functions wchar_t <-> char, returning the number of characters converted
+VSTRTOOLS_INTERFACE int V_UTF8ToUnicode( const char *pUTF8, wchar_t *pwchDest, int cubDestSizeInBytes );
+VSTRTOOLS_INTERFACE int V_UnicodeToUTF8( const wchar_t *pUnicode, char *pUTF8, int cubDestSizeInBytes );
+VSTRTOOLS_INTERFACE int V_UCS2ToUnicode( const ucs2 *pUCS2, wchar_t *pUnicode, int cubDestSizeInBytes );
+VSTRTOOLS_INTERFACE int V_UCS2ToUTF8( const ucs2 *pUCS2, char *pUTF8, int cubDestSizeInBytes );
+VSTRTOOLS_INTERFACE int V_UnicodeToUCS2( const wchar_t *pUnicode, int cubSrcInBytes, char *pUCS2, int cubDestSizeInBytes );
+VSTRTOOLS_INTERFACE int V_UTF8ToUCS2( const char *pUTF8, int cubSrcInBytes, ucs2 *pUCS2, int cubDestSizeInBytes );
+
+// copy at most n bytes into destination, will not corrupt utf-8 multi-byte sequences
+VSTRTOOLS_INTERFACE void * V_UTF8_strncpy( char *pDest, const char *pSrc, size_t nMaxBytes );
+
+
+//
+// This utility class is for performing UTF-8 <-> UTF-16 conversion.
+// It is intended for use with function/method parameters.
+//
+// For example, you can call
+// FunctionTakingUTF16( CStrAutoEncode( utf8_string ).ToWString() )
+// or
+// FunctionTakingUTF8( CStrAutoEncode( utf16_string ).ToString() )
+//
+// The converted string is allocated off the heap, and destroyed when
+// the object goes out of scope.
+//
+// if the string cannot be converted, NULL is returned.
+//
+// This class doesn't have any conversion operators; the intention is
+// to encourage the developer to get used to having to think about which
+// encoding is desired.
+//
+class CStrAutoEncode
+{
+public:
+
+ // ctor
+ explicit CStrAutoEncode( const char *pch )
+ {
+ m_pch = pch;
+ m_pwch = NULL;
+#if !defined( WIN32 ) && !defined(_WIN32)
+ m_pucs2 = NULL;
+ m_bCreatedUCS2 = false;
+#endif
+ m_bCreatedUTF16 = false;
+ }
+
+ // ctor
+ explicit CStrAutoEncode( const wchar_t *pwch )
+ {
+ m_pch = NULL;
+ m_pwch = pwch;
+#if !defined( WIN32 ) && !defined(_WIN32)
+ m_pucs2 = NULL;
+ m_bCreatedUCS2 = false;
+#endif
+ m_bCreatedUTF16 = true;
+ }
+
+#if !defined(WIN32) && !defined(_WINDOWS) && !defined(_WIN32) && !defined(_PS3)
+ explicit CStrAutoEncode( const ucs2 *pwch )
+ {
+ m_pch = NULL;
+ m_pwch = NULL;
+ m_pucs2 = pwch;
+ m_bCreatedUCS2 = true;
+ m_bCreatedUTF16 = false;
+ }
+#endif
+
+ // returns the UTF-8 string, converting on the fly.
+ const char* ToString()
+ {
+ PopulateUTF8();
+ return m_pch;
+ }
+
+ // returns the UTF-8 string - a writable pointer.
+ // only use this if you don't want to call const_cast
+ // yourself. We need this for cases like CreateProcess.
+ char* ToStringWritable()
+ {
+ PopulateUTF8();
+ return const_cast< char* >( m_pch );
+ }
+
+ // returns the UTF-16 string, converting on the fly.
+ const wchar_t* ToWString()
+ {
+ PopulateUTF16();
+ return m_pwch;
+ }
+
+#if !defined( WIN32 ) && !defined(_WIN32)
+ // returns the UTF-16 string, converting on the fly.
+ const ucs2* ToUCS2String()
+ {
+ PopulateUCS2();
+ return m_pucs2;
+ }
+#endif
+
+ // returns the UTF-16 string - a writable pointer.
+ // only use this if you don't want to call const_cast
+ // yourself. We need this for cases like CreateProcess.
+ wchar_t* ToWStringWritable()
+ {
+ PopulateUTF16();
+ return const_cast< wchar_t* >( m_pwch );
+ }
+
+ // dtor
+ ~CStrAutoEncode()
+ {
+ // if we're "native unicode" then the UTF-8 string is something we allocated,
+ // and vice versa.
+ if ( m_bCreatedUTF16 )
+ {
+ delete [] m_pch;
+ }
+ else
+ {
+ delete [] m_pwch;
+ }
+#if !defined( WIN32 ) && !defined(_WIN32)
+ if ( !m_bCreatedUCS2 && m_pucs2 )
+ delete [] m_pucs2;
+#endif
+ }
+
+private:
+ // ensure we have done any conversion work required to farm out a
+ // UTF-8 encoded string.
+ //
+ // We perform two heap allocs here; the first one is the worst-case
+ // (four bytes per Unicode code point). This is usually quite pessimistic,
+ // so we perform a second allocation that's just the size we need.
+ void PopulateUTF8()
+ {
+ if ( !m_bCreatedUTF16 )
+ return; // no work to do
+ if ( m_pwch == NULL )
+ return; // don't have a UTF-16 string to convert
+ if ( m_pch != NULL )
+ return; // already been converted to UTF-8; no work to do
+
+ // each Unicode code point can expand to as many as four bytes in UTF-8; we
+ // also need to leave room for the terminating NUL.
+ uint32 cbMax = 4 * static_cast<uint32>( V_wcslen( m_pwch ) ) + 1;
+ char *pchTemp = new char[ cbMax ];
+ if ( V_UnicodeToUTF8( m_pwch, pchTemp, cbMax ) )
+ {
+ uint32 cchAlloc = static_cast<uint32>( V_strlen( pchTemp ) ) + 1;
+ char *pchHeap = new char[ cchAlloc ];
+ V_strncpy( pchHeap, pchTemp, cchAlloc );
+ delete [] pchTemp;
+ m_pch = pchHeap;
+ }
+ else
+ {
+ // do nothing, and leave the UTF-8 string NULL
+ delete [] pchTemp;
+ }
+ }
+
+ // ensure we have done any conversion work required to farm out a
+ // UTF-16 encoded string.
+ //
+ // We perform two heap allocs here; the first one is the worst-case
+ // (one code point per UTF-8 byte). This is sometimes pessimistic,
+ // so we perform a second allocation that's just the size we need.
+ void PopulateUTF16()
+ {
+ if ( m_bCreatedUTF16 )
+ return; // no work to do
+ if ( m_pch == NULL )
+ return; // no UTF-8 string to convert
+ if ( m_pwch != NULL )
+ return; // already been converted to UTF-16; no work to do
+
+ uint32 cchMax = static_cast<uint32>( V_strlen( m_pch ) ) + 1;
+ wchar_t *pwchTemp = new wchar_t[ cchMax ];
+ if ( V_UTF8ToUnicode( m_pch, pwchTemp, cchMax * sizeof( wchar_t ) ) )
+ {
+ uint32 cchAlloc = static_cast<uint32>( V_wcslen( pwchTemp ) ) + 1;
+ wchar_t *pwchHeap = new wchar_t[ cchAlloc ];
+ V_wcsncpy( pwchHeap, pwchTemp, cchAlloc * sizeof( wchar_t ) );
+ delete [] pwchTemp;
+ m_pwch = pwchHeap;
+ }
+ else
+ {
+ // do nothing, and leave the UTF-16 string NULL
+ delete [] pwchTemp;
+ }
+ }
+
+#if !defined( WIN32 ) && !defined(_WIN32)
+ // ensure we have done any conversion work required to farm out a
+ // UTF-16 encoded string.
+ //
+ // We perform two heap allocs here; the first one is the worst-case
+ // (one code point per UTF-8 byte). This is sometimes pessimistic,
+ // so we perform a second allocation that's just the size we need.
+ void PopulateUCS2()
+ {
+ if ( m_bCreatedUCS2 )
+ return;
+ if ( m_pch == NULL )
+ return; // no UTF-8 string to convert
+ if ( m_pucs2 != NULL )
+ return; // already been converted to UTF-16; no work to do
+
+ uint32 cchMax = static_cast<uint32>( V_strlen( m_pch ) ) + 1;
+ ucs2 *pwchTemp = new ucs2[ cchMax ];
+ if ( V_UTF8ToUCS2( m_pch, cchMax, pwchTemp, cchMax * sizeof( ucs2 ) ) )
+ {
+ uint32 cchAlloc = cchMax;
+ ucs2 *pwchHeap = new ucs2[ cchAlloc ];
+ memcpy( pwchHeap, pwchTemp, cchAlloc * sizeof( ucs2 ) );
+ delete [] pwchTemp;
+ m_pucs2 = pwchHeap;
+ }
+ else
+ {
+ // do nothing, and leave the UTF-16 string NULL
+ delete [] pwchTemp;
+ }
+ }
+#endif
+
+ // one of these pointers is an owned pointer; whichever
+ // one is the encoding OTHER than the one we were initialized
+ // with is the pointer we've allocated and must free.
+ const char *m_pch;
+ const wchar_t *m_pwch;
+#if !defined( WIN32 ) && !defined(_WIN32)
+ const ucs2 *m_pucs2;
+ bool m_bCreatedUCS2;
+#endif
+ // "created as UTF-16", means our owned string is the UTF-8 string not the UTF-16 one.
+ bool m_bCreatedUTF16;
+
+};
+
+
+#define V_UTF8ToUnicode V_UTF8ToUnicode
+#define V_UnicodeToUTF8 V_UnicodeToUTF8
+
+
+#endif \ No newline at end of file