|
Blender
V2.59
|
00001 /* 00002 * $Id: BL_System.cpp 36523 2011-05-06 20:18:42Z blendix $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00021 * All rights reserved. 00022 * 00023 * The Original Code is: all of this file. 00024 * 00025 * Contributor(s): none yet. 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 * Interface to the commandline arguments 00029 */ 00030 00035 #include "CTR_Map.h" 00036 #include "STR_HashedString.h" 00037 #include "BL_System.h" 00038 00039 struct SingletonSystem { 00040 CTR_Map<STR_HashedString,int> int_params; 00041 CTR_Map<STR_HashedString,float> float_params; 00042 CTR_Map<STR_HashedString,STR_String> string_params; 00043 }; 00044 00045 static SingletonSystem *_system_instance = NULL; 00046 00047 SYS_SystemHandle SYS_GetSystem() 00048 { 00049 if(!_system_instance) 00050 _system_instance = new SingletonSystem(); 00051 00052 return (SYS_SystemHandle)_system_instance; 00053 } 00054 00055 void SYS_DeleteSystem(SYS_SystemHandle sys) 00056 { 00057 if(_system_instance) { 00058 delete _system_instance; 00059 _system_instance = NULL; 00060 } 00061 } 00062 00063 int SYS_GetCommandLineInt(SYS_SystemHandle sys, const char *paramname, int defaultvalue) 00064 { 00065 int *result = ((SingletonSystem *)sys)->int_params[paramname]; 00066 if(result) 00067 return *result; 00068 00069 return defaultvalue; 00070 } 00071 00072 float SYS_GetCommandLineFloat(SYS_SystemHandle sys, const char *paramname, float defaultvalue) 00073 { 00074 float *result = ((SingletonSystem *)sys)->float_params[paramname]; 00075 if(result) 00076 return *result; 00077 00078 return defaultvalue; 00079 } 00080 00081 const char *SYS_GetCommandLineString(SYS_SystemHandle sys, const char *paramname, const char *defaultvalue) 00082 { 00083 STR_String *result = ((SingletonSystem *)sys)->string_params[paramname]; 00084 if(result) 00085 return *result; 00086 00087 return defaultvalue; 00088 } 00089 00090 void SYS_WriteCommandLineInt(SYS_SystemHandle sys, const char *paramname, int value) 00091 { 00092 ((SingletonSystem *)sys)->int_params.insert(paramname, value); 00093 } 00094 00095 void SYS_WriteCommandLineFloat(SYS_SystemHandle sys, const char *paramname, float value) 00096 { 00097 ((SingletonSystem *)sys)->float_params.insert(paramname, value); 00098 } 00099 00100 void SYS_WriteCommandLineString(SYS_SystemHandle sys, const char *paramname, const char *value) 00101 { 00102 ((SingletonSystem *)sys)->string_params.insert(paramname, value); 00103 } 00104