public/ILibrarySys.h
author Phong Dang <teame06@gmail.com>
Wed Aug 01 07:29:40 2007 +0000 (2007-08-01)
changeset 1241 2e8046793bc9
parent 1226 478550a4d5ec
child 1330 ab94316bb52b
permissions -rw-r--r--
Added check to make sure player are alive to perform sm_slap, sm_burn, sm_slay.
     1 /**
     2  * vim: set ts=4 :
     3  * ================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     6  * ================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or 
     9  * modify it under the terms of the GNU General Public License, 
    10  * version 3.0, as published by the Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  * GNU General Public License for more details.
    16  *
    17  * You should have received a copy of the GNU General Public License
    18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to 
    21  * link the code of this program (as well as its derivative works) to 
    22  * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any 
    23  * Game MODs that run on software by the Valve Corporation.  You must 
    24  * obey the GNU General Public License in all respects for all other 
    25  * code used. Additionally, AlliedModders LLC grants this exception 
    26  * to all derivative works. AlliedModders LLC defines further 
    27  * exceptions, found in LICENSE.txt (as of this writing, version 
    28  * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #ifndef _INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_
    34 #define _INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_
    35 
    36 /**
    37  * @file ILibrarySys.h
    38  * @brief Defines platform-dependent operations, such as opening libraries and files.
    39  */
    40 
    41 #include <IShareSys.h>
    42 
    43 namespace SourceMod
    44 {
    45 	#define SMINTERFACE_LIBRARYSYS_NAME		"ILibrarySys"
    46 	#define SMINTERFACE_LIBRARYSYS_VERSION	3
    47 
    48 	class ILibrary
    49 	{
    50 	public:
    51 		/** Virtual destructor (calls CloseLibrary) */
    52 		virtual ~ILibrary()
    53 		{
    54 		};
    55 	public:
    56 		/**
    57 		 * @brief Closes dynamic library and invalidates pointer.
    58 		 */
    59 		virtual void CloseLibrary() =0;
    60 
    61 		/**
    62 		 * @brief Retrieves a symbol pointer from the dynamic library.
    63 		 *
    64 		 * @param symname	Symbol name.
    65 		 * @return			Symbol pointer, NULL if not found.
    66 		 */
    67 		virtual void *GetSymbolAddress(const char *symname) =0;
    68 	};
    69 
    70 	/**
    71 	 * @brief Directory browsing abstraction.
    72 	 */
    73 	class IDirectory
    74 	{
    75 	public:
    76 		/** Virtual destructor */
    77 		virtual ~IDirectory()
    78 		{
    79 		}
    80 	public:
    81 		/**
    82 		 * @brief Returns true if there are more files to read, false otherwise.
    83 		 */
    84 		virtual bool MoreFiles() =0;
    85 
    86 		/**
    87 		 * @brief Advances to the next entry in the stream.
    88 		 */
    89 		virtual void NextEntry() =0;
    90 
    91 		/**
    92 		 * @brief Returns the name of the current entry.
    93 		 */
    94 		virtual const char *GetEntryName() =0;
    95 
    96 		/**
    97 		 * @brief Returns whether the current entry is a directory.
    98 		 */
    99 		virtual bool IsEntryDirectory() =0;
   100 
   101 		/**
   102 		 * @brief Returns whether the current entry is a file.
   103 		 */
   104 		virtual bool IsEntryFile() =0;
   105 
   106 		/**
   107 		 * @brief Returns true if the current entry is valid
   108 		 *        (Used similarly to MoreFiles).
   109 		 */
   110 		virtual bool IsEntryValid() =0;
   111 	};
   112 
   113 	/**
   114 	 * @brief Contains various operating system specific code.
   115 	 */
   116 	class ILibrarySys : public SMInterface
   117 	{
   118 	public:
   119 		virtual const char *GetInterfaceName()
   120 		{
   121 			return SMINTERFACE_LIBRARYSYS_NAME;
   122 		}
   123 		virtual unsigned int GetInterfaceVersion()
   124 		{
   125 			return SMINTERFACE_LIBRARYSYS_VERSION;
   126 		}
   127 	public:
   128 		/**
   129 		 * @brief Opens a dynamic library file.
   130 		 * 
   131 		 * @param path		Path to library file (.dll/.so).
   132 		 * @param error		Buffer for any error message (may be NULL).
   133 		 * @param maxlength	Maximum length of error buffer.
   134 		 * @return			Pointer to an ILibrary, NULL if failed.
   135 		 */
   136 		virtual ILibrary *OpenLibrary(const char *path, char *error, size_t maxlength) =0;
   137 
   138 		/**
   139 		 * @brief Opens a directory for reading.
   140 		 *
   141 		 * @param path		Path to directory.
   142 		 * @return			Pointer to an IDirectory, NULL if failed.
   143 		 */
   144 		virtual IDirectory *OpenDirectory(const char *path) =0;
   145 
   146 		/**
   147 		 * @brief Closes a directory and frees its handle.
   148 		 * 
   149 		 * @param dir		Pointer to IDirectory.
   150 		 */
   151 		virtual void CloseDirectory(IDirectory *dir) =0;
   152 
   153 		/**
   154 		 * @brief Returns true if a path exists.
   155 		 */
   156 		virtual bool PathExists(const char *path) =0;
   157 
   158 		/**
   159 		 * @brief Returns true if the path is a normal file.
   160 		 */
   161 		virtual bool IsPathFile(const char *path) =0;
   162 
   163 		/**
   164 		 * @brief Returns true if the path is a normal directory.
   165 		 */
   166 		virtual bool IsPathDirectory(const char *path) =0;
   167 
   168 		/**
   169 		 * @brief Gets a platform-specific error message.
   170 		 * This should only be called when an ILibrary function fails.
   171 		 * Win32 equivalent: GetLastError() + FormatMessage()
   172 		 * POSIX equivalent: errno + strerror()
   173 		 *
   174 		 * @param error		Error message buffer.
   175 		 * @param maxlength	Maximum length of error buffer.
   176 		 */
   177 		virtual void GetPlatformError(char *error, size_t maxlength) =0;
   178 
   179 		/**
   180 		 * @brief Formats a string similar to snprintf(), except
   181 		 * corrects all non-platform compatible path separators to be
   182 		 * the correct platform character.
   183 		 *
   184 		 * @param buffer	Output buffer pointer.
   185 		 * @param maxlength	Output buffer size.
   186 		 * @param pathfmt	Format string of path.
   187 		 * @param ...		Format string arguments.
   188 		 */
   189 		virtual size_t PathFormat(char *buffer, size_t maxlength, const char *pathfmt, ...) =0;
   190 
   191 		/**
   192 		 * @brief Returns a pointer to the extension in a filename.
   193 		 *
   194 		 * @param filename	Name of file from which the extension should be extracted.
   195 		 * @return			Pointer to file extension.
   196 		 */
   197 		virtual const char *GetFileExtension(const char *filename) =0;
   198 
   199 		/**
   200 		 * @brief Creates a directory.
   201 		 *
   202 		 * @param path		Full, absolute path of the directory to create.
   203 		 * @return			True on success, false otherwise.
   204 		 */
   205 		virtual bool CreateFolder(const char *path) =0;
   206 	};
   207 }
   208 
   209 #endif //_INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_