core/convar_sm_l4d.h
author Drifter <rgr_02@comcast.net>
Wed May 30 23:00:16 2012 -0400 (2012-05-30)
changeset 3543 9287a18e9a33
parent 3138 b7625c10af59
child 3961 0dc477c29792
permissions -rw-r--r--
Fix for SDKTools TeamScore natives crash on CS:GO (bug 5319, r=psychonic).
     1 //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
     2 //
     3 // Purpose: 
     4 //
     5 // $Workfile:     $
     6 // $Date:         $
     7 //
     8 //-----------------------------------------------------------------------------
     9 // $NoKeywords: $
    10 //===========================================================================//
    11 
    12 #ifndef CONVAR_H
    13 #define CONVAR_H
    14 
    15 #if _WIN32
    16 #pragma once
    17 #endif
    18 
    19 #include "tier0/dbg.h"
    20 #include "tier1/iconvar.h"
    21 #include "tier1/utlvector.h"
    22 #include "tier1/utlstring.h"
    23 #include "icvar.h"
    24 
    25 #ifdef _WIN32
    26 #define FORCEINLINE_CVAR FORCEINLINE
    27 #elif defined _LINUX || defined __APPLE__
    28 #define FORCEINLINE_CVAR inline
    29 #else
    30 #error "implement me"
    31 #endif
    32 
    33 
    34 //-----------------------------------------------------------------------------
    35 // Forward declarations
    36 //-----------------------------------------------------------------------------
    37 class ConVar;
    38 class CCommand;
    39 class ConCommand;
    40 class ConCommandBase;
    41 struct characterset_t;
    42 
    43 
    44 
    45 //-----------------------------------------------------------------------------
    46 // Any executable that wants to use ConVars need to implement one of
    47 // these to hook up access to console variables.
    48 //-----------------------------------------------------------------------------
    49 class IConCommandBaseAccessor
    50 {
    51 public:
    52 	// Flags is a combination of FCVAR flags in cvar.h.
    53 	// hOut is filled in with a handle to the variable.
    54 	virtual bool RegisterConCommandBase( ConCommandBase *pVar ) = 0;
    55 };
    56 
    57 
    58 //-----------------------------------------------------------------------------
    59 // Helper method for console development
    60 //-----------------------------------------------------------------------------
    61 #if defined( _X360 ) && !defined( _RETAIL )
    62 void ConVar_PublishToVXConsole();
    63 #endif
    64 
    65 
    66 //-----------------------------------------------------------------------------
    67 // Called when a ConCommand needs to execute
    68 //-----------------------------------------------------------------------------
    69 typedef void ( *FnCommandCallbackV1_t )( void );
    70 typedef void ( *FnCommandCallback_t )( const CCommand &command );
    71 
    72 #define COMMAND_COMPLETION_MAXITEMS		64
    73 #define COMMAND_COMPLETION_ITEM_LENGTH	64
    74 
    75 //-----------------------------------------------------------------------------
    76 // Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings
    77 //-----------------------------------------------------------------------------
    78 typedef int  ( *FnCommandCompletionCallback )( const char *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] );
    79 
    80 
    81 //-----------------------------------------------------------------------------
    82 // Interface version
    83 //-----------------------------------------------------------------------------
    84 class ICommandCallback
    85 {
    86 public:
    87 	virtual void CommandCallback( const CCommand &command ) = 0;
    88 };
    89 
    90 class ICommandCompletionCallback
    91 {
    92 public:
    93 	virtual int  CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) = 0;
    94 };
    95 
    96 //-----------------------------------------------------------------------------
    97 // Purpose: The base console invoked command/cvar interface
    98 //-----------------------------------------------------------------------------
    99 class ConCommandBase
   100 {
   101 	friend class CCvar;
   102 	friend class ConVar;
   103 	friend class ConCommand;
   104 	friend void ConVar_Register( int nCVarFlag, IConCommandBaseAccessor *pAccessor );
   105 	friend void ConVar_PublishToVXConsole();
   106 
   107 	// FIXME: Remove when ConVar changes are done
   108 	friend class CDefaultCvar;
   109 
   110 public:
   111 								ConCommandBase( void );
   112 								ConCommandBase( const char *pName, const char *pHelpString = 0, 
   113 									int flags = 0 );
   114 
   115 	virtual						~ConCommandBase( void );
   116 
   117 	virtual	bool				IsCommand( void ) const;
   118 
   119 	// Check flag
   120 	virtual bool				IsFlagSet( int flag ) const;
   121 	// Set flag
   122 	virtual void				AddFlags( int flags );
   123 	// Remove flag
   124 	virtual void				RemoveFlags( int flags );
   125 	// Get flags
   126 	virtual int					GetFlags( void ) const;
   127 
   128 	// Return name of cvar
   129 	virtual const char			*GetName( void ) const;
   130 
   131 	// Return help text for cvar
   132 	virtual const char			*GetHelpText( void ) const;
   133 
   134 	// Deal with next pointer
   135 	const ConCommandBase		*GetNext( void ) const;
   136 	ConCommandBase				*GetNext( void );
   137 
   138 	inline void SetNext(ConCommandBase *pBase)
   139 	{
   140 		m_pNext = pBase;
   141 	}
   142 	
   143 	virtual bool				IsRegistered( void ) const;
   144 
   145 	// Returns the DLL identifier
   146 	virtual CVarDLLIdentifier_t	GetDLLIdentifier() const;
   147 
   148 protected:
   149 	virtual void				Create( const char *pName, const char *pHelpString = 0, 
   150 									int flags = 0 );
   151 
   152 	// Used internally by OneTimeInit to initialize/shutdown
   153 	virtual void				Init();
   154 	void						Shutdown();
   155 
   156 	// Internal copy routine ( uses new operator from correct module )
   157 	char						*CopyString( const char *from );
   158 
   159 private:
   160 	// Next ConVar in chain
   161 	// Prior to register, it points to the next convar in the DLL.
   162 	// Once registered, though, m_pNext is reset to point to the next
   163 	// convar in the global list
   164 	ConCommandBase				*m_pNext;
   165 
   166 	// Has the cvar been added to the global list?
   167 	bool						m_bRegistered;
   168 
   169 	// Static data
   170 	const char 					*m_pszName;
   171 	const char 					*m_pszHelpString;
   172 	
   173 	// ConVar flags
   174 	int							m_nFlags;
   175 
   176 protected:
   177 	// ConVars add themselves to this list for the executable. 
   178 	// Then ConVar_Register runs through  all the console variables 
   179 	// and registers them into a global list stored in vstdlib.dll
   180 	static ConCommandBase		*s_pConCommandBases;
   181 
   182 	// ConVars in this executable use this 'global' to access values.
   183 	static IConCommandBaseAccessor	*s_pAccessor;
   184 public:
   185 	inline void SetFlags(int flags)	
   186 	{ 
   187 		m_nFlags = flags; 
   188 	}
   189 };
   190 
   191 
   192 //-----------------------------------------------------------------------------
   193 // Command tokenizer
   194 //-----------------------------------------------------------------------------
   195 class CCommand
   196 {
   197 public:
   198 	CCommand();
   199 	CCommand( int nArgC, const char **ppArgV );
   200 	bool Tokenize( const char *pCommand, characterset_t *pBreakSet = NULL );
   201 	void Reset();
   202 
   203 	int ArgC() const;
   204 	const char **ArgV() const;
   205 	const char *ArgS() const;					// All args that occur after the 0th arg, in string form
   206 	const char *GetCommandString() const;		// The entire command in string form, including the 0th arg
   207 	const char *operator[]( int nIndex ) const;	// Gets at arguments
   208 	const char *Arg( int nIndex ) const;		// Gets at arguments
   209 	
   210 	// Helper functions to parse arguments to commands.
   211 	const char* FindArg( const char *pName ) const;
   212 	int FindArgInt( const char *pName, int nDefaultVal ) const;
   213 
   214 	static int MaxCommandLength();
   215 	static characterset_t* DefaultBreakSet();
   216 
   217 private:
   218 	enum
   219 	{
   220 		COMMAND_MAX_ARGC = 64,
   221 		COMMAND_MAX_LENGTH = 512,
   222 	};
   223 
   224 	int		m_nArgc;
   225 	int		m_nArgv0Size;
   226 	char	m_pArgSBuffer[ COMMAND_MAX_LENGTH ];
   227 	char	m_pArgvBuffer[ COMMAND_MAX_LENGTH ];
   228 	const char*	m_ppArgv[ COMMAND_MAX_ARGC ];
   229 };
   230 
   231 inline int CCommand::MaxCommandLength()
   232 {
   233 	return COMMAND_MAX_LENGTH - 1;
   234 }
   235 
   236 inline int CCommand::ArgC() const
   237 {
   238 	return m_nArgc;
   239 }
   240 
   241 inline const char **CCommand::ArgV() const
   242 {
   243 	return m_nArgc ? (const char**)m_ppArgv : NULL;
   244 }
   245 
   246 inline const char *CCommand::ArgS() const
   247 {
   248 	return m_nArgv0Size ? &m_pArgSBuffer[m_nArgv0Size] : "";
   249 }
   250 
   251 inline const char *CCommand::GetCommandString() const
   252 {
   253 	return m_nArgc ? m_pArgSBuffer : "";
   254 }
   255 
   256 inline const char *CCommand::Arg( int nIndex ) const
   257 {
   258 	// FIXME: Many command handlers appear to not be particularly careful
   259 	// about checking for valid argc range. For now, we're going to
   260 	// do the extra check and return an empty string if it's out of range
   261 	if ( nIndex < 0 || nIndex >= m_nArgc )
   262 		return "";
   263 	return m_ppArgv[nIndex];
   264 }
   265 
   266 inline const char *CCommand::operator[]( int nIndex ) const
   267 {
   268 	return Arg( nIndex );
   269 }
   270 
   271 
   272 //-----------------------------------------------------------------------------
   273 // Purpose: The console invoked command
   274 //-----------------------------------------------------------------------------
   275 class ConCommand : public ConCommandBase
   276 {
   277 friend class CCvar;
   278 
   279 public:
   280 	typedef ConCommandBase BaseClass;
   281 
   282 	ConCommand( const char *pName, FnCommandCallbackV1_t callback, 
   283 		const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
   284 	ConCommand( const char *pName, FnCommandCallback_t callback, 
   285 		const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
   286 	ConCommand( const char *pName, ICommandCallback *pCallback, 
   287 		const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 );
   288 
   289 	virtual ~ConCommand( void );
   290 
   291 	virtual	bool IsCommand( void ) const;
   292 
   293 	virtual int AutoCompleteSuggest( const char *partial, CUtlVector< CUtlString > &commands );
   294 
   295 	virtual bool CanAutoComplete( void );
   296 
   297 	// Invoke the function
   298 	virtual void Dispatch( const CCommand &command );
   299 
   300 private:
   301 	// NOTE: To maintain backward compat, we have to be very careful:
   302 	// All public virtual methods must appear in the same order always
   303 	// since engine code will be calling into this code, which *does not match*
   304 	// in the mod code; it's using slightly different, but compatible versions
   305 	// of this class. Also: Be very careful about adding new fields to this class.
   306 	// Those fields will not exist in the version of this class that is instanced
   307 	// in mod code.
   308 
   309 	// Call this function when executing the command
   310 	union
   311 	{
   312 		FnCommandCallbackV1_t m_fnCommandCallbackV1;
   313 		FnCommandCallback_t m_fnCommandCallback;
   314 		ICommandCallback *m_pCommandCallback; 
   315 	};
   316 
   317 	union
   318 	{
   319 		FnCommandCompletionCallback	m_fnCompletionCallback;
   320 		ICommandCompletionCallback *m_pCommandCompletionCallback;
   321 	};
   322 
   323 	bool m_bHasCompletionCallback : 1;
   324 	bool m_bUsingNewCommandCallback : 1;
   325 	bool m_bUsingCommandCallbackInterface : 1;
   326 public:
   327 	inline FnCommandCallback_t GetCallback() const
   328 	{ 
   329 		return m_fnCommandCallback; 
   330 	}
   331 };
   332 
   333 
   334 //-----------------------------------------------------------------------------
   335 // Purpose: A console variable
   336 //-----------------------------------------------------------------------------
   337 class ConVar : public ConCommandBase, public IConVar
   338 {
   339 friend class CCvar;
   340 friend class ConVarRef;
   341 
   342 public:
   343 	typedef ConCommandBase BaseClass;
   344 
   345 								ConVar( const char *pName, const char *pDefaultValue, int flags = 0);
   346 
   347 								ConVar( const char *pName, const char *pDefaultValue, int flags, 
   348 									const char *pHelpString );
   349 								ConVar( const char *pName, const char *pDefaultValue, int flags, 
   350 									const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax );
   351 								ConVar( const char *pName, const char *pDefaultValue, int flags, 
   352 									const char *pHelpString, FnChangeCallback_t callback );
   353 								ConVar( const char *pName, const char *pDefaultValue, int flags, 
   354 									const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax,
   355 									FnChangeCallback_t callback );
   356 
   357 	virtual						~ConVar( void );
   358 
   359 	virtual	bool				IsCommand( void ) const;
   360 	virtual bool				IsFlagSet( int flag ) const;
   361 	virtual void				AddFlags( int flags );
   362 	virtual int					GetFlags( void ) const;
   363 	virtual const char			*GetName( void ) const;
   364 	virtual const char*			GetHelpText( void ) const;
   365 	virtual bool				IsRegistered( void ) const;
   366 		
   367 	// Install a change callback (there shouldn't already be one....)
   368 	void InstallChangeCallback( FnChangeCallback_t callback );
   369 
   370 	// Retrieve value
   371 	FORCEINLINE_CVAR float			GetFloat( void ) const;
   372 	FORCEINLINE_CVAR int			GetInt( void ) const;
   373 	FORCEINLINE_CVAR bool			GetBool() const {  return !!GetInt(); }
   374 	FORCEINLINE_CVAR char const	   *GetString( void ) const;
   375 	
   376 	// Used internally by OneTimeInit to initialize.
   377 	virtual void				Init();
   378 	
   379 	virtual const char 			*GetBaseName( void ) const;
   380 	virtual int					GetSplitScreenPlayerSlot ( void ) const;
   381 
   382 	// Any function that allocates/frees memory needs to be virtual or else you'll have crashes
   383 	//  from alloc/free across dll/exe boundaries.
   384 	
   385 	// These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue).
   386 	virtual void				SetValue( const char *value );
   387 	virtual void				SetValue( float value );
   388 	virtual void				SetValue( int value );
   389 #if SOURCE_ENGINE >= SE_LEFT4DEAD2
   390 	virtual void				SetValue( Color value );
   391 #endif
   392 	
   393 	// Reset to default value
   394 	void						Revert( void );
   395 
   396 	// True if it has a min/max setting
   397 	bool						GetMin( float& minVal ) const;
   398 	bool						GetMax( float& maxVal ) const;
   399 	const char					*GetDefault( void ) const;
   400 
   401 private:
   402 	// Called by CCvar when the value of a var is changing.
   403 	virtual void				InternalSetValue(const char *value);
   404 	// For CVARs marked FCVAR_NEVER_AS_STRING
   405 	virtual void				InternalSetFloatValue( float fNewValue );
   406 	virtual void				InternalSetIntValue( int nValue );
   407 #if SOURCE_ENGINE >= SE_LEFT4DEAD2
   408 	virtual void				InternalSetColorValue( Color value );
   409 #endif
   410 
   411 	virtual bool				ClampValue( float& value );
   412 	virtual void				ChangeStringValue( const char *tempVal, float flOldValue );
   413 
   414 	virtual void				Create( const char *pName, const char *pDefaultValue, int flags = 0,
   415 									const char *pHelpString = 0, bool bMin = false, float fMin = 0.0,
   416 									bool bMax = false, float fMax = false, FnChangeCallback_t callback = 0 );
   417 
   418 private:
   419 
   420 	// This either points to "this" or it points to the original declaration of a ConVar.
   421 	// This allows ConVars to exist in separate modules, and they all use the first one to be declared.
   422 	// m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar).
   423 	ConVar						*m_pParent;
   424 
   425 	// Static data
   426 	const char					*m_pszDefaultValue;
   427 	
   428 	// Value
   429 	// Dynamically allocated
   430 	char						*m_pszString;
   431 	int							m_StringLength;
   432 
   433 	// Values
   434 	float						m_fValue;
   435 	int							m_nValue;
   436 
   437 	// Min/Max values
   438 	bool						m_bHasMin;
   439 	float						m_fMinVal;
   440 	bool						m_bHasMax;
   441 	float						m_fMaxVal;
   442 	
   443 	// Call this function when ConVar changes
   444 	FnChangeCallback_t			m_fnChangeCallback;
   445 public:
   446 	inline FnChangeCallback_t GetCallback() const
   447 	{
   448 		return m_fnChangeCallback;
   449 	}
   450 	inline void SetMin(bool set, float min=0.0)
   451 	{ 
   452 		m_bHasMin = set; 
   453 		m_fMinVal = min; 
   454 	}
   455 	inline void SetMax(bool set, float max=0.0)
   456 	{
   457 		m_bHasMax = set;
   458 		m_fMaxVal = max; 
   459 	}
   460 };
   461 
   462 
   463 //-----------------------------------------------------------------------------
   464 // Purpose: Return ConVar value as a float
   465 // Output : float
   466 //-----------------------------------------------------------------------------
   467 FORCEINLINE_CVAR float ConVar::GetFloat( void ) const
   468 {
   469 	return m_pParent->m_fValue;
   470 }
   471 
   472 //-----------------------------------------------------------------------------
   473 // Purpose: Return ConVar value as an int
   474 // Output : int
   475 //-----------------------------------------------------------------------------
   476 FORCEINLINE_CVAR int ConVar::GetInt( void ) const 
   477 {
   478 	return m_pParent->m_nValue;
   479 }
   480 
   481 
   482 //-----------------------------------------------------------------------------
   483 // Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
   484 // Output : const char *
   485 //-----------------------------------------------------------------------------
   486 FORCEINLINE_CVAR const char *ConVar::GetString( void ) const 
   487 {
   488 	if ( m_nFlags & FCVAR_NEVER_AS_STRING )
   489 		return "FCVAR_NEVER_AS_STRING";
   490 
   491 	return ( m_pParent->m_pszString ) ? m_pParent->m_pszString : "";
   492 }
   493 
   494 
   495 //-----------------------------------------------------------------------------
   496 // Used to read/write convars that already exist (replaces the FindVar method)
   497 //-----------------------------------------------------------------------------
   498 class ConVarRef
   499 {
   500 public:
   501 	ConVarRef( const char *pName );
   502 	ConVarRef( const char *pName, bool bIgnoreMissing );
   503 	ConVarRef( IConVar *pConVar );
   504 
   505 	void Init( const char *pName, bool bIgnoreMissing );
   506 	bool IsValid() const;
   507 	bool IsFlagSet( int nFlags ) const;
   508 	IConVar *GetLinkedConVar();
   509 
   510 	// Get/Set value
   511 	float GetFloat( void ) const;
   512 	int GetInt( void ) const;
   513 	bool GetBool() const { return !!GetInt(); }
   514 	const char *GetString( void ) const;
   515 
   516 	void SetValue( const char *pValue );
   517 	void SetValue( float flValue );
   518 	void SetValue( int nValue );
   519 	void SetValue( bool bValue );
   520 
   521 	const char *GetName() const;
   522 
   523 	const char *GetDefault() const;
   524 
   525 private:
   526 	// High-speed method to read convar data
   527 	IConVar *m_pConVar;
   528 	ConVar *m_pConVarState;
   529 };
   530 
   531 
   532 //-----------------------------------------------------------------------------
   533 // Did we find an existing convar of that name?
   534 //-----------------------------------------------------------------------------
   535 FORCEINLINE_CVAR bool ConVarRef::IsFlagSet( int nFlags ) const
   536 {
   537 	return ( m_pConVar->IsFlagSet( nFlags ) != 0 );
   538 }
   539 
   540 FORCEINLINE_CVAR IConVar *ConVarRef::GetLinkedConVar()
   541 {
   542 	return m_pConVar;
   543 }
   544 
   545 FORCEINLINE_CVAR const char *ConVarRef::GetName() const
   546 {
   547 	return m_pConVar->GetName();
   548 }
   549 
   550 
   551 //-----------------------------------------------------------------------------
   552 // Purpose: Return ConVar value as a float
   553 //-----------------------------------------------------------------------------
   554 FORCEINLINE_CVAR float ConVarRef::GetFloat( void ) const
   555 {
   556 	return m_pConVarState->m_fValue;
   557 }
   558 
   559 //-----------------------------------------------------------------------------
   560 // Purpose: Return ConVar value as an int
   561 //-----------------------------------------------------------------------------
   562 FORCEINLINE_CVAR int ConVarRef::GetInt( void ) const 
   563 {
   564 	return m_pConVarState->m_nValue;
   565 }
   566 
   567 //-----------------------------------------------------------------------------
   568 // Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
   569 //-----------------------------------------------------------------------------
   570 FORCEINLINE_CVAR const char *ConVarRef::GetString( void ) const 
   571 {
   572 	Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) );
   573 	return m_pConVarState->m_pszString;
   574 }
   575 
   576 
   577 FORCEINLINE_CVAR void ConVarRef::SetValue( const char *pValue )
   578 {
   579 	m_pConVar->SetValue( pValue );
   580 }
   581 
   582 FORCEINLINE_CVAR void ConVarRef::SetValue( float flValue )
   583 {
   584 	m_pConVar->SetValue( flValue );
   585 }
   586 
   587 FORCEINLINE_CVAR void ConVarRef::SetValue( int nValue )
   588 {
   589 	m_pConVar->SetValue( nValue );
   590 }
   591 
   592 FORCEINLINE_CVAR void ConVarRef::SetValue( bool bValue )
   593 {
   594 	m_pConVar->SetValue( bValue ? 1 : 0 );
   595 }
   596 
   597 FORCEINLINE_CVAR const char *ConVarRef::GetDefault() const
   598 {
   599 	return m_pConVarState->m_pszDefaultValue;
   600 }
   601 
   602 
   603 //-----------------------------------------------------------------------------
   604 // Called by the framework to register ConCommands with the ICVar
   605 //-----------------------------------------------------------------------------
   606 void ConVar_Register( int nCVarFlag = 0, IConCommandBaseAccessor *pAccessor = NULL );
   607 void ConVar_Unregister( );
   608 
   609 
   610 //-----------------------------------------------------------------------------
   611 // Utility methods 
   612 //-----------------------------------------------------------------------------
   613 void ConVar_PrintFlags( const ConCommandBase *var );
   614 void ConVar_PrintDescription( const ConCommandBase *pVar );
   615 
   616 
   617 //-----------------------------------------------------------------------------
   618 // Purpose: Utility class to quickly allow ConCommands to call member methods
   619 //-----------------------------------------------------------------------------
   620 #ifdef _MSC_VER
   621 #pragma warning (disable : 4355 )
   622 #endif
   623 
   624 template< class T >
   625 class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback
   626 {
   627 	typedef ConCommand BaseClass;
   628 	typedef void ( T::*FnMemberCommandCallback_t )( const CCommand &command );
   629 	typedef int  ( T::*FnMemberCommandCompletionCallback_t )( const char *pPartial, CUtlVector< CUtlString > &commands );
   630 
   631 public:
   632 	CConCommandMemberAccessor( T* pOwner, const char *pName, FnMemberCommandCallback_t callback, const char *pHelpString = 0,
   633 		int flags = 0, FnMemberCommandCompletionCallback_t completionFunc = 0 ) :
   634 		BaseClass( pName, this, pHelpString, flags, ( completionFunc != 0 ) ? this : NULL )
   635 	{
   636 		m_pOwner = pOwner;
   637 		m_Func = callback;
   638 		m_CompletionFunc = completionFunc;
   639 	}
   640 
   641 	~CConCommandMemberAccessor()
   642 	{
   643 		Shutdown();
   644 	}
   645 
   646 	void SetOwner( T* pOwner )
   647 	{
   648 		m_pOwner = pOwner;
   649 	}
   650 
   651 	virtual void CommandCallback( const CCommand &command )
   652 	{
   653 		Assert( m_pOwner && m_Func );
   654 		(m_pOwner->*m_Func)( command );
   655 	}
   656 
   657 	virtual int  CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands )
   658 	{
   659 		Assert( m_pOwner && m_CompletionFunc );
   660 		return (m_pOwner->*m_CompletionFunc)( pPartial, commands );
   661 	}
   662 
   663 private:
   664 	T* m_pOwner;
   665 	FnMemberCommandCallback_t m_Func;
   666 	FnMemberCommandCompletionCallback_t m_CompletionFunc;
   667 };
   668 
   669 #ifdef _MSC_VER
   670 #pragma warning ( default : 4355 )
   671 #endif
   672 
   673 //-----------------------------------------------------------------------------
   674 // Purpose: Utility macros to quicky generate a simple console command
   675 //-----------------------------------------------------------------------------
   676 #define CON_COMMAND( name, description ) \
   677    static void name( const CCommand &args ); \
   678    static ConCommand name##_command( #name, name, description ); \
   679    static void name( const CCommand &args )
   680 
   681 #define CON_COMMAND_F( name, description, flags ) \
   682    static void name( const CCommand &args ); \
   683    static ConCommand name##_command( #name, name, description, flags ); \
   684    static void name( const CCommand &args )
   685 
   686 #define CON_COMMAND_F_COMPLETION( name, description, flags, completion ) \
   687 	static void name( const CCommand &args ); \
   688 	static ConCommand name##_command( #name, name, description, flags, completion ); \
   689 	static void name( const CCommand &args )
   690 
   691 #define CON_COMMAND_EXTERN( name, _funcname, description ) \
   692 	void _funcname( const CCommand &args ); \
   693 	static ConCommand name##_command( #name, _funcname, description ); \
   694 	void _funcname( const CCommand &args )
   695 
   696 #define CON_COMMAND_EXTERN_F( name, _funcname, description, flags ) \
   697 	void _funcname( const CCommand &args ); \
   698 	static ConCommand name##_command( #name, _funcname, description, flags ); \
   699 	void _funcname( const CCommand &args )
   700 
   701 #define CON_COMMAND_MEMBER_F( _thisclass, name, _funcname, description, flags ) \
   702 	void _funcname( const CCommand &args );						\
   703 	friend class CCommandMemberInitializer_##_funcname;			\
   704 	class CCommandMemberInitializer_##_funcname					\
   705 	{															\
   706 	public:														\
   707 		CCommandMemberInitializer_##_funcname() : m_ConCommandAccessor( NULL, name, &_thisclass::_funcname, description, flags )	\
   708 		{														\
   709 			m_ConCommandAccessor.SetOwner( GET_OUTER( _thisclass, m_##_funcname##_register ) );	\
   710 		}														\
   711 	private:													\
   712 		CConCommandMemberAccessor< _thisclass > m_ConCommandAccessor;	\
   713 	};															\
   714 																\
   715 	CCommandMemberInitializer_##_funcname m_##_funcname##_register;		\
   716 
   717 
   718 #endif // CONVAR_H