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