00001 //--------------------------------------------------------------------------- 00002 /// \file CATPlatform.h 00003 /// \brief Platform-specific object creation 00004 /// \ingroup CAT 00005 /// 00006 /// Copyright (c) 2003-2008 by Michael Ellison. 00007 /// See COPYING.txt for the \ref gaslicense License (MIT License). 00008 /// 00009 // $Author: mikeellison $ 00010 // $Date: 2008-01-21 08:33:12 -0600 (Mon, 21 Jan 2008) $ 00011 // $Revision: $ 00012 // $NoKeywords: $ 00013 // 00014 //--------------------------------------------------------------------------- 00015 #ifndef CATPlatform_H_ 00016 #define CATPlatform_H_ 00017 00018 #include "CATTypes.h" 00019 #include "CATString.h" 00020 00021 class CATFileSystem; 00022 00023 /// \class CATPlatform 00024 /// \brief Platform-specific object creation 00025 /// \ingroup CAT 00026 /// 00027 /// When a base class needs more than a few members that are platform- 00028 /// specific, it can get downright fugly to use #ifdef. CATPlatform tries 00029 /// to solve this problem. 00030 /// 00031 /// For such classes, create a pure virtual interface class. Then, create a 00032 /// child class for each platform. Then, include the pure virtual class 00033 /// in whatever source you need to create such an object in and include 00034 /// CATPlatform. When you need the object, acquire it from CATPlatform by 00035 /// calling Get[ClassName]() - CATPlatform will create your object for you. 00036 /// 00037 /// You can then use it using the pure interface. To free it, call 00038 /// CATPlatform::Release() on the object. 00039 /// 00040 /// Note: Currently, most of the classes done this way are NOT reference 00041 /// counted. Instead, you get an actual new object each time, then it really 00042 /// goes away when you call CATPlatform::Release(). Don't try tricky copying 00043 /// stuff and expect the copy to work after you release the original or vise- 00044 /// versa. In the future, some objects may be made singleton or reference 00045 /// counted here, however. Your best bet is to call the Get* functions when 00046 /// you need an object, and the Release() when you're done with it - leave 00047 /// system-wide optimizations to the CATPlatform object. 00048 /// 00049 /// Release() also sets the incoming referenced pointer to NULL to discourage 00050 /// hanging pointer errors. 00051 /// 00052 /// There is no CATPlatform.cpp. Instead, for each platform, there is a 00053 /// seperate CATPlatform_PLATFORM.cpp file. Only place the appropriate 00054 /// platform file in your project (or exclude the others from compile). 00055 class CATPlatform 00056 { 00057 public: 00058 CATPlatform(); 00059 virtual ~CATPlatform(); 00060 00061 /// GetFileSystem() acquires the appropriate file system for the path. 00062 /// 00063 /// Call CATFileSystem::Initialize() on the returned file system 00064 /// before using it. Call CATPlatform::Release() on the object 00065 /// when done. 00066 /// 00067 /// \param basePath - base path to start file system at. 00068 CATFileSystem* GetFileSystem( const CATString& basePath = ""); 00069 00070 /// Release() function for CATFileSystem objects. 00071 /// \param fileSys - ref to ptr to CATFileSystem. Set to 0 on release. 00072 void Release(CATFileSystem*& fileSys); 00073 }; 00074 00075 extern CATPlatform* gPlatform; 00076 00077 #endif // CATPlatform_H_