[Orxonox-commit 1320] r6038 - in sandbox: . bin cmake data doc/api src src/external/tolua src/libraries src/libraries/core src/libraries/util src/orxonox
rgrieder at orxonox.net
rgrieder at orxonox.net
Thu Nov 5 21:22:23 CET 2009
Author: rgrieder
Date: 2009-11-05 21:22:22 +0100 (Thu, 05 Nov 2009)
New Revision: 6038
Added:
sandbox/src/libraries/core/CommandLineParser.cc
sandbox/src/libraries/core/CommandLineParser.h
sandbox/src/libraries/core/PathConfig.cc
sandbox/src/libraries/core/PathConfig.h
sandbox/src/libraries/util/Clock.cc
sandbox/src/libraries/util/Clock.h
Removed:
sandbox/src/libraries/core/Clock.cc
sandbox/src/libraries/core/Clock.h
sandbox/src/libraries/core/CommandLine.cc
sandbox/src/libraries/core/CommandLine.h
sandbox/src/libraries/core/Factory.cc
sandbox/src/libraries/core/Factory.h
sandbox/src/libraries/util/ScopedSingleton.h
Modified:
sandbox/
sandbox/bin/vld.ini.in
sandbox/cmake/CompilerConfigMSVC.cmake
sandbox/cmake/LibraryConfig.cmake
sandbox/cmake/PackageConfig.cmake
sandbox/cmake/ParseMacroArguments.cmake
sandbox/cmake/PrecompiledHeaderFiles.cmake
sandbox/cmake/SourceFileUtilities.cmake
sandbox/cmake/TargetUtilities.cmake
sandbox/data/CMakeLists.txt
sandbox/doc/api/doxy.config.in
sandbox/src/Orxonox.cc
sandbox/src/OrxonoxConfig.cmake
sandbox/src/external/tolua/CMakeLists.txt
sandbox/src/libraries/CMakeLists.txt
sandbox/src/libraries/core/CMakeLists.txt
sandbox/src/libraries/core/ClassFactory.h
sandbox/src/libraries/core/ConfigFileManager.cc
sandbox/src/libraries/core/Core.cc
sandbox/src/libraries/core/Core.h
sandbox/src/libraries/core/CoreIncludes.h
sandbox/src/libraries/core/CorePrereqs.h
sandbox/src/libraries/core/Functor.h
sandbox/src/libraries/core/Game.cc
sandbox/src/libraries/core/Game.h
sandbox/src/libraries/core/GameState.h
sandbox/src/libraries/core/Identifier.cc
sandbox/src/libraries/core/Identifier.h
sandbox/src/libraries/core/Iterator.h
sandbox/src/libraries/core/Language.cc
sandbox/src/libraries/core/LuaState.cc
sandbox/src/libraries/core/ObjectListIterator.h
sandbox/src/libraries/core/OrxonoxClass.cc
sandbox/src/libraries/core/OrxonoxClass.h
sandbox/src/libraries/util/CMakeLists.txt
sandbox/src/libraries/util/Scope.h
sandbox/src/libraries/util/UtilPrereqs.h
sandbox/src/orxonox/GSRoot.cc
sandbox/src/orxonox/Main.cc
sandbox/src/orxonox/OrxonoxPrereqs.h
Log:
Synchronised sandbox with current code trunk. There should be a few bug fixes.
Property changes on: sandbox
___________________________________________________________________
Modified: svn:mergeinfo
- /code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/resource2:3372-5694
code/branches/buildsystem:1874-2276,2278-2400
code/branches/buildsystem2:2506-2658
code/branches/buildsystem3:2662-2708
code/branches/ceguilua:1802-1808
code/branches/core3:1572-1739
code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
code/branches/gametypes:2826-3031
code/branches/gcc43:1580
code/branches/gui:1635-1723,2795-2894
code/branches/input:1629-1636
code/branches/lodfinal:2372-2411
code/branches/map:2801-3086,3089
code/branches/miniprojects:2754-2824
code/branches/netp2:2835-2988
code/branches/netp3:2988-3082
code/branches/netp6:3214-3302
code/branches/network:2356
code/branches/network64:2210-2355
code/branches/objecthierarchy:1911-2085,2100,2110-2169
code/branches/objecthierarchy2:2171-2479
code/branches/overlay:2117-2385
code/branches/particles:2829-3085
code/branches/pch:3113-3194
code/branches/physics:1912-2055,2107-2439
code/branches/physics_merge:2436-2457
code/branches/pickups:1926-2086,2127,2827-2915
code/branches/pickups2:2107-2497,2915-3071
code/branches/presentation:2369-2652,2654-2660
code/branches/questsystem:1894-2088
code/branches/questsystem2:2107-2259
code/branches/questsystem5:2776-2905
code/branches/resource:3327-3366
code/branches/script_trigger:1295-1953,1955
code/branches/sound:2829-3010
code/branches/weapon:1925-2094
code/branches/weapon2:2107-2488
code/branches/weapons:2897-3051
code/branches/weaponsystem:2742-2890
+ /code/branches/core5:5768-5928
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/resource2:3372-5694
/code/trunk:5794-6035
code/branches/buildsystem:1874-2276,2278-2400
code/branches/buildsystem2:2506-2658
code/branches/buildsystem3:2662-2708
code/branches/ceguilua:1802-1808
code/branches/core3:1572-1739
code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
code/branches/gametypes:2826-3031
code/branches/gcc43:1580
code/branches/gui:1635-1723,2795-2894
code/branches/input:1629-1636
code/branches/lodfinal:2372-2411
code/branches/map:2801-3086,3089
code/branches/miniprojects:2754-2824
code/branches/netp2:2835-2988
code/branches/netp3:2988-3082
code/branches/netp6:3214-3302
code/branches/network:2356
code/branches/network64:2210-2355
code/branches/objecthierarchy:1911-2085,2100,2110-2169
code/branches/objecthierarchy2:2171-2479
code/branches/overlay:2117-2385
code/branches/particles:2829-3085
code/branches/pch:3113-3194
code/branches/physics:1912-2055,2107-2439
code/branches/physics_merge:2436-2457
code/branches/pickups:1926-2086,2127,2827-2915
code/branches/pickups2:2107-2497,2915-3071
code/branches/presentation:2369-2652,2654-2660
code/branches/questsystem:1894-2088
code/branches/questsystem2:2107-2259
code/branches/questsystem5:2776-2905
code/branches/resource:3327-3366
code/branches/script_trigger:1295-1953,1955
code/branches/sound:2829-3010
code/branches/weapon:1925-2094
code/branches/weapon2:2107-2488
code/branches/weapons:2897-3051
code/branches/weaponsystem:2742-2890
Modified: sandbox/bin/vld.ini.in
===================================================================
--- sandbox/bin/vld.ini.in 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/bin/vld.ini.in 2009-11-05 20:22:22 UTC (rev 6038)
@@ -55,7 +55,7 @@
; Valid Values: Any list containing module names (i.e. names of EXEs or DLLs).
; Default: None.
;
-ForceIncludeModules =
+ForceIncludeModules = boost_date_time-vc80-mt-gd-1_39.dll, boost_filesystem-vc80-mt-gd-1_39.dll, boost_system-vc80-mt-gd-1_39.dll, boost_thread-vc80-mt-gd-1_39.dll, enet_d.dll, lua_d.dll, ogg_d.dll, vorbis_d.dll, vorbifile_d.dll
; Maximum number of data bytes to display for each leaked block. If zero, then
; the data dump is completely suppressed and only call stacks are shown.
@@ -65,7 +65,7 @@
; Value Values: 0 - 4294967295
; Default: 4294967295
;
-MaxDataDump =
+MaxDataDump = 0
; Maximum number of call stack frames to trace back during leak detection.
; Limiting this to a low number can reduce the CPU utilization overhead imposed
Modified: sandbox/cmake/CompilerConfigMSVC.cmake
===================================================================
--- sandbox/cmake/CompilerConfigMSVC.cmake 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/cmake/CompilerConfigMSVC.cmake 2009-11-05 20:22:22 UTC (rev 6038)
@@ -69,10 +69,10 @@
ADD_COMPILER_FLAGS("-D_CRT_SECURE_NO_WARNINGS" CACHE)
# Overwrite CMake default flags here.
-SET_COMPILER_FLAGS("-MDd -Od -Zi -D_DEBUG -Gm -RTC1" Debug CACHE)
-SET_COMPILER_FLAGS("-MD -O2 -DNDEBUG -MP2" Release CACHE)
-SET_COMPILER_FLAGS("-MD -O2 -Zi -DNDEBUG -MP2" RelWithDebInfo CACHE)
-SET_COMPILER_FLAGS("-MD -O1 -DNDEBUG -MP2" MinSizeRel CACHE)
+SET_COMPILER_FLAGS("-MDd -Od -Zi -D_DEBUG -MP2 -RTC1" Debug CACHE)
+SET_COMPILER_FLAGS("-MD -O2 -DNDEBUG -MP2" Release CACHE)
+SET_COMPILER_FLAGS("-MD -O2 -Zi -DNDEBUG -MP2" RelWithDebInfo CACHE)
+SET_COMPILER_FLAGS("-MD -O1 -DNDEBUG -MP2" MinSizeRel CACHE)
# Use Link time code generation for Release config if ORXONOX_RELEASE is defined
IF(ORXONOX_RELEASE)
Modified: sandbox/cmake/LibraryConfig.cmake
===================================================================
--- sandbox/cmake/LibraryConfig.cmake 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/cmake/LibraryConfig.cmake 2009-11-05 20:22:22 UTC (rev 6038)
@@ -88,7 +88,7 @@
##### Boost #####
# Expand the next statement if newer boost versions than 1.36.1 are released
-SET(Boost_ADDITIONAL_VERSIONS 1.37 1.37.0 1.38 1.38.0 1.39 1.39.0)
+SET(Boost_ADDITIONAL_VERSIONS 1.37 1.37.0 1.38 1.38.0 1.39 1.39.0 1.40 1.40.0)
FIND_PACKAGE(Boost 1.35 REQUIRED thread filesystem system date_time)
# No auto linking, so this option is useless anyway
MARK_AS_ADVANCED(Boost_LIB_DIAGNOSTIC_DEFINITIONS)
Modified: sandbox/cmake/PackageConfig.cmake
===================================================================
--- sandbox/cmake/PackageConfig.cmake 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/cmake/PackageConfig.cmake 2009-11-05 20:22:22 UTC (rev 6038)
@@ -25,9 +25,13 @@
#
# Check package version info
-# MAJOR: Interface breaking change somewhere (library version changed, etc.)
-# MINOR: Bug fix or small conformant changes
-SET(DEPENDENCY_VERSION_REQUIRED 3)
+# MAJOR: Breaking change
+# MINOR: No breaking changes by the dependency package
+# For example any code running on 3.0 should still run on 3.1
+# But you can specify that the code only runs on 3.1 and higher
+# or 4.0 and higher (so both 3.1 and 4.0 will work).
+SET(ALLOWED_MINIMUM_VERSIONS 3.1 4.0)
+
IF(NOT EXISTS ${DEPENDENCY_PACKAGE_DIR}/version.txt)
SET(DEPENDENCY_VERSION 1.0)
ELSE()
@@ -43,11 +47,22 @@
ENDIF()
INCLUDE(CompareVersionStrings)
-COMPARE_VERSION_STRINGS(${DEPENDENCY_VERSION} ${DEPENDENCY_VERSION_REQUIRED} _result TRUE)
-IF(NOT _result EQUAL 0)
+SET(_version_match FALSE)
+FOREACH(_version ${ALLOWED_MINIMUM_VERSIONS})
+ # Get major version
+ STRING(REGEX REPLACE "^([0-9]+)\\..*$" "\\1" _major_version "${_version}")
+ COMPARE_VERSION_STRINGS(${DEPENDENCY_VERSION} ${_major_version} _result TRUE)
+ IF(_result EQUAL 0)
+ COMPARE_VERSION_STRINGS(${DEPENDENCY_VERSION} ${_version} _result FALSE)
+ IF(NOT _result LESS 0)
+ SET(_version_match TRUE)
+ ENDIF()
+ ENDIF()
+ENDFOREACH(_version)
+IF(NOT _version_match)
MESSAGE(FATAL_ERROR "Your dependency package version is ${DEPENDENCY_VERSION}\n"
- "Required version: ${DEPENDENCY_VERSION_REQUIRED}\n"
- "You can get a new version from www.orxonox.net")
+ "Possible required versions: ${ALLOWED_MINIMUM_VERSIONS}\n"
+ "You can get a new version from www.orxonox.net")
ENDIF()
IF(NOT _INTERNAL_PACKAGE_MESSAGE)
Modified: sandbox/cmake/ParseMacroArguments.cmake
===================================================================
--- sandbox/cmake/ParseMacroArguments.cmake 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/cmake/ParseMacroArguments.cmake 2009-11-05 20:22:22 UTC (rev 6038)
@@ -39,6 +39,11 @@
# Using LIST(FIND ...) speeds up the process
SET(_keywords ${_switches} ${_list_names})
+ # Reset all arguments
+ FOREACH(_arg ${_switches} ${_list_names})
+ SET(_arg_${_arg})
+ ENDFOREACH(_arg)
+
# Parse all the arguments and set the corresponding variable
# If the option is just a switch, set the variable to its name for later use
FOREACH(_arg ${ARGN})
Modified: sandbox/cmake/PrecompiledHeaderFiles.cmake
===================================================================
--- sandbox/cmake/PrecompiledHeaderFiles.cmake 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/cmake/PrecompiledHeaderFiles.cmake 2009-11-05 20:22:22 UTC (rev 6038)
@@ -109,7 +109,7 @@
# This is just the best possible opportunity to address this dependency issue
GET_GCC_COMPILER_FLAGS(${_target_name} _pch_gcc_flags)
# Make sure we recompile the pch file even if only the flags change
- IF(NOT "${_pch_gcc_flags}" STREQUAL "${_INTERNAL_${_target_name}_PCH_GCC_FLAGS}")
+ IF(NOT "${_pch_gcc_flags}" STREQUAL "${_INTERNAL_${_target_name}_PCH_GCC_FLAGS}" OR NOT EXISTS "${_pch_dep_helper_file}")
SET(_INTERNAL_${_target_name}_PCH_GCC_FLAGS "${_pch_gcc_flags}" CACHE INTERNAL "")
FILE(WRITE ${_pch_dep_helper_file} "/* ${_pch_gcc_flags} */")
ENDIF()
Modified: sandbox/cmake/SourceFileUtilities.cmake
===================================================================
--- sandbox/cmake/SourceFileUtilities.cmake 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/cmake/SourceFileUtilities.cmake 2009-11-05 20:22:22 UTC (rev 6038)
@@ -23,18 +23,68 @@
# Several functions that help organising the source tree.
# [ADD/SET]_SOURCE_FILES - Writes source files to the cache by force and
# adds the current directory.
- # GET_ALL_HEADER_FILES - Finds all header files recursively.
+ # Also compiles multiple source files into a single
+ # one by including them
+ # Use COMPILATION_[BEGIN|END] in
+ # [ADD|SET]_SOURCE_FILES and specify the name of
+ # the new source file after COMPILATION_BEGIN
+ # GET_ALL_HEADER_FILES - Finds all header files recursively.
# GENERATE_SOURCE_GROUPS - Set Visual Studio source groups.
#
-# Adds source files with the full path to a list
-FUNCTION(ADD_SOURCE_FILES _varname)
- # Prefix the full path
+FUNCTION(PREPARE_SOURCE_FILES)
SET(_fullpath_sources)
FOREACH(_file ${ARGN})
- GET_SOURCE_FILE_PROPERTY(_filepath ${_file} LOCATION)
- LIST(APPEND _fullpath_sources ${_filepath})
+ IF(_file STREQUAL "COMPILATION_BEGIN")
+ SET(_compile TRUE)
+ # Next file is the name of the compilation
+ SET(_get_name TRUE)
+ ELSEIF(_get_name)
+ SET(_get_name FALSE)
+ SET(_compilation_name ${_file})
+ ELSEIF(_file STREQUAL "COMPILATION_END")
+ IF(NOT _compilation_name)
+ MESSAGE(FATAL_ERROR "No name provided for source file compilation")
+ ENDIF()
+ IF(NOT DISABLE_COMPILATIONS)
+ SET(_compilation_file ${CMAKE_CURRENT_BINARY_DIR}/${_compilation_name})
+ SET(_include_string)
+ FOREACH(_file2 ${_compilation})
+ SET(_include_string "${_include_string}#include \"${_file2}\"\n")
+ ENDFOREACH(_file2)
+ IF(EXISTS )
+ FILE(READ ${_compilation_file} _include_string_file)
+ ENDIF()
+ IF(NOT _include_string STREQUAL "${_include_string_file}")
+ FILE(WRITE ${_compilation_file} "${_include_string}")
+ ENDIF()
+ LIST(APPEND _fullpath_sources ${_compilation_file})
+ # MSVC hack that excludes the compilations from the intellisense database
+ # (There is a bug with the "-" instead of "/". Only works for "Zm#" argument)
+ IF(MSVC)
+ SET_SOURCE_FILES_PROPERTIES(${_compilation_file} PROPERTIES COMPILE_FLAGS "-Zm1000")
+ ENDIF()
+ ENDIF()
+ SET(_compilation_name)
+ SET(_compilation)
+ SET(_compile FALSE)
+ ELSE()
+ # Prefix the full path
+ GET_SOURCE_FILE_PROPERTY(_filepath ${_file} LOCATION)
+ LIST(APPEND _fullpath_sources ${_filepath})
+ IF(_compile AND NOT DISABLE_COMPILATIONS)
+ LIST(APPEND _compilation ${_filepath})
+ LIST(APPEND _fullpath_sources "H")
+ ENDIF()
+ ENDIF()
ENDFOREACH(_file)
+ SET(_fullpath_sources ${_fullpath_sources} PARENT_SCOPE)
+ENDFUNCTION(PREPARE_SOURCE_FILES)
+
+
+# Adds source files with the full path to a list
+FUNCTION(ADD_SOURCE_FILES _varname)
+ PREPARE_SOURCE_FILES(${ARGN})
# Write into the cache to avoid variable scoping in subdirs
SET(${_varname} ${${_varname}} ${_fullpath_sources} CACHE INTERNAL "Do not edit")
ENDFUNCTION(ADD_SOURCE_FILES)
@@ -42,12 +92,7 @@
# Sets source files with the full path
FUNCTION(SET_SOURCE_FILES _varname)
- # Prefix the full path
- SET(_fullpath_sources)
- FOREACH(_file ${ARGN})
- GET_SOURCE_FILE_PROPERTY(_filepath ${_file} LOCATION)
- LIST(APPEND _fullpath_sources ${_filepath})
- ENDFOREACH(_file)
+ PREPARE_SOURCE_FILES(${ARGN})
# Write into the cache to avoid variable scoping in subdirs
SET(${_varname} ${_fullpath_sources} CACHE INTERNAL "Do not edit")
ENDFUNCTION(SET_SOURCE_FILES)
@@ -65,9 +110,14 @@
FOREACH(_file ${ARGN})
GET_SOURCE_FILE_PROPERTY(_full_filepath ${_file} LOCATION)
FILE(RELATIVE_PATH _relative_path ${CMAKE_CURRENT_SOURCE_DIR} ${_full_filepath})
- GET_FILENAME_COMPONENT(_relative_path ${_relative_path} PATH)
- STRING(REPLACE "/" "\\\\" _group_path "${_relative_path}")
- SOURCE_GROUP("Source\\${_group_path}" FILES ${_file})
+ IF(NOT _relative_path MATCHES "^\\.\\.")
+ GET_FILENAME_COMPONENT(_relative_path ${_relative_path} PATH)
+ STRING(REPLACE "/" "\\\\" _group_path "${_relative_path}")
+ SOURCE_GROUP("Source\\${_group_path}" FILES ${_file})
+ ELSE()
+ # Has to be a compilation
+ SOURCE_GROUP("Compilations" FILES ${_file})
+ ENDIF()
ENDFOREACH(_file)
ENDFUNCTION(GENERATE_SOURCE_GROUPS)
Modified: sandbox/cmake/TargetUtilities.cmake
===================================================================
--- sandbox/cmake/TargetUtilities.cmake 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/cmake/TargetUtilities.cmake 2009-11-05 20:22:22 UTC (rev 6038)
@@ -66,16 +66,16 @@
INCLUDE(PrecompiledHeaderFiles)
ENDIF()
-FUNCTION(ORXONOX_ADD_LIBRARY _target_name)
+MACRO(ORXONOX_ADD_LIBRARY _target_name)
TU_ADD_TARGET(${_target_name} LIBRARY "STATIC;SHARED" ${ARGN})
-ENDFUNCTION(ORXONOX_ADD_LIBRARY)
+ENDMACRO(ORXONOX_ADD_LIBRARY)
-FUNCTION(ORXONOX_ADD_EXECUTABLE _target_name)
+MACRO(ORXONOX_ADD_EXECUTABLE _target_name)
TU_ADD_TARGET(${_target_name} EXECUTABLE "WIN32" ${ARGN})
-ENDFUNCTION(ORXONOX_ADD_EXECUTABLE)
+ENDMACRO(ORXONOX_ADD_EXECUTABLE)
-FUNCTION(TU_ADD_TARGET _target_name _target_type _additional_switches)
+MACRO(TU_ADD_TARGET _target_name _target_type _additional_switches)
CAPITALISE_NAME(${_target_name} _target_name_capitalised)
# Specify all possible options (either switch or with add. arguments)
@@ -87,13 +87,24 @@
PARSE_MACRO_ARGUMENTS("${_switches}" "${_list_names}" ${ARGN})
- # GET_HEADER_FILES
+ # Workaround: Source file properties get lost when leaving a subdirectory
+ # Therefore an "H" after a file means we have to set it as HEADER_FILE_ONLY
+ FOREACH(_file ${_arg_SOURCE_FILES})
+ IF(_file STREQUAL "H")
+ SET_SOURCE_FILES_PROPERTIES(${_last_file} PROPERTIES HEADER_FILE_ONLY TRUE)
+ ELSE()
+ SET(_last_file ${_file})
+ LIST(APPEND _${_target_name}_source_files ${_file})
+ ENDIF()
+ ENDFOREACH(_file)
+
+ # Assemble all header files of the library
IF(_arg_FIND_HEADER_FILES)
- GET_ALL_HEADER_FILES(_${target_name}_header_files)
+ GET_ALL_HEADER_FILES(_${_target_name}_header_files)
ENDIF()
# Remove potential duplicates
- SET(_${_target_name}_files ${_${target_name}_header_files} ${_arg_SOURCE_FILES})
+ SET(_${_target_name}_files ${_${_target_name}_header_files} ${_${_target_name}_source_files})
LIST(REMOVE_DUPLICATES _${_target_name}_files)
# Generate the source groups
@@ -140,6 +151,12 @@
SET(_arg_STATIC STATIC)
ENDIF()
+ # No warnings needed from third party libraries
+ IF(_arg_ORXONOX_EXTERNAL)
+ REMOVE_COMPILER_FLAGS("-W3 -W4" MSVC)
+ ADD_COMPILER_FLAGS("-w")
+ ENDIF()
+
# Set default linking if required
IF(NOT _arg_SHARED AND NOT _arg_STATIC)
IF("${ORXONOX_DEFAULT_LINK}" STREQUAL "STATIC")
@@ -156,6 +173,15 @@
SET(_arg_STATIC)
ENDIF()
+ # Don't compile header files
+ FOREACH(_file ${_${_target_name}_files})
+ IF(NOT _file MATCHES "\\.(c|cc|cpp)")
+ SET_SOURCE_FILES_PROPERTIES(${_file} PROPERTIES HEADER_FILE_ONLY TRUE)
+ ENDIF()
+ ENDFOREACH(_file)
+
+
+
# Add the library/executable
IF("${_target_type}" STREQUAL "LIBRARY")
ADD_LIBRARY(${_target_name} ${_arg_STATIC} ${_arg_SHARED}
@@ -165,6 +191,22 @@
${_${_target_name}_files})
ENDIF()
+
+
+ # Change library prefix to "lib"
+ IF(MSVC AND ${_target_type} STREQUAL "LIBRARY")
+ SET_TARGET_PROPERTIES(${_target_name} PROPERTIES
+ PREFIX "lib"
+ )
+ ENDIF()
+
+ # MSVC hack to exclude external library sources from the intellisense database
+ # (IntelliSense stops working when adding "-Zm1000" as compile flag. "/Zm1000"
+ # would not work because of the slash)
+ IF(_arg_ORXONOX_EXTERNAL AND MSVC)
+ SET_TARGET_PROPERTIES(${_target_name} PROPERTIES COMPILE_FLAGS "-Zm1000")
+ ENDIF()
+
# MODULE B
IF (_arg_MODULE)
SET_TARGET_PROPERTIES(${_target_name} PROPERTIES
@@ -215,7 +257,7 @@
ENDIF()
ENDIF()
-ENDFUNCTION(TU_ADD_TARGET)
+ENDMACRO(TU_ADD_TARGET)
# Creates a helper file with name <name_of_the_library>${ORXONOX_MODULE_EXTENSION}
Modified: sandbox/data/CMakeLists.txt
===================================================================
--- sandbox/data/CMakeLists.txt 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/data/CMakeLists.txt 2009-11-05 20:22:22 UTC (rev 6038)
@@ -24,7 +24,7 @@
# Default search paths are: ../../data and ../data_extern
#
-# For dev runs we've got two data directory. The one from the other repository root folder
+# For dev runs we've got two data directories. The one from the other repository root folder
# is called EXTERNAL_DATA
SET(DATA_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
SET(DATA_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
Modified: sandbox/doc/api/doxy.config.in
===================================================================
--- sandbox/doc/api/doxy.config.in 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/doc/api/doxy.config.in 2009-11-05 20:22:22 UTC (rev 6038)
@@ -139,7 +139,7 @@
# comments will behave just like the Qt-style comments (thus requiring an
# explicit @brief command for a brief description.
-JAVADOC_AUTOBRIEF = NO
+JAVADOC_AUTOBRIEF = YES
# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen
# treat a multi-line C++ special comment block (i.e. a block of //! or ///
Modified: sandbox/src/Orxonox.cc
===================================================================
--- sandbox/src/Orxonox.cc 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/Orxonox.cc 2009-11-05 20:22:22 UTC (rev 6038)
@@ -62,9 +62,9 @@
std::string strCmdLine;
for (int i = 1; i < argc; ++i)
strCmdLine += argv[i] + std::string(" ");
+#endif
return orxonox::main(strCmdLine);
-#endif
}
catch (...)
{
Modified: sandbox/src/OrxonoxConfig.cmake
===================================================================
--- sandbox/src/OrxonoxConfig.cmake 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/OrxonoxConfig.cmake 2009-11-05 20:22:22 UTC (rev 6038)
@@ -38,6 +38,9 @@
OPTION(PCH_ENABLE "Global PCH switch" TRUE)
ENDIF()
+# Global switch to disable multiple file compilations
+OPTION(DISABLE_COMPILATIONS "Global multi-file compilation switch" FALSE)
+
# Use WinMain() or main()?
IF(WIN32)
OPTION(ORXONOX_USE_WINMAIN "Use WinMain (doesn't show console) or main" FALSE)
Modified: sandbox/src/external/tolua/CMakeLists.txt
===================================================================
--- sandbox/src/external/tolua/CMakeLists.txt 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/external/tolua/CMakeLists.txt 2009-11-05 20:22:22 UTC (rev 6038)
@@ -19,22 +19,18 @@
################### Tolua++ library ###################
-SET(TOLUA++_FILES
+SET_SOURCE_FILES(TOLUA++_FILES
tolua_event.h
tolua++.h
-
+COMPILATION_BEGIN ToluaCompilation.c
tolua_event.c
tolua_is.c
tolua_map.c
tolua_push.c
tolua_to.c
+COMPILATION_END
)
-GENERATE_SOURCE_GROUPS(${TOLUA++_FILES})
-# No warnings needed from third party libraries
-REMOVE_COMPILER_FLAGS("-W3 -W4" MSVC)
-ADD_COMPILER_FLAGS("-w")
-
ORXONOX_ADD_LIBRARY(tolua++_orxonox
ORXONOX_EXTERNAL
DEFINE_SYMBOL
Modified: sandbox/src/libraries/CMakeLists.txt
===================================================================
--- sandbox/src/libraries/CMakeLists.txt 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/CMakeLists.txt 2009-11-05 20:22:22 UTC (rev 6038)
@@ -24,5 +24,5 @@
################ Sub Directories ################
+ADD_SUBDIRECTORY(util)
ADD_SUBDIRECTORY(core)
-ADD_SUBDIRECTORY(util)
Modified: sandbox/src/libraries/core/CMakeLists.txt
===================================================================
--- sandbox/src/libraries/core/CMakeLists.txt 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/CMakeLists.txt 2009-11-05 20:22:22 UTC (rev 6038)
@@ -18,8 +18,6 @@
#
SET_SOURCE_FILES(CORE_SRC_FILES
- Clock.cc
- ConfigFileManager.cc
ConfigValueContainer.cc
Core.cc
DynLib.cc
@@ -32,17 +30,21 @@
OrxonoxClass.cc
# command
- CommandLine.cc
+ CommandLineParser.cc
Executor.cc
# hierarchy
- Factory.cc
Identifier.cc
MetaObjectList.cc
# level
BaseObject.cc
+COMPILATION_BEGIN FilesystemCompilation.cc
+ ConfigFileManager.cc
+ PathConfig.cc
+COMPILATION_END
+
# multithreading
Thread.cc
ThreadPool.cc
Modified: sandbox/src/libraries/core/ClassFactory.h
===================================================================
--- sandbox/src/libraries/core/ClassFactory.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/ClassFactory.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -41,65 +41,49 @@
#include <string>
#include "util/Debug.h"
-#include "Factory.h"
#include "Identifier.h"
namespace orxonox
{
+ // ###########################
+ // ### Factory ###
+ // ###########################
+ //! Base-class of ClassFactory.
+ class _CoreExport Factory
+ {
+ public:
+ virtual ~Factory() {};
+ virtual BaseObject* fabricate(BaseObject* creator) = 0;
+ };
+
// ###############################
// ### ClassFactory ###
// ###############################
//! The ClassFactory is able to create new objects of a specific class.
template <class T>
- class ClassFactory : public BaseFactory
+ class ClassFactory : public Factory
{
public:
- static bool create(const std::string& name);
- BaseObject* fabricate(BaseObject* creator);
+ /**
+ @brief Constructor: Adds the ClassFactory to the Identifier of the same type.
+ @param name The name of the class
+ @param bLoadable True if the class can be loaded through XML
+ */
+ ClassFactory(const std::string& name, bool bLoadable = true)
+ {
+ COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl;
+ ClassIdentifier<T>::getIdentifier(name)->addFactory(this);
+ }
- private:
- ClassFactory() {} // Don't create
- ClassFactory(const ClassFactory& factory) {} // Don't copy
- virtual ~ClassFactory() {} // Don't delete
-
- static T* createNewObject(BaseObject* creator);
+ /**
+ @brief Creates and returns a new object of class T.
+ @return The new object
+ */
+ inline BaseObject* fabricate(BaseObject* creator)
+ {
+ return static_cast<BaseObject*>(new T(creator));
+ }
};
-
- /**
- @brief Adds the ClassFactory to the Identifier of the same type and the Identifier to the Factory.
- @param name The name of the class
- @param bLoadable True if the class can be loaded through XML
- @return Always true (this is needed because the compiler only allows assignments before main())
- */
- template <class T>
- bool ClassFactory<T>::create(const std::string& name)
- {
- COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl;
- ClassIdentifier<T>::getIdentifier(name)->addFactory(new ClassFactory<T>);
- Factory::add(name, ClassIdentifier<T>::getIdentifier());
-
- return true;
- }
-
- /**
- @brief Creates and returns a new object of class T.
- @return The new object
- */
- template <class T>
- inline BaseObject* ClassFactory<T>::fabricate(BaseObject* creator)
- {
- return ClassFactory<T>::createNewObject(creator);
- }
-
- /**
- @brief Creates and returns a new object of class T; this is a wrapper for the new operator.
- @return The new object
- */
- template <class T>
- inline T* ClassFactory<T>::createNewObject(BaseObject* creator)
- {
- return new T(creator);
- }
}
#endif /* _ClassFactory_H__ */
Deleted: sandbox/src/libraries/core/Clock.cc
===================================================================
--- sandbox/src/libraries/core/Clock.cc 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/Clock.cc 2009-11-05 20:22:22 UTC (rev 6038)
@@ -1,78 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief
-*/
-
-#include "Clock.h"
-#include <OgreTimer.h>
-
-namespace orxonox
-{
- Clock::Clock()
- : timer_(new Ogre::Timer())
- , storedTime_(0)
- , tickTime_(0)
- , tickDt_(0)
- , tickDtFloat_(0.0f)
- , lastTimersTime_(0)
- {
- }
-
- Clock::~Clock()
- {
- delete timer_;
- }
-
- void Clock::capture()
- {
- unsigned long timersTime = timer_->getMicroseconds();
- tickTime_ = storedTime_ + timersTime;
- tickDt_ = timersTime - lastTimersTime_;
- tickDtFloat_ = static_cast<float>(tickDt_) / 1000000.0f;
-
- if (timersTime > 0xFFFFFFFF/4)
- {
- // Ogre timer will overflow at 2^32 microseconds if unsigned long is 32 bit
- storedTime_ += timersTime;
- lastTimersTime_ = 0;
- timer_->reset();
- }
- else
- {
- lastTimersTime_ = timersTime;
- }
- }
-
- unsigned long long Clock::getRealMicroseconds() const
- {
- return this->timer_->getMicroseconds() + this->storedTime_;
- }
-}
Deleted: sandbox/src/libraries/core/Clock.h
===================================================================
--- sandbox/src/libraries/core/Clock.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/Clock.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -1,68 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-#ifndef _Clock_H__
-#define _Clock_H__
-
-#include "CorePrereqs.h"
-
-namespace Ogre { class Timer; }
-
-namespace orxonox
-{
- class _CoreExport Clock
- {
- public:
- Clock();
- ~Clock();
-
- void capture();
-
- unsigned long long getMicroseconds() const { return tickTime_; }
- unsigned long long getMilliseconds() const { return tickTime_ / 1000; }
- unsigned long getSeconds() const { return static_cast<long> (tickTime_ / 1000000); }
- float getSecondsPrecise() const { return static_cast<float>(tickTime_ / 1000000.0f); }
-
- float getDeltaTime() const { return tickDtFloat_; }
- long getDeltaTimeMicroseconds() const { return tickDt_; }
-
- unsigned long long getRealMicroseconds() const;
-
- private:
- Clock(const Clock& instance);
-
- Ogre::Timer* timer_;
- unsigned long long storedTime_;
- unsigned long long tickTime_;
- long tickDt_;
- float tickDtFloat_;
- unsigned long lastTimersTime_;
- };
-}
-
-#endif /* _Clock_H__ */
Deleted: sandbox/src/libraries/core/CommandLine.cc
===================================================================
--- sandbox/src/libraries/core/CommandLine.cc 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/CommandLine.cc 2009-11-05 20:22:22 UTC (rev 6038)
@@ -1,378 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-#include "CommandLine.h"
-
-#include <algorithm>
-#include <sstream>
-#include <boost/filesystem.hpp>
-
-#include "util/Convert.h"
-#include "util/Debug.h"
-#include "util/Exception.h"
-#include "util/StringUtils.h"
-#include "util/SubString.h"
-#include "Core.h"
-
-namespace orxonox
-{
- SetCommandLineOnlyArgument(optionsFile, "start.ini").shortcut("o");
-
- /**
- @brief
- Parses a value string for a command line argument.
- It simply uses convertValue(Output, Input) to do that.
- Bools are treated specially. That is necessary
- so that you can have simple command line switches.
- */
- void CommandLineArgument::parse(const std::string& value, bool bParsingFile)
- {
- if (bParsingFile && this->bCommandLineOnly_)
- ThrowException(Argument, "Command line argument '" + getName() + "' is not allowed in files.");
- if (value_.getType() == MT_Type::Bool)
- {
- // simulate command line switch
- bool temp;
- if (convertValue(&temp, value))
- {
- this->bHasDefaultValue_ = false;
- this->value_ = temp;
- }
- else if (value == "")
- {
- this->bHasDefaultValue_ = false;
- this->value_ = true;
- }
- else
- ThrowException(Argument, "Could not read command line argument '" + getName() + "'.");
- }
- else
- {
- if (!value_.setValue(value))
- {
- value_.setValue(defaultValue_);
- ThrowException(Argument, "Could not read command line argument '" + getName() + "'.");
- }
- else
- this->bHasDefaultValue_ = false;
- }
- }
-
-
- /**
- @brief
- Destructor destroys all CommandLineArguments with it.
- */
- CommandLine::~CommandLine()
- {
- CommandLine::destroyAllArguments();
- }
-
- /**
- @brief
- Returns a unique instance (Meyers Singleton).
- */
- CommandLine& CommandLine::_getInstance()
- {
- static CommandLine instance;
- return instance;
- }
-
- /**
- @brief
- Destroys all command line arguments. This should be called at the end
- of main. Do not use before that.
- */
- void CommandLine::destroyAllArguments()
- {
- for (std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.begin();
- it != _getInstance().cmdLineArgs_.end(); ++it)
- delete it->second;
- _getInstance().cmdLineArgs_.clear();
- }
-
- /**
- @brief
- Reads the command line parses the values of each argument.
- It is then stored in the corresponding CommandLineArgument.
- @note
- The reason that you have to provide the string to be parsed as
- space separted list is because of argc and argv. If you only have
- a whole string, simply use getAllStrings() of SubString.
- @param arguments
- Vector of space separated strings.
- */
- void CommandLine::_parse(const std::vector<std::string>& arguments, bool bParsingFile)
- {
- try
- {
- // why this? See bFirstTimeParse_ declaration.
- if (bFirstTimeParse_)
- {
- // first shove all the shortcuts in a map
- for (std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.begin();
- it != cmdLineArgs_.end(); ++it)
- {
- OrxAssert(cmdLineArgsShortcut_.find(it->second->getShortcut()) == cmdLineArgsShortcut_.end(),
- "Cannot have two command line shortcut with the same name.");
- if (it->second->getShortcut() != "")
- cmdLineArgsShortcut_[it->second->getShortcut()] = it->second;
- }
- bFirstTimeParse_ = false;
- }
-
- std::string name;
- std::string shortcut;
- std::string value;
- for (unsigned int i = 0; i < arguments.size(); ++i)
- {
- if (arguments[i].size() != 0)
- {
- // sure not ""
- if (arguments[i][0] == '-')
- {
- // start with "-"
- if (arguments[i].size() == 1)
- {
- // argument[i] is "-", probably a minus sign
- value += "- ";
- }
- else if (arguments[i][1] <= 57 && arguments[i][1] >= 48)
- {
- // negative number as a value
- value += arguments[i] + " ";
- }
- else
- {
- // can be shortcut or full name argument
-
- // save old data first
- value = removeTrailingWhitespaces(value);
- if (name != "")
- {
- checkFullArgument(name, value, bParsingFile);
- name = "";
- assert(shortcut == "");
- }
- else if (shortcut != "")
- {
- checkShortcut(shortcut, value, bParsingFile);
- shortcut = "";
- assert(name == "");
- }
-
- if (arguments[i][1] == '-')
- {
- // full name argument with "--name"
- name = arguments[i].substr(2);
- }
- else
- {
- // shortcut with "-s"
- shortcut = arguments[i].substr(1);
- }
-
- // reset value string
- value = "";
- }
- }
- else
- {
- // value string
-
- if (name == "" && shortcut == "")
- {
- ThrowException(Argument, "Expected \"-\" or \"-\" in command line arguments.\n");
- }
-
- // Concatenate strings as long as there's no new argument by "-" or "--"
- value += arguments[i] + ' ';
- }
- }
- }
-
- // parse last argument
- value = removeTrailingWhitespaces(value);
- if (name != "")
- {
- checkFullArgument(name, value, bParsingFile);
- assert(shortcut == "");
- }
- else if (shortcut != "")
- {
- checkShortcut(shortcut, value, bParsingFile);
- assert(name == "");
- }
- }
- catch (const ArgumentException& ex)
- {
- COUT(0) << "Could not parse command line (including additional files): " << ex.what() << std::endl;
- COUT(0) << CommandLine::getUsageInformation() << std::endl;
- throw GeneralException("");
- }
- }
-
- /**
- @brief
- Parses an argument based on its full name.
- @param name
- Full name of the argument
- @param value
- String containing the value
- */
- void CommandLine::checkFullArgument(const std::string& name, const std::string& value, bool bParsingFile)
- {
- std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.find(name);
- if (it == cmdLineArgs_.end())
- ThrowException(Argument, "Command line argument '" + name + "' does not exist.");
-
- it->second->parse(value, bParsingFile);
- }
-
- /**
- @brief
- Parses an argument based on its shortcut.
- @param shortcut
- Shotcut to the argument
- @param value
- String containing the value
- */
- void CommandLine::checkShortcut(const std::string& shortcut, const std::string& value, bool bParsingFile)
- {
- std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgsShortcut_.find(shortcut);
- if (it == cmdLineArgsShortcut_.end())
- ThrowException(Argument, "Command line shortcut '" + shortcut + "' does not exist.");
-
- it->second->parse(value, bParsingFile);
- }
-
- std::string CommandLine::getUsageInformation()
- {
- CommandLine& inst = _getInstance();
- std::ostringstream infoStr;
-
- // determine maximum name size
- size_t maxNameSize = 0;
- for (std::map<std::string, CommandLineArgument*>::const_iterator it = inst.cmdLineArgs_.begin();
- it != inst.cmdLineArgs_.end(); ++it)
- {
- maxNameSize = std::max(it->second->getName().size(), maxNameSize);
- }
-
- infoStr << "Usage: orxonox [options]" << std::endl;
- infoStr << "Available options:" << std::endl;
-
- for (std::map<std::string, CommandLineArgument*>::const_iterator it = inst.cmdLineArgs_.begin();
- it != inst.cmdLineArgs_.end(); ++it)
- {
- if (it->second->getShortcut() != "")
- infoStr << " [-" << it->second->getShortcut() << "] ";
- else
- infoStr << " ";
- infoStr << "--" << it->second->getName() << " ";
- if (it->second->getValue().getType() != MT_Type::Bool)
- infoStr << "ARG ";
- else
- infoStr << " ";
- // fill with the necessary amount of blanks
- infoStr << std::string(maxNameSize - it->second->getName().size(), ' ');
- infoStr << ": " << it->second->getInformation();
- infoStr << std::endl;
- }
- return infoStr.str();
- }
-
- /**
- @brief
- Retrieves a CommandLineArgument.
- The method throws an exception if 'name' was not found or the value could not be converted.
- @note
- You shold of course not call this method before the command line has been parsed.
- */
- const CommandLineArgument* CommandLine::getArgument(const std::string& name)
- {
- std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.find(name);
- if (it == _getInstance().cmdLineArgs_.end())
- {
- ThrowException(Argument, "Could find command line argument '" + name + "'.");
- }
- else
- {
- return it->second;
- }
- }
-
- /**
- @brief
- Parses only the command line for CommandLineArguments.
- */
- void CommandLine::_parseCommandLine(const std::string& cmdLine)
- {
- std::vector<std::string> args;
- SubString tokens(cmdLine, " ", " ", false, '\\', true, '"', true, '(', ')', false);
- for (unsigned i = 0; i < tokens.size(); ++i)
- args.push_back(tokens[i]);
- this->_parse(args, false);
- }
-
- /**
- @brief
- Parses start.ini (or the file specified with --optionsFile) for CommandLineArguments.
- */
- void CommandLine::_parseFile()
- {
- std::string filename = CommandLine::getValue("optionsFile").getString();
- boost::filesystem::path filepath(Core::getConfigPath() / filename);
-
- // look for additional arguments in given file or start.ini as default
- // They will not overwrite the arguments given directly
- std::ifstream file;
- file.open(filepath.string().c_str());
- std::vector<std::string> args;
- if (file)
- {
- while (!file.eof())
- {
- std::string line;
- std::getline(file, line);
- line = removeTrailingWhitespaces(line);
- //if (!(line[0] == '#' || line[0] == '%'))
- //{
- SubString tokens(line, " ", " ", false, '\\', true, '"', true, '(', ')', false, '#');
- for (unsigned i = 0; i < tokens.size(); ++i)
- if (tokens[i][0] != '#')
- args.push_back(tokens[i]);
- //args.insert(args.end(), tokens.getAllStrings().begin(), tokens.getAllStrings().end());
- //}
- }
- file.close();
- }
-
- _parse(args, true);
- }
-}
Deleted: sandbox/src/libraries/core/CommandLine.h
===================================================================
--- sandbox/src/libraries/core/CommandLine.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/CommandLine.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -1,223 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-#ifndef _CommandLine_H__
-#define _CommandLine_H__
-
-#include "CorePrereqs.h"
-
-#include <map>
-#include "util/OrxAssert.h"
-#include "util/MultiType.h"
-
-#define SetCommandLineArgument(name, defaultValue) \
- orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
- = orxonox::CommandLine::addArgument(#name, defaultValue, false)
-#define SetCommandLineOnlyArgument(name, defaultValue) \
- orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
- = orxonox::CommandLine::addArgument(#name, defaultValue, true)
-#define SetCommandLineSwitch(name) \
- orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
- = orxonox::CommandLine::addArgument(#name, false, false)
-#define SetCommandLineOnlySwitch(name) \
- orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
- = orxonox::CommandLine::addArgument(#name, false, true)
-
-
-namespace orxonox
-{
- /**
- @brief
- Container class for a command line argument of any type supported by MultiType.
-
- Whenever you want to have an option specified by a command line switch,
- you need to first define it with SetCommandLineArgument(name, defaultValue).
- It is then added to a map and possibly changed when the command line is being parsed.
- If the option was not given, you can detect this by asking hasDefaultValue().
-
- There is a possibility to define a short cut so you can write "-p 20" instead of "--port 20".
- Note the difference between "-" and "--"!
- Also, there is no restriction to the number of strings you add after --name.
- So "--startVector (2, 4, 5)" is perfectly legal.
-
- Retrieving an argument is possible with the getCommandLineArgument function of the
- CommandLine class. It is a Singleton, but the public interface is static.
- */
- class _CoreExport CommandLineArgument
- {
- friend class CommandLine;
-
- public:
- //! Tells whether the value has been changed by the command line.
- bool hasDefaultValue() const { return bHasDefaultValue_; }
- //! Returns the name of the argument.
- const std::string& getName() const { return name_; }
-
- //! Returns the shortcut (example: "-p 22" for "--port 22") of the argument.
- //! Evaluates to "" if there is none.
- const std::string& getShortcut() const { return shortcut_; }
- //! Sets the shortcut for the argument
- CommandLineArgument& shortcut(const std::string& shortcut)
- { this->shortcut_ = shortcut; return *this; }
-
- //! Returns the usage information
- const std::string& getInformation() const { return this->usageInformation_; }
- //! Sets the option information when displaying orxonox usage.
- CommandLineArgument& information(const std::string& usage)
- { this->usageInformation_ = usage; return *this; }
-
- //! Returns the actual value of the argument. Can be equal to default value.
- MultiType getValue() const { return value_; }
- //! Returns the given default value as type T.
- MultiType getDefaultValue() const { return defaultValue_; }
-
- private:
- //! Constructor initialises both value_ and defaultValue_ with defaultValue.
- CommandLineArgument(const std::string& name, const MultiType& defaultValue, bool bCommandLineOnly)
- : bHasDefaultValue_(true)
- , name_(name)
- , value_(defaultValue)
- , defaultValue_(defaultValue)
- , bCommandLineOnly_(bCommandLineOnly)
- { }
-
- //! Undefined copy constructor
- CommandLineArgument(const CommandLineArgument& instance);
- ~CommandLineArgument() { }
-
- //! Parses the value string of a command line argument.
- void parse(const std::string& value, bool bParsingFile);
-
- //! Tells whether the value has been changed by the command line.
- bool bHasDefaultValue_;
-
- private:
- std::string name_; //!< Name of the argument
- std::string shortcut_; //!< Shortcut of the argument. @see getShortcut().
- std::string usageInformation_; //!< Tells about the usage of this parameter
-
- MultiType value_; //!< The actual value
- MultiType defaultValue_; //!< Default value. Should not be changed.
- bool bCommandLineOnly_; //!< Whether you cannot specify the value in a text file
- };
-
-
- /**
- @brief
- Global interface to command line options.
- Allows to add and retrieve command line arguments. Also does the parsing.
- @note
- Internally it is a Singleton, but the public interface is static.
- @see
- CommandLineArgument
- */
- class _CoreExport CommandLine
- {
- public:
-
- //! Parse redirection to internal member method.
- static void parseCommandLine(const std::string& cmdLine) { _getInstance()._parseCommandLine(cmdLine); }
- static void parseFile() { _getInstance()._parseFile(); }
-
- static std::string getUsageInformation();
-
- static const CommandLineArgument* getArgument(const std::string& name);
- //! Writes the argument value in the given parameter.
- template <class T>
- static void getValue(const std::string& name, T* value)
- { *value = (T)(getArgument(name)->getValue()); }
- static MultiType getValue(const std::string& name)
- { return getArgument(name)->getValue(); }
- template <class T>
- static CommandLineArgument& addArgument(const std::string& name, T defaultValue, bool bCommandLineOnly);
-
- static bool existsArgument(const std::string& name)
- {
- std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.find(name);
- return !(it == _getInstance().cmdLineArgs_.end());
- }
-
- static void destroyAllArguments();
-
- private:
- //! Constructor initialises bFirstTimeParse_ with true.
- CommandLine() : bFirstTimeParse_(true) { }
- //! Undefined copy constructor
- CommandLine(const CommandLine& instance);
- ~CommandLine();
-
- static CommandLine& _getInstance();
-
- void _parseCommandLine(const std::string& cmdLine);
- void _parseFile();
- void _parse(const std::vector<std::string>& arguments, bool bParsingFile);
- void checkFullArgument(const std::string& name, const std::string& value, bool bParsingFile);
- void checkShortcut(const std::string& shortcut, const std::string& value, bool bParsingFile);
-
- /**
- Tells whether we parsed for the first time. The CommmandLineArguments are added before main().
- So when we call parse() the first time, we need to create a map with all shortcuts since these
- get added after addCommandLineArgument().
- */
- bool bFirstTimeParse_;
-
- //! Holds all pointers to the arguments and serves as a search map by name.
- std::map<std::string, CommandLineArgument*> cmdLineArgs_;
- //! Search map by shortcut for the arguments.
- std::map<std::string, CommandLineArgument*> cmdLineArgsShortcut_;
- };
-
- template <>
- inline void CommandLine::getValue<std::string>(const std::string& name, std::string* value)
- {
- *value = getArgument(name)->getValue().getString();
- }
-
- /**
- @brief
- Adds a new CommandLineArgument to the internal map.
- Note that only such arguments are actually valid.
- @param name
- Name of the argument. Shortcut can be added later.
- @param defaultValue
- Default value that is used when argument was not given.
- */
- template <class T>
- CommandLineArgument& CommandLine::addArgument(const std::string& name, T defaultValue, bool bCommandLineOnly)
- {
- OrxAssert(!_getInstance().existsArgument(name),
- "Cannot add a command line argument with name '" + name + "' twice.");
- OrxAssert(MultiType(defaultValue).getType() != MT_Type::Bool || MultiType(defaultValue).getBool() != true,
- "Boolean command line arguments with positive default values are not supported." << std::endl
- << "Please use SetCommandLineSwitch and adjust your argument: " << name);
-
- return *(_getInstance().cmdLineArgs_[name] = new CommandLineArgument(name, defaultValue, bCommandLineOnly));
- }
-}
-
-#endif /* _CommandLine_H__ */
Copied: sandbox/src/libraries/core/CommandLineParser.cc (from rev 6035, code/trunk/src/libraries/core/CommandLineParser.cc)
===================================================================
--- sandbox/src/libraries/core/CommandLineParser.cc (rev 0)
+++ sandbox/src/libraries/core/CommandLineParser.cc 2009-11-05 20:22:22 UTC (rev 6038)
@@ -0,0 +1,377 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "CommandLineParser.h"
+
+#include <algorithm>
+#include <sstream>
+
+#include "util/Convert.h"
+#include "util/Debug.h"
+#include "util/Exception.h"
+#include "util/StringUtils.h"
+#include "util/SubString.h"
+#include "PathConfig.h"
+
+namespace orxonox
+{
+ SetCommandLineOnlyArgument(optionsFile, "start.ini").shortcut("o");
+
+ /**
+ @brief
+ Parses a value string for a command line argument.
+ It simply uses convertValue(Output, Input) to do that.
+ Bools are treated specially. That is necessary
+ so that you can have simple command line switches.
+ */
+ void CommandLineArgument::parse(const std::string& value, bool bParsingFile)
+ {
+ if (bParsingFile && this->bCommandLineOnly_)
+ ThrowException(Argument, "Command line argument '" + getName() + "' is not allowed in files.");
+ if (value_.getType() == MT_Type::Bool)
+ {
+ // simulate command line switch
+ bool temp;
+ if (convertValue(&temp, value))
+ {
+ this->bHasDefaultValue_ = false;
+ this->value_ = temp;
+ }
+ else if (value == "")
+ {
+ this->bHasDefaultValue_ = false;
+ this->value_ = true;
+ }
+ else
+ ThrowException(Argument, "Could not read command line argument '" + getName() + "'.");
+ }
+ else
+ {
+ if (!value_.setValue(value))
+ {
+ value_.setValue(defaultValue_);
+ ThrowException(Argument, "Could not read command line argument '" + getName() + "'.");
+ }
+ else
+ this->bHasDefaultValue_ = false;
+ }
+ }
+
+
+ /**
+ @brief
+ Destructor destroys all CommandLineArguments with it.
+ */
+ CommandLineParser::~CommandLineParser()
+ {
+ CommandLineParser::destroyAllArguments();
+ }
+
+ /**
+ @brief
+ Returns a unique instance (Meyers Singleton).
+ */
+ CommandLineParser& CommandLineParser::_getInstance()
+ {
+ static CommandLineParser instance;
+ return instance;
+ }
+
+ /**
+ @brief
+ Destroys all command line arguments. This should be called at the end
+ of main. Do not use before that.
+ */
+ void CommandLineParser::destroyAllArguments()
+ {
+ for (std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.begin();
+ it != _getInstance().cmdLineArgs_.end(); ++it)
+ delete it->second;
+ _getInstance().cmdLineArgs_.clear();
+ }
+
+ /**
+ @brief
+ Reads the command line parses the values of each argument.
+ It is then stored in the corresponding CommandLineArgument.
+ @note
+ The reason that you have to provide the string to be parsed as
+ space separted list is because of argc and argv. If you only have
+ a whole string, simply use getAllStrings() of SubString.
+ @param arguments
+ Vector of space separated strings.
+ */
+ void CommandLineParser::_parse(const std::vector<std::string>& arguments, bool bParsingFile)
+ {
+ try
+ {
+ // why this? See bFirstTimeParse_ declaration.
+ if (bFirstTimeParse_)
+ {
+ // first shove all the shortcuts in a map
+ for (std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.begin();
+ it != cmdLineArgs_.end(); ++it)
+ {
+ OrxAssert(cmdLineArgsShortcut_.find(it->second->getShortcut()) == cmdLineArgsShortcut_.end(),
+ "Cannot have two command line shortcut with the same name.");
+ if (it->second->getShortcut() != "")
+ cmdLineArgsShortcut_[it->second->getShortcut()] = it->second;
+ }
+ bFirstTimeParse_ = false;
+ }
+
+ std::string name;
+ std::string shortcut;
+ std::string value;
+ for (unsigned int i = 0; i < arguments.size(); ++i)
+ {
+ if (arguments[i].size() != 0)
+ {
+ // sure not ""
+ if (arguments[i][0] == '-')
+ {
+ // start with "-"
+ if (arguments[i].size() == 1)
+ {
+ // argument[i] is "-", probably a minus sign
+ value += "- ";
+ }
+ else if (arguments[i][1] <= 57 && arguments[i][1] >= 48)
+ {
+ // negative number as a value
+ value += arguments[i] + " ";
+ }
+ else
+ {
+ // can be shortcut or full name argument
+
+ // save old data first
+ value = removeTrailingWhitespaces(value);
+ if (name != "")
+ {
+ checkFullArgument(name, value, bParsingFile);
+ name = "";
+ assert(shortcut == "");
+ }
+ else if (shortcut != "")
+ {
+ checkShortcut(shortcut, value, bParsingFile);
+ shortcut = "";
+ assert(name == "");
+ }
+
+ if (arguments[i][1] == '-')
+ {
+ // full name argument with "--name"
+ name = arguments[i].substr(2);
+ }
+ else
+ {
+ // shortcut with "-s"
+ shortcut = arguments[i].substr(1);
+ }
+
+ // reset value string
+ value = "";
+ }
+ }
+ else
+ {
+ // value string
+
+ if (name == "" && shortcut == "")
+ {
+ ThrowException(Argument, "Expected \"-\" or \"-\" in command line arguments.\n");
+ }
+
+ // Concatenate strings as long as there's no new argument by "-" or "--"
+ value += arguments[i] + ' ';
+ }
+ }
+ }
+
+ // parse last argument
+ value = removeTrailingWhitespaces(value);
+ if (name != "")
+ {
+ checkFullArgument(name, value, bParsingFile);
+ assert(shortcut == "");
+ }
+ else if (shortcut != "")
+ {
+ checkShortcut(shortcut, value, bParsingFile);
+ assert(name == "");
+ }
+ }
+ catch (const ArgumentException& ex)
+ {
+ COUT(0) << "Could not parse command line (including additional files): " << ex.what() << std::endl;
+ COUT(0) << CommandLineParser::getUsageInformation() << std::endl;
+ throw GeneralException("");
+ }
+ }
+
+ /**
+ @brief
+ Parses an argument based on its full name.
+ @param name
+ Full name of the argument
+ @param value
+ String containing the value
+ */
+ void CommandLineParser::checkFullArgument(const std::string& name, const std::string& value, bool bParsingFile)
+ {
+ std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.find(name);
+ if (it == cmdLineArgs_.end())
+ ThrowException(Argument, "Command line argument '" + name + "' does not exist.");
+
+ it->second->parse(value, bParsingFile);
+ }
+
+ /**
+ @brief
+ Parses an argument based on its shortcut.
+ @param shortcut
+ Shotcut to the argument
+ @param value
+ String containing the value
+ */
+ void CommandLineParser::checkShortcut(const std::string& shortcut, const std::string& value, bool bParsingFile)
+ {
+ std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgsShortcut_.find(shortcut);
+ if (it == cmdLineArgsShortcut_.end())
+ ThrowException(Argument, "Command line shortcut '" + shortcut + "' does not exist.");
+
+ it->second->parse(value, bParsingFile);
+ }
+
+ std::string CommandLineParser::getUsageInformation()
+ {
+ CommandLineParser& inst = _getInstance();
+ std::ostringstream infoStr;
+
+ // determine maximum name size
+ size_t maxNameSize = 0;
+ for (std::map<std::string, CommandLineArgument*>::const_iterator it = inst.cmdLineArgs_.begin();
+ it != inst.cmdLineArgs_.end(); ++it)
+ {
+ maxNameSize = std::max(it->second->getName().size(), maxNameSize);
+ }
+
+ infoStr << std::endl;
+ infoStr << "Usage: orxonox [options]" << std::endl;
+ infoStr << "Available options:" << std::endl;
+
+ for (std::map<std::string, CommandLineArgument*>::const_iterator it = inst.cmdLineArgs_.begin();
+ it != inst.cmdLineArgs_.end(); ++it)
+ {
+ if (it->second->getShortcut() != "")
+ infoStr << " [-" << it->second->getShortcut() << "] ";
+ else
+ infoStr << " ";
+ infoStr << "--" << it->second->getName() << " ";
+ if (it->second->getValue().getType() != MT_Type::Bool)
+ infoStr << "ARG ";
+ else
+ infoStr << " ";
+ // fill with the necessary amount of blanks
+ infoStr << std::string(maxNameSize - it->second->getName().size(), ' ');
+ infoStr << ": " << it->second->getInformation();
+ infoStr << std::endl;
+ }
+ return infoStr.str();
+ }
+
+ /**
+ @brief
+ Retrieves a CommandLineArgument.
+ The method throws an exception if 'name' was not found or the value could not be converted.
+ @note
+ You shold of course not call this method before the command line has been parsed.
+ */
+ const CommandLineArgument* CommandLineParser::getArgument(const std::string& name)
+ {
+ std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.find(name);
+ if (it == _getInstance().cmdLineArgs_.end())
+ {
+ ThrowException(Argument, "Could find command line argument '" + name + "'.");
+ }
+ else
+ {
+ return it->second;
+ }
+ }
+
+ /**
+ @brief
+ Parses only the command line for CommandLineArguments.
+ */
+ void CommandLineParser::_parseCommandLine(const std::string& cmdLine)
+ {
+ std::vector<std::string> args;
+ SubString tokens(cmdLine, " ", " ", false, '\\', true, '"', true, '(', ')', false);
+ for (unsigned i = 0; i < tokens.size(); ++i)
+ args.push_back(tokens[i]);
+ this->_parse(args, false);
+ }
+
+ /**
+ @brief
+ Parses start.ini (or the file specified with --optionsFile) for CommandLineArguments.
+ */
+ void CommandLineParser::_parseFile()
+ {
+ std::string filename = CommandLineParser::getValue("optionsFile").getString();
+
+ // look for additional arguments in given file or start.ini as default
+ // They will not overwrite the arguments given directly
+ std::ifstream file;
+ file.open((PathConfig::getConfigPathString() + filename).c_str());
+ std::vector<std::string> args;
+ if (file)
+ {
+ while (!file.eof())
+ {
+ std::string line;
+ std::getline(file, line);
+ line = removeTrailingWhitespaces(line);
+ //if (!(line[0] == '#' || line[0] == '%'))
+ //{
+ SubString tokens(line, " ", " ", false, '\\', true, '"', true, '(', ')', false, '#');
+ for (unsigned i = 0; i < tokens.size(); ++i)
+ if (tokens[i][0] != '#')
+ args.push_back(tokens[i]);
+ //args.insert(args.end(), tokens.getAllStrings().begin(), tokens.getAllStrings().end());
+ //}
+ }
+ file.close();
+ }
+
+ _parse(args, true);
+ }
+}
Copied: sandbox/src/libraries/core/CommandLineParser.h (from rev 6035, code/trunk/src/libraries/core/CommandLineParser.h)
===================================================================
--- sandbox/src/libraries/core/CommandLineParser.h (rev 0)
+++ sandbox/src/libraries/core/CommandLineParser.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -0,0 +1,223 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _CommandLine_H__
+#define _CommandLine_H__
+
+#include "CorePrereqs.h"
+
+#include <map>
+#include "util/OrxAssert.h"
+#include "util/MultiType.h"
+
+#define SetCommandLineArgument(name, defaultValue) \
+ orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
+ = orxonox::CommandLineParser::addArgument(#name, defaultValue, false)
+#define SetCommandLineOnlyArgument(name, defaultValue) \
+ orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
+ = orxonox::CommandLineParser::addArgument(#name, defaultValue, true)
+#define SetCommandLineSwitch(name) \
+ orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
+ = orxonox::CommandLineParser::addArgument(#name, false, false)
+#define SetCommandLineOnlySwitch(name) \
+ orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
+ = orxonox::CommandLineParser::addArgument(#name, false, true)
+
+
+namespace orxonox
+{
+ /**
+ @brief
+ Container class for a command line argument of any type supported by MultiType.
+
+ Whenever you want to have an option specified by a command line switch,
+ you need to first define it with SetCommandLineArgument(name, defaultValue).
+ It is then added to a map and possibly changed when the command line is being parsed.
+ If the option was not given, you can detect this by asking hasDefaultValue().
+
+ There is a possibility to define a short cut so you can write "-p 20" instead of "--port 20".
+ Note the difference between "-" and "--"!
+ Also, there is no restriction to the number of strings you add after --name.
+ So "--startVector (2, 4, 5)" is perfectly legal.
+
+ Retrieving an argument is possible with the getCommandLineArgument function of the
+ CommandLineParser class. It is a Singleton, but the public interface is static.
+ */
+ class _CoreExport CommandLineArgument
+ {
+ friend class CommandLineParser;
+
+ public:
+ //! Tells whether the value has been changed by the command line.
+ bool hasDefaultValue() const { return bHasDefaultValue_; }
+ //! Returns the name of the argument.
+ const std::string& getName() const { return name_; }
+
+ //! Returns the shortcut (example: "-p 22" for "--port 22") of the argument.
+ //! Evaluates to "" if there is none.
+ const std::string& getShortcut() const { return shortcut_; }
+ //! Sets the shortcut for the argument
+ CommandLineArgument& shortcut(const std::string& shortcut)
+ { this->shortcut_ = shortcut; return *this; }
+
+ //! Returns the usage information
+ const std::string& getInformation() const { return this->usageInformation_; }
+ //! Sets the option information when displaying orxonox usage.
+ CommandLineArgument& information(const std::string& usage)
+ { this->usageInformation_ = usage; return *this; }
+
+ //! Returns the actual value of the argument. Can be equal to default value.
+ MultiType getValue() const { return value_; }
+ //! Returns the given default value as type T.
+ MultiType getDefaultValue() const { return defaultValue_; }
+
+ private:
+ //! Constructor initialises both value_ and defaultValue_ with defaultValue.
+ CommandLineArgument(const std::string& name, const MultiType& defaultValue, bool bCommandLineOnly)
+ : bHasDefaultValue_(true)
+ , name_(name)
+ , value_(defaultValue)
+ , defaultValue_(defaultValue)
+ , bCommandLineOnly_(bCommandLineOnly)
+ { }
+
+ //! Undefined copy constructor
+ CommandLineArgument(const CommandLineArgument& instance);
+ ~CommandLineArgument() { }
+
+ //! Parses the value string of a command line argument.
+ void parse(const std::string& value, bool bParsingFile);
+
+ //! Tells whether the value has been changed by the command line.
+ bool bHasDefaultValue_;
+
+ private:
+ std::string name_; //!< Name of the argument
+ std::string shortcut_; //!< Shortcut of the argument. @see getShortcut().
+ std::string usageInformation_; //!< Tells about the usage of this parameter
+
+ MultiType value_; //!< The actual value
+ MultiType defaultValue_; //!< Default value. Should not be changed.
+ bool bCommandLineOnly_; //!< Whether you cannot specify the value in a text file
+ };
+
+
+ /**
+ @brief
+ Global interface to command line options.
+ Allows to add and retrieve command line arguments. Also does the parsing.
+ @note
+ Internally it is a Singleton, but the public interface is static.
+ @see
+ CommandLineArgument
+ */
+ class _CoreExport CommandLineParser
+ {
+ public:
+
+ //! Parse redirection to internal member method.
+ static void parseCommandLine(const std::string& cmdLine) { _getInstance()._parseCommandLine(cmdLine); }
+ static void parseFile() { _getInstance()._parseFile(); }
+
+ static std::string getUsageInformation();
+
+ static const CommandLineArgument* getArgument(const std::string& name);
+ //! Writes the argument value in the given parameter.
+ template <class T>
+ static void getValue(const std::string& name, T* value)
+ { *value = (T)(getArgument(name)->getValue()); }
+ static MultiType getValue(const std::string& name)
+ { return getArgument(name)->getValue(); }
+ template <class T>
+ static CommandLineArgument& addArgument(const std::string& name, T defaultValue, bool bCommandLineOnly);
+
+ static bool existsArgument(const std::string& name)
+ {
+ std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.find(name);
+ return !(it == _getInstance().cmdLineArgs_.end());
+ }
+
+ static void destroyAllArguments();
+
+ private:
+ //! Constructor initialises bFirstTimeParse_ with true.
+ CommandLineParser() : bFirstTimeParse_(true) { }
+ //! Undefined copy constructor
+ CommandLineParser(const CommandLineParser& instance);
+ ~CommandLineParser();
+
+ static CommandLineParser& _getInstance();
+
+ void _parseCommandLine(const std::string& cmdLine);
+ void _parseFile();
+ void _parse(const std::vector<std::string>& arguments, bool bParsingFile);
+ void checkFullArgument(const std::string& name, const std::string& value, bool bParsingFile);
+ void checkShortcut(const std::string& shortcut, const std::string& value, bool bParsingFile);
+
+ /**
+ Tells whether we parsed for the first time. The CommmandLineArguments are added before main().
+ So when we call parse() the first time, we need to create a map with all shortcuts since these
+ get added after addCommandLineArgument().
+ */
+ bool bFirstTimeParse_;
+
+ //! Holds all pointers to the arguments and serves as a search map by name.
+ std::map<std::string, CommandLineArgument*> cmdLineArgs_;
+ //! Search map by shortcut for the arguments.
+ std::map<std::string, CommandLineArgument*> cmdLineArgsShortcut_;
+ };
+
+ template <>
+ inline void CommandLineParser::getValue<std::string>(const std::string& name, std::string* value)
+ {
+ *value = getArgument(name)->getValue().getString();
+ }
+
+ /**
+ @brief
+ Adds a new CommandLineArgument to the internal map.
+ Note that only such arguments are actually valid.
+ @param name
+ Name of the argument. Shortcut can be added later.
+ @param defaultValue
+ Default value that is used when argument was not given.
+ */
+ template <class T>
+ CommandLineArgument& CommandLineParser::addArgument(const std::string& name, T defaultValue, bool bCommandLineOnly)
+ {
+ OrxAssert(!_getInstance().existsArgument(name),
+ "Cannot add a command line argument with name '" + name + "' twice.");
+ OrxAssert(MultiType(defaultValue).getType() != MT_Type::Bool || MultiType(defaultValue).getBool() != true,
+ "Boolean command line arguments with positive default values are not supported." << std::endl
+ << "Please use SetCommandLineSwitch and adjust your argument: " << name);
+
+ return *(_getInstance().cmdLineArgs_[name] = new CommandLineArgument(name, defaultValue, bCommandLineOnly));
+ }
+}
+
+#endif /* _CommandLine_H__ */
Modified: sandbox/src/libraries/core/ConfigFileManager.cc
===================================================================
--- sandbox/src/libraries/core/ConfigFileManager.cc 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/ConfigFileManager.cc 2009-11-05 20:22:22 UTC (rev 6038)
@@ -34,14 +34,14 @@
#include "util/Math.h"
#include "util/StringUtils.h"
#include "ConfigValueContainer.h"
-#include "Core.h"
+#include "PathConfig.h"
namespace orxonox
{
bool config(const std::string& classname, const std::string& varname, const std::string& value)
{
- std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname));
- if (identifier != Identifier::getLowercaseIdentifierMapEnd())
+ std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname));
+ if (identifier != Identifier::getLowercaseStringIdentifierMapEnd())
{
std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname));
if (variable != (*identifier).second->getLowercaseConfigValueMapEnd())
@@ -52,8 +52,8 @@
bool tconfig(const std::string& classname, const std::string& varname, const std::string& value)
{
- std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname));
- if (identifier != Identifier::getLowercaseIdentifierMapEnd())
+ std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname));
+ if (identifier != Identifier::getLowercaseStringIdentifierMapEnd())
{
std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname));
if (variable != (*identifier).second->getLowercaseConfigValueMapEnd())
@@ -214,11 +214,11 @@
this->clear();
// Get default file if necessary and available
- boost::filesystem::path filepath(Core::getConfigPath() / this->filename_);
+ boost::filesystem::path filepath(PathConfig::getConfigPath() / this->filename_);
if (!boost::filesystem::exists(filepath))
{
// Try to get default one from the data folder
- boost::filesystem::path defaultFilepath(Core::getDataPath() / "defaultConfig" / this->filename_);
+ boost::filesystem::path defaultFilepath(PathConfig::getDataPath() / "defaultConfig" / this->filename_);
if (boost::filesystem::exists(defaultFilepath))
{
COUT(3) << "Copied " << this->filename_ << " from the defaultConfig folder." << std::endl;
@@ -328,7 +328,7 @@
void ConfigFile::save() const
{
std::ofstream file;
- file.open((Core::getConfigPathString() + filename_).c_str(), std::fstream::out);
+ file.open((PathConfig::getConfigPathString() + filename_).c_str(), std::fstream::out);
file.setf(std::ios::fixed, std::ios::floatfield);
file.precision(6);
@@ -368,8 +368,8 @@
{
for (std::list<ConfigFileSection*>::iterator it1 = this->sections_.begin(); it1 != this->sections_.end(); )
{
- std::map<std::string, Identifier*>::const_iterator it2 = Identifier::getIdentifierMap().find((*it1)->getName());
- if (it2 != Identifier::getIdentifierMapEnd() && (*it2).second->hasConfigValues())
+ std::map<std::string, Identifier*>::const_iterator it2 = Identifier::getStringIdentifierMap().find((*it1)->getName());
+ if (it2 != Identifier::getStringIdentifierMapEnd() && (*it2).second->hasConfigValues())
{
// The section exists, delete comment
if (bCleanComments)
@@ -447,7 +447,7 @@
{
if (this->type_ == ConfigFileType::Settings)
{
- for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getIdentifierMapBegin(); it != Identifier::getIdentifierMapEnd(); ++it)
+ for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin(); it != Identifier::getStringIdentifierMapEnd(); ++it)
{
if (it->second->hasConfigValues())
{
Modified: sandbox/src/libraries/core/Core.cc
===================================================================
--- sandbox/src/libraries/core/Core.cc 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/Core.cc 2009-11-05 20:22:22 UTC (rev 6038)
@@ -36,11 +36,7 @@
#include "Core.h"
#include <cassert>
-#include <fstream>
-#include <cstdlib>
-#include <cstdio>
-#include <boost/version.hpp>
-#include <boost/filesystem.hpp>
+#include <vector>
#ifdef ORXONOX_PLATFORM_WINDOWS
# ifndef WIN32_LEAN_AND_MEAN
@@ -49,43 +45,27 @@
# include <windows.h>
# undef min
# undef max
-#elif defined(ORXONOX_PLATFORM_APPLE)
-# include <sys/param.h>
-# include <mach-o/dyld.h>
-#else /* Linux */
-# include <sys/types.h>
-# include <unistd.h>
#endif
-#include "SpecialConfig.h"
+#include "util/Clock.h"
#include "util/Debug.h"
#include "util/Exception.h"
#include "util/SignalHandler.h"
-#include "Clock.h"
-#include "CommandLine.h"
+#include "PathConfig.h"
+#include "CommandLineParser.h"
#include "ConfigFileManager.h"
#include "ConfigValueIncludes.h"
#include "CoreIncludes.h"
#include "DynLibManager.h"
-#include "Factory.h"
#include "Identifier.h"
#include "Language.h"
#include "LuaState.h"
-// Boost 1.36 has some issues with deprecated functions that have been omitted
-#if (BOOST_VERSION == 103600)
-# define BOOST_LEAF_FUNCTION filename
-#else
-# define BOOST_LEAF_FUNCTION leaf
-#endif
-
namespace orxonox
{
//! Static pointer to the singleton
Core* Core::singletonPtr_s = 0;
- SetCommandLineArgument(externalDataPath, "").information("Path to the external data files");
- SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file");
#ifdef ORXONOX_PLATFORM_WINDOWS
SetCommandLineArgument(limitToCPU, 0).information("Limits the program to one cpu/core (1, 2, 3, etc.). 0 turns it off (default)");
@@ -194,14 +174,6 @@
int softDebugLevelShell_; //!< The debug level for the ingame shell
std::string language_; //!< The language
bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called
-
- //! Path to the parent directory of the ones above if program was installed with relativ pahts
- boost::filesystem::path rootPath_;
- boost::filesystem::path executablePath_; //!< Path to the executable
- boost::filesystem::path modulePath_; //!< Path to the modules
- boost::filesystem::path dataPath_; //!< Path to the data file folder
- boost::filesystem::path configPath_; //!< Path to the config file folder
- boost::filesystem::path logPath_; //!< Path to the log file folder
};
@@ -209,86 +181,49 @@
// Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands)
: identifierDestroyer_(Identifier::destroyAllIdentifiers)
, configuration_(new CoreConfiguration()) // Don't yet create config values!
- , bDevRun_(false)
{
// Set the hard coded fixed paths
- this->setFixedPaths();
+ this->pathConfig_.reset(new PathConfig());
// Create a new dynamic library manager
this->dynLibManager_.reset(new DynLibManager());
// Load modules
- try
+ const std::vector<std::string>& modulePaths = this->pathConfig_->getModulePaths();
+ for (std::vector<std::string>::const_iterator it = modulePaths.begin(); it != modulePaths.end(); ++it)
{
- // We search for helper files with the following extension
- std::string moduleextension = specialConfig::moduleExtension;
- size_t moduleextensionlength = moduleextension.size();
-
- // Search in the directory of our executable
- boost::filesystem::path searchpath = this->configuration_->modulePath_;
-
- // Add that path to the PATH variable in case a module depends on another one
- std::string pathVariable = getenv("PATH");
- putenv(const_cast<char*>(("PATH=" + pathVariable + ";" + configuration_->modulePath_.string()).c_str()));
-
- boost::filesystem::directory_iterator file(searchpath);
- boost::filesystem::directory_iterator end;
-
- // Iterate through all files
- while (file != end)
+ try
{
- std::string filename = file->BOOST_LEAF_FUNCTION();
-
- // Check if the file ends with the exension in question
- if (filename.size() > moduleextensionlength)
- {
- if (filename.substr(filename.size() - moduleextensionlength) == moduleextension)
- {
- // We've found a helper file - now load the library with the same name
- std::string library = filename.substr(0, filename.size() - moduleextensionlength);
- boost::filesystem::path librarypath = searchpath / library;
-
- try
- {
- DynLibManager::getInstance().load(librarypath.string());
- }
- catch (...)
- {
- COUT(1) << "Couldn't load module \"" << librarypath.string() << "\": " << Exception::handleMessage() << std::endl;
- }
- }
- }
-
- ++file;
+ this->dynLibManager_->load(*it);
}
+ catch (...)
+ {
+ COUT(1) << "Couldn't load module \"" << *it << "\": " << Exception::handleMessage() << std::endl;
+ }
}
- catch (...)
- {
- COUT(1) << "An error occurred while loading modules: " << Exception::handleMessage() << std::endl;
- }
// Parse command line arguments AFTER the modules have been loaded (static code!)
- CommandLine::parseCommandLine(cmdLine);
+ CommandLineParser::parseCommandLine(cmdLine);
// Set configurable paths like log, config and media
- this->setConfigurablePaths();
+ this->pathConfig_->setConfigurablePaths();
// create a signal handler (only active for linux)
// This call is placed as soon as possible, but after the directories are set
this->signalHandler_.reset(new SignalHandler());
- this->signalHandler_->doCatch(configuration_->executablePath_.string(), Core::getLogPathString() + "orxonox_crash.log");
+ this->signalHandler_->doCatch(PathConfig::getExecutablePathString(), PathConfig::getLogPathString() + "orxonox_crash.log");
// Set the correct log path. Before this call, /tmp (Unix) or %TEMP% was used
- OutputHandler::getOutStream().setLogPath(Core::getLogPathString());
+ OutputHandler::getOutStream().setLogPath(PathConfig::getLogPathString());
// Parse additional options file now that we know its path
- CommandLine::parseFile();
+ CommandLineParser::parseFile();
#ifdef ORXONOX_PLATFORM_WINDOWS
// limit the main thread to the first core so that QueryPerformanceCounter doesn't jump
// do this after ogre has initialised. Somehow Ogre changes the settings again (not through
// the timer though).
- int limitToCPU = CommandLine::getValue("limitToCPU");
+ int limitToCPU = CommandLineParser::getValue("limitToCPU");
if (limitToCPU > 0)
setThreadAffinity(static_cast<unsigned int>(limitToCPU));
#endif
@@ -296,13 +231,13 @@
// Manage ini files and set the default settings file (usually orxonox.ini)
this->configFileManager_.reset(new ConfigFileManager());
this->configFileManager_->setFilename(ConfigFileType::Settings,
- CommandLine::getValue("settingsFile").getString());
+ CommandLineParser::getValue("settingsFile").getString());
// Required as well for the config values
this->languageInstance_.reset(new Language());
// creates the class hierarchy for all classes with factories
- Factory::createClassHierarchy();
+ Identifier::createClassHierarchy();
// Do this soon after the ConfigFileManager has been created to open up the
// possibility to configure everything below here
@@ -375,42 +310,6 @@
Core::getInstance().configuration_->resetLanguage();
}
- /*static*/ const boost::filesystem::path& Core::getDataPath()
- {
- return getInstance().configuration_->dataPath_;
- }
- /*static*/ std::string Core::getDataPathString()
- {
- return getInstance().configuration_->dataPath_.string() + '/';
- }
-
- /*static*/ const boost::filesystem::path& Core::getConfigPath()
- {
- return getInstance().configuration_->configPath_;
- }
- /*static*/ std::string Core::getConfigPathString()
- {
- return getInstance().configuration_->configPath_.string() + '/';
- }
-
- /*static*/ const boost::filesystem::path& Core::getLogPath()
- {
- return getInstance().configuration_->logPath_;
- }
- /*static*/ std::string Core::getLogPathString()
- {
- return getInstance().configuration_->logPath_.string() + '/';
- }
-
- /*static*/ const boost::filesystem::path& Core::getRootPath()
- {
- return getInstance().configuration_->rootPath_;
- }
- /*static*/ std::string Core::getRootPathString()
- {
- return getInstance().configuration_->rootPath_.string() + '/';
- }
-
/**
@note
The code of this function has been copied and adjusted from OGRE, an open source graphics engine.
@@ -457,175 +356,6 @@
#endif
}
- /**
- @brief
- Retrievs the executable path and sets all hard coded fixed path (currently only the module path)
- Also checks for "orxonox_dev_build.keep_me" in the executable diretory.
- If found it means that this is not an installed run, hence we
- don't write the logs and config files to ~/.orxonox
- @throw
- GeneralException
- */
- void Core::setFixedPaths()
- {
- //////////////////////////
- // FIND EXECUTABLE PATH //
- //////////////////////////
-
-#ifdef ORXONOX_PLATFORM_WINDOWS
- // get executable module
- TCHAR buffer[1024];
- if (GetModuleFileName(NULL, buffer, 1024) == 0)
- ThrowException(General, "Could not retrieve executable path.");
-
-#elif defined(ORXONOX_PLATFORM_APPLE)
- char buffer[1024];
- unsigned long path_len = 1023;
- if (_NSGetExecutablePath(buffer, &path_len))
- ThrowException(General, "Could not retrieve executable path.");
-
-#else /* Linux */
- /* written by Nicolai Haehnle <prefect_ at gmx.net> */
-
- /* Get our PID and build the name of the link in /proc */
- char linkname[64]; /* /proc/<pid>/exe */
- if (snprintf(linkname, sizeof(linkname), "/proc/%i/exe", getpid()) < 0)
- {
- /* This should only happen on large word systems. I'm not sure
- what the proper response is here.
- Since it really is an assert-like condition, aborting the
- program seems to be in order. */
- assert(false);
- }
-
- /* Now read the symbolic link */
- char buffer[1024];
- int ret;
- ret = readlink(linkname, buffer, 1024);
- /* In case of an error, leave the handling up to the caller */
- if (ret == -1)
- ThrowException(General, "Could not retrieve executable path.");
-
- /* Ensure proper NUL termination */
- buffer[ret] = 0;
-#endif
-
- configuration_->executablePath_ = boost::filesystem::path(buffer);
-#ifndef ORXONOX_PLATFORM_APPLE
- configuration_->executablePath_ = configuration_->executablePath_.branch_path(); // remove executable name
-#endif
-
- /////////////////////
- // SET MODULE PATH //
- /////////////////////
-
- if (boost::filesystem::exists(configuration_->executablePath_ / "orxonox_dev_build.keep_me"))
- {
- COUT(1) << "Running from the build tree." << std::endl;
- Core::bDevRun_ = true;
- configuration_->modulePath_ = specialConfig::moduleDevDirectory;
- }
- else
- {
-
-#ifdef INSTALL_COPYABLE // --> relative paths
-
- // Also set the root path
- boost::filesystem::path relativeExecutablePath(specialConfig::defaultRuntimePath);
- configuration_->rootPath_ = configuration_->executablePath_;
- while (!boost::filesystem::equivalent(configuration_->rootPath_ / relativeExecutablePath, configuration_->executablePath_)
- && !configuration_->rootPath_.empty())
- configuration_->rootPath_ = configuration_->rootPath_.branch_path();
- if (configuration_->rootPath_.empty())
- ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");
-
- // Module path is fixed as well
- configuration_->modulePath_ = configuration_->rootPath_ / specialConfig::defaultModulePath;
-
-#else
-
- // There is no root path, so don't set it at all
- // Module path is fixed as well
- configuration_->modulePath_ = specialConfig::moduleInstallDirectory;
-
-#endif
- }
- }
-
- /**
- @brief
- Sets config, log and media path and creates folders if necessary.
- @throws
- GeneralException
- */
- void Core::setConfigurablePaths()
- {
- if (Core::isDevelopmentRun())
- {
- configuration_->dataPath_ = specialConfig::dataDevDirectory;
- configuration_->configPath_ = specialConfig::configDevDirectory;
- configuration_->logPath_ = specialConfig::logDevDirectory;
- }
- else
- {
-
-#ifdef INSTALL_COPYABLE // --> relative paths
-
- // Using paths relative to the install prefix, complete them
- configuration_->dataPath_ = configuration_->rootPath_ / specialConfig::defaultDataPath;
- configuration_->configPath_ = configuration_->rootPath_ / specialConfig::defaultConfigPath;
- configuration_->logPath_ = configuration_->rootPath_ / specialConfig::defaultLogPath;
-
-#else
-
- configuration_->dataPath_ = specialConfig::dataInstallDirectory;
-
- // Get user directory
-# ifdef ORXONOX_PLATFORM_UNIX /* Apple? */
- char* userDataPathPtr(getenv("HOME"));
-# else
- char* userDataPathPtr(getenv("APPDATA"));
-# endif
- if (userDataPathPtr == NULL)
- ThrowException(General, "Could not retrieve user data path.");
- boost::filesystem::path userDataPath(userDataPathPtr);
- userDataPath /= ".orxonox";
-
- configuration_->configPath_ = userDataPath / specialConfig::defaultConfigPath;
- configuration_->logPath_ = userDataPath / specialConfig::defaultLogPath;
-
-#endif
-
- }
-
- // Option to put all the config and log files in a separate folder
- if (!CommandLine::getArgument("writingPathSuffix")->hasDefaultValue())
- {
- std::string directory(CommandLine::getValue("writingPathSuffix").getString());
- configuration_->configPath_ = configuration_->configPath_ / directory;
- configuration_->logPath_ = configuration_->logPath_ / directory;
- }
-
- // Create directories to avoid problems when opening files in non existent folders.
- std::vector<std::pair<boost::filesystem::path, std::string> > directories;
- directories.push_back(std::make_pair(boost::filesystem::path(configuration_->configPath_), "config"));
- directories.push_back(std::make_pair(boost::filesystem::path(configuration_->logPath_), "log"));
-
- for (std::vector<std::pair<boost::filesystem::path, std::string> >::iterator it = directories.begin();
- it != directories.end(); ++it)
- {
- if (boost::filesystem::exists(it->first) && !boost::filesystem::is_directory(it->first))
- {
- ThrowException(General, std::string("The ") + it->second + " directory has been preoccupied by a file! \
- Please remove " + it->first.string());
- }
- if (boost::filesystem::create_directories(it->first)) // function may not return true at all (bug?)
- {
- COUT(4) << "Created " << it->second << " directory" << std::endl;
- }
- }
- }
-
void Core::preUpdate(const Clock& time)
{
}
Modified: sandbox/src/libraries/core/Core.h
===================================================================
--- sandbox/src/libraries/core/Core.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/Core.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -27,15 +27,6 @@
*
*/
-/**
- at file
- at brief
- Declaration of the Core class.
- at details
- The Core class is a singleton, only used to configure some variables
- in the core through the config-file.
-*/
-
#ifndef _Core_H__
#define _Core_H__
@@ -54,9 +45,6 @@
/**
@brief
The Core class is a singleton used to configure the program basics.
- @details
- The class provides information about the data, config and log path.
- It determines those by the use of platform specific functions.
@remark
You should only create this singleton once because it destroys the identifiers!
*/
@@ -84,36 +72,16 @@
static const std::string& getLanguage();
static void resetLanguage();
- //! Returns the path to the data files as boost::filesystem::path
- static const boost::filesystem::path& getDataPath();
- //! Returns the path to the config files as boost::filesystem::path
- static const boost::filesystem::path& getConfigPath();
- //! Returns the path to the log files as boost::filesystem::path
- static const boost::filesystem::path& getLogPath();
- //! Returns the path to the root folder as boost::filesystem::path
- static const boost::filesystem::path& getRootPath();
- //! Returns the path to the data files as std::string
- static std::string getDataPathString();
- //! Returns the path to the config files as std::string
- static std::string getConfigPathString();
- //! Returns the path to the log files as std::string
- static std::string getLogPathString();
- //! Returns the path to the root folder as std::string
- static std::string getRootPathString();
-
- static bool isDevelopmentRun() { return getInstance().bDevRun_; }
-
private:
Core(const Core&); //!< Don't use (undefined symbol)
void preUpdate(const Clock& time);
void postUpdate(const Clock& time);
- void setFixedPaths();
- void setConfigurablePaths();
void setThreadAffinity(int limitToCPU);
// Mind the order for the destruction!
+ scoped_ptr<PathConfig> pathConfig_;
scoped_ptr<DynLibManager> dynLibManager_;
scoped_ptr<SignalHandler> signalHandler_;
SimpleScopeGuard identifierDestroyer_;
@@ -121,8 +89,6 @@
scoped_ptr<Language> languageInstance_;
scoped_ptr<CoreConfiguration> configuration_;
- bool bDevRun_; //!< True for runs in the build directory (not installed)
-
static Core* singletonPtr_s;
};
}
Modified: sandbox/src/libraries/core/CoreIncludes.h
===================================================================
--- sandbox/src/libraries/core/CoreIncludes.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/CoreIncludes.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -28,7 +28,7 @@
/**
@file
- @brief Definition of macros for Identifier and Factory.
+ @brief Definition of macros for Identifiers
Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface
or the BaseObject itself, it needs the macro RegisterRootObject(class) instead.
@@ -44,7 +44,6 @@
#include "util/Debug.h"
#include "Identifier.h"
-#include "Factory.h"
#include "ClassFactory.h"
#include "ObjectList.h"
@@ -75,11 +74,11 @@
InternRegisterObject(ClassName, true)
/**
- @brief Creates the entry in the Factory.
+ @brief Creates the Factory.
@param ClassName The name of the class
*/
#define CreateFactory(ClassName) \
- bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName)
+ Factory* _##ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName)
/**
@brief Returns the Identifier of the given class.
@@ -92,21 +91,21 @@
namespace orxonox
{
/**
- @brief Returns the Identifier with a given name through the factory.
+ @brief Returns the Identifier with a given name.
@param String The name of the class
*/
inline Identifier* ClassByString(const std::string& name)
{
- return Factory::getIdentifier(name);
+ return Identifier::getIdentifierByString(name);
}
/**
- @brief Returns the Identifier with a given network ID through the factory.
- @param networkID The network ID of the class
+ @brief Returns the Identifier with a given lowercase name.
+ @param String The lowercase name of the class
*/
- inline Identifier* ClassByID(uint32_t id)
+ inline Identifier* ClassByLowercaseString(const std::string& name)
{
- return Factory::getIdentifier(id);
+ return Identifier::getIdentifierByLowercaseString(name);
}
}
Modified: sandbox/src/libraries/core/CorePrereqs.h
===================================================================
--- sandbox/src/libraries/core/CorePrereqs.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/CorePrereqs.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -27,8 +27,9 @@
*/
/**
- @file
- @brief Contains all the necessary forward declarations for all classes and structs.
+ at file
+ at brief
+ Shared library macros, enums, constants and forward declarations for the core library
*/
#ifndef _CorePrereqs_H__
@@ -39,6 +40,7 @@
//-----------------------------------------------------------------------
// Shared library settings
//-----------------------------------------------------------------------
+
#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined( CORE_STATIC_BUILD )
# ifdef CORE_SHARED_BUILD
# define _CoreExport __declspec(dllexport)
@@ -55,21 +57,31 @@
# define _CoreExport
#endif
+//-----------------------------------------------------------------------
+// Constants
+//-----------------------------------------------------------------------
+namespace orxonox
+{
+ static const uint32_t OBJECTID_UNKNOWN = static_cast<uint32_t>(-1);
+}
+
//-----------------------------------------------------------------------
-// Forward declarations
+// Enums
//-----------------------------------------------------------------------
+
namespace orxonox
{
namespace XMLPort
{
enum Mode
{
+ NOP,
LoadObject,
SaveObject,
ExpandObject
};
- }
+}
namespace KeybindMode
{
@@ -81,13 +93,18 @@
None
};
};
+}
+//-----------------------------------------------------------------------
+// Forward declarations
+//-----------------------------------------------------------------------
+
+namespace orxonox
+{
typedef std::string LanguageEntryLabel;
class ArgumentCompleter;
class ArgumentCompletionListElement;
- class BaseFactory;
- class BaseMetaObjectListElement;
class BaseObject;
template <class T>
class ClassFactory;
@@ -97,10 +114,8 @@
class ClassTreeMaskIterator;
class ClassTreeMaskNode;
class ClassTreeMaskObjectIterator;
- class Clock;
class CommandEvaluation;
- class CommandExecutor;
- class CommandLine;
+ class CommandLineParser;
class CommandLineArgument;
class ConfigFile;
class ConfigFileEntry;
@@ -108,13 +123,14 @@
class ConfigFileEntryValue;
class ConfigFileManager;
class ConfigFileSection;
+ struct ConfigFileType;
class ConfigValueContainer;
class ConsoleCommand;
class Core;
class DynLib;
class DynLibManager;
struct Event;
- class EventContainer;
+ class EventState;
class Executor;
template <class T>
class ExecutorMember;
@@ -124,16 +140,17 @@
template <class T>
class FunctorMember;
class FunctorStatic;
+ class Game;
+ class GameState;
+ struct GameStateInfo;
+ struct GameStateTreeNode;
class GraphicsManager;
class GUIManager;
class Identifier;
class IRC;
template <class T>
class Iterator;
- class IteratorBase;
class Language;
- class LanguageEntry;
- class Loader;
class LuaState;
class MemoryArchive;
class MemoryArchiveFactory;
@@ -151,10 +168,13 @@
class ObjectListIterator;
class OgreWindowEventListener;
class OrxonoxClass;
+ class PathConfig;
struct ResourceInfo;
class Shell;
class ShellListener;
template <class T>
+ class SmartPtr;
+ template <class T>
class SubclassIdentifier;
class TclBind;
struct TclInterpreterBundle;
@@ -162,6 +182,10 @@
class TclThreadList;
class TclThreadManager;
class Template;
+ class Thread;
+ class ThreadPool;
+ template <class T>
+ class WeakPtr;
class WindowEventListener;
class XMLFile;
class XMLNameListener;
@@ -172,17 +196,10 @@
class XMLPortObjectContainer;
class XMLPortParamContainer;
- // game states
- class Game;
- class GameState;
- struct GameStateInfo;
- struct GameStateTreeNode;
-
- // input
+ // Input
class BaseCommand;
class BufferedParamCommand;
class Button;
- class CalibratorCallback;
class HalfAxis;
class InputBuffer;
class InputDevice;
@@ -191,18 +208,17 @@
class InputHandler;
class InputManager;
class InputState;
+ struct InputStatePriority;
+ class JoyStickQuantityListener;
class JoyStick;
- class Mouse;
+ class KeyBinder;
+ class KeyBinderManager;
class Keyboard;
- class KeyBinder;
class KeyDetector;
+ class KeyEvent;
+ class Mouse;
class ParamCommand;
class SimpleCommand;
-
-
- // multithreading
- class Thread;
- class ThreadPool;
}
// CppTcl
@@ -281,14 +297,7 @@
}
namespace orxonox
{
- using ticpp::Document;
using ticpp::Element;
- using ticpp::Declaration;
- using ticpp::StylesheetReference;
- using ticpp::Text;
- using ticpp::Comment;
- using ticpp::Attribute;
}
-
#endif /* _CorePrereqs_H__ */
Deleted: sandbox/src/libraries/core/Factory.cc
===================================================================
--- sandbox/src/libraries/core/Factory.cc 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/Factory.cc 2009-11-05 20:22:22 UTC (rev 6038)
@@ -1,94 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Implementation of the Factory class.
-*/
-
-#include "Factory.h"
-
-#include "util/Debug.h"
-#include "Identifier.h"
-#include "BaseObject.h"
-
-namespace orxonox
-{
- /**
- @brief Returns the Identifier with a given name.
- @param name The name of the wanted Identifier
- @return The Identifier
- */
- Identifier* Factory::getIdentifier(const std::string& name)
- {
- std::map<std::string, Identifier*>::const_iterator it = getFactoryPointer()->identifierStringMap_.find(name);
- if (it != getFactoryPointer()->identifierStringMap_.end())
- return it->second;
- else
- return 0;
- }
-
- /**
- @brief Adds a new Identifier to both maps.
- @param name The name of the identifier
- @param identifier The identifier to add
- */
- void Factory::add(const std::string& name, Identifier* identifier)
- {
- getFactoryPointer()->identifierStringMap_[name] = identifier;
- }
-
- /**
- @brief Creates the class-hierarchy by creating and destroying one object of each type.
- */
- void Factory::createClassHierarchy()
- {
- COUT(3) << "*** Factory: Create class-hierarchy" << std::endl;
- std::map<std::string, Identifier*>::iterator it;
- it = getFactoryPointer()->identifierStringMap_.begin();
- (*getFactoryPointer()->identifierStringMap_.begin()).second->startCreatingHierarchy();
- for (it = getFactoryPointer()->identifierStringMap_.begin(); it != getFactoryPointer()->identifierStringMap_.end(); ++it)
- {
- // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
- BaseObject* temp = (*it).second->fabricate(0);
- delete temp;
- }
- (*getFactoryPointer()->identifierStringMap_.begin()).second->stopCreatingHierarchy();
- COUT(3) << "*** Factory: Finished class-hierarchy creation" << std::endl;
- }
-
- /**
- @brief Ensures the Factory gets created in the right moment.
- @return The Factory.
- */
- Factory* Factory::getFactoryPointer()
- {
- static Factory theOneAndOnlyFactoryInstance = Factory();
- return &theOneAndOnlyFactoryInstance;
- }
-}
Deleted: sandbox/src/libraries/core/Factory.h
===================================================================
--- sandbox/src/libraries/core/Factory.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/Factory.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -1,98 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Definition of the Factory and the BaseFactory class.
-
- The Factory is a singleton, containing two maps to map either the name or the network ID
- of a class with the corresponding Identifier.
-
- Usage:
- ID(classname) or ID(networkID) returns the corresponding Identifier.
-
-
- BaseObject is the parent of ClassFactory which is defined in ClassFactory.h.
- It can't be defined in ClassFactory.h, because of circular dependencies.
-*/
-
-#ifndef _Factory_H__
-#define _Factory_H__
-
-#include "CorePrereqs.h"
-
-#include <map>
-#include <string>
-
-namespace orxonox
-{
- // ###############################
- // ### Factory ###
- // ###############################
- //! The Factory is used to map the name or the network ID of a class with its Identifier.
- class _CoreExport Factory
- {
- public:
- static Identifier* getIdentifier(const std::string& name);
- static Identifier* getIdentifier(const uint32_t id);
- static void add(const std::string& name, Identifier* identifier);
- static void createClassHierarchy();
-
- static Factory* getFactoryPointer(); // avoid overriding order problem in the static intialisation process
-
- /** @brief Returns the factory-map. */
- static const std::map<std::string, Identifier*>& getFacbtoryMap()
- { return Factory::getFactoryPointer()->identifierStringMap_; }
- /** @brief Returns the begin-iterator of the factory-map. */
- static std::map<std::string, Identifier*>::const_iterator getFactoryMapBegin()
- { return Factory::getFactoryPointer()->identifierStringMap_.begin(); }
- /** @brief Returns the end-iterator of the factory-map. */
- static std::map<std::string, Identifier*>::const_iterator getFactoryMapEnd()
- { return Factory::getFactoryPointer()->identifierStringMap_.end(); }
-
- private:
- Factory() {} // don't create
- Factory(const Factory& factory); // don't copy
- ~Factory() {} // don't delete
-
- std::map<std::string, Identifier*> identifierStringMap_; //!< The map, mapping the name with the Identifier
- };
-
- // ###############################
- // ### BaseFactory ###
- // ###############################
- //! Base-class of ClassFactory. Has to be defined separate because of circular dependencies.
- class _CoreExport BaseFactory
- {
- public:
- virtual BaseObject* fabricate(BaseObject* creator) = 0;
- virtual ~BaseFactory() {};
- };
-}
-
-#endif /* _Factory_H__ */
Modified: sandbox/src/libraries/core/Functor.h
===================================================================
--- sandbox/src/libraries/core/Functor.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/Functor.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -190,34 +190,40 @@
-#define FUNCTOR_TEMPLATE(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE##ismember##returnvalue##numparams
-#define FUNCTOR_TEMPLATE000
-#define FUNCTOR_TEMPLATE001 template <class P1>
-#define FUNCTOR_TEMPLATE002 template <class P1, class P2>
-#define FUNCTOR_TEMPLATE003 template <class P1, class P2, class P3>
-#define FUNCTOR_TEMPLATE004 template <class P1, class P2, class P3, class P4>
-#define FUNCTOR_TEMPLATE005 template <class P1, class P2, class P3, class P4, class P5>
-#define FUNCTOR_TEMPLATE010 template <class R>
-#define FUNCTOR_TEMPLATE011 template <class R, class P1>
-#define FUNCTOR_TEMPLATE012 template <class R, class P1, class P2>
-#define FUNCTOR_TEMPLATE013 template <class R, class P1, class P2, class P3>
-#define FUNCTOR_TEMPLATE014 template <class R, class P1, class P2, class P3, class P4>
-#define FUNCTOR_TEMPLATE015 template <class R, class P1, class P2, class P3, class P4, class P5>
-#define FUNCTOR_TEMPLATE100 template <class T>
-#define FUNCTOR_TEMPLATE101 template <class T, class P1>
-#define FUNCTOR_TEMPLATE102 template <class T, class P1, class P2>
-#define FUNCTOR_TEMPLATE103 template <class T, class P1, class P2, class P3>
-#define FUNCTOR_TEMPLATE104 template <class T, class P1, class P2, class P3, class P4>
-#define FUNCTOR_TEMPLATE105 template <class T, class P1, class P2, class P3, class P4, class P5>
-#define FUNCTOR_TEMPLATE110 template <class T, class R>
-#define FUNCTOR_TEMPLATE111 template <class T, class R, class P1>
-#define FUNCTOR_TEMPLATE112 template <class T, class R, class P1, class P2>
-#define FUNCTOR_TEMPLATE113 template <class T, class R, class P1, class P2, class P3>
-#define FUNCTOR_TEMPLATE114 template <class T, class R, class P1, class P2, class P3, class P4>
-#define FUNCTOR_TEMPLATE115 template <class T, class R, class P1, class P2, class P3, class P4, class P5>
+#define FUNCTOR_TEMPLATE(ismember, returnvalue, numparams, additionalobject) FUNCTOR_TEMPLATE##ismember##returnvalue##numparams(additionalobject)
+#define FUNCTOR_TEMPLATE000(additionalobject)
+#define FUNCTOR_TEMPLATE001(additionalobject) template <class P1>
+#define FUNCTOR_TEMPLATE002(additionalobject) template <class P1, class P2>
+#define FUNCTOR_TEMPLATE003(additionalobject) template <class P1, class P2, class P3>
+#define FUNCTOR_TEMPLATE004(additionalobject) template <class P1, class P2, class P3, class P4>
+#define FUNCTOR_TEMPLATE005(additionalobject) template <class P1, class P2, class P3, class P4, class P5>
+#define FUNCTOR_TEMPLATE010(additionalobject) template <class R>
+#define FUNCTOR_TEMPLATE011(additionalobject) template <class R, class P1>
+#define FUNCTOR_TEMPLATE012(additionalobject) template <class R, class P1, class P2>
+#define FUNCTOR_TEMPLATE013(additionalobject) template <class R, class P1, class P2, class P3>
+#define FUNCTOR_TEMPLATE014(additionalobject) template <class R, class P1, class P2, class P3, class P4>
+#define FUNCTOR_TEMPLATE015(additionalobject) template <class R, class P1, class P2, class P3, class P4, class P5>
+#define FUNCTOR_TEMPLATE100(additionalobject) template <class T FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
+#define FUNCTOR_TEMPLATE101(additionalobject) template <class T, class P1 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
+#define FUNCTOR_TEMPLATE102(additionalobject) template <class T, class P1, class P2 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
+#define FUNCTOR_TEMPLATE103(additionalobject) template <class T, class P1, class P2, class P3 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
+#define FUNCTOR_TEMPLATE104(additionalobject) template <class T, class P1, class P2, class P3, class P4 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
+#define FUNCTOR_TEMPLATE105(additionalobject) template <class T, class P1, class P2, class P3, class P4, class P5 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
+#define FUNCTOR_TEMPLATE110(additionalobject) template <class T, class R FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
+#define FUNCTOR_TEMPLATE111(additionalobject) template <class T, class R, class P1 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
+#define FUNCTOR_TEMPLATE112(additionalobject) template <class T, class R, class P1, class P2 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
+#define FUNCTOR_TEMPLATE113(additionalobject) template <class T, class R, class P1, class P2, class P3 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
+#define FUNCTOR_TEMPLATE114(additionalobject) template <class T, class R, class P1, class P2, class P3, class P4 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
+#define FUNCTOR_TEMPLATE115(additionalobject) template <class T, class R, class P1, class P2, class P3, class P4, class P5 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
+#define FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT##additionalobject
+#define FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT0
+#define FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT1 , class O
+
+
+
#define FUNCTOR_TEMPLATE_CLASSES(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE_CLASSES##ismember##returnvalue##numparams
#define FUNCTOR_TEMPLATE_CLASSES000
#define FUNCTOR_TEMPLATE_CLASSES001 <P1>
@@ -316,7 +322,7 @@
#define CREATE_STATIC_FUNCTOR(returnvalue, numparams) \
- FUNCTOR_TEMPLATE(0, returnvalue, numparams) \
+ FUNCTOR_TEMPLATE(0, returnvalue, numparams, 0) \
class FunctorStatic##returnvalue##numparams : public FunctorStatic \
{ \
public: \
@@ -346,7 +352,7 @@
}; \
\
\
- FUNCTOR_TEMPLATE(0, returnvalue, numparams) \
+ FUNCTOR_TEMPLATE(0, returnvalue, numparams, 0) \
inline FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
{ \
return new FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams) (functionPointer); \
@@ -357,7 +363,7 @@
#define CREATE_MEMBER_FUNCTOR(returnvalue, numparams) \
- FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
+ FUNCTOR_TEMPLATE(1, returnvalue, numparams, 0) \
class FunctorMember##returnvalue##numparams : public FunctorMember<T> \
{ \
public: \
@@ -390,7 +396,7 @@
}; \
\
\
- FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
+ FUNCTOR_TEMPLATE(1, returnvalue, numparams, 0) \
class FunctorConstMember##returnvalue##numparams : public FunctorMember<T> \
{ \
public: \
@@ -422,17 +428,34 @@
}; \
\
\
- FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
+ FUNCTOR_TEMPLATE(1, returnvalue, numparams, 0) \
inline FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
{ \
return new FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
} \
\
\
- FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
+ FUNCTOR_TEMPLATE(1, returnvalue, numparams, 0) \
inline FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \
{ \
return new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
+ } \
+ \
+ FUNCTOR_TEMPLATE(1, returnvalue, numparams, 1) \
+ inline FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)), O* object) \
+ { \
+ FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* functor = new FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
+ functor->setObject(object); \
+ return functor; \
+ } \
+ \
+ \
+ FUNCTOR_TEMPLATE(1, returnvalue, numparams, 1) \
+ inline FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const, O* object) \
+ { \
+ FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* functor = new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
+ functor->setObject(object); \
+ return functor; \
}
Modified: sandbox/src/libraries/core/Game.cc
===================================================================
--- sandbox/src/libraries/core/Game.cc 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/Game.cc 2009-11-05 20:22:22 UTC (rev 6038)
@@ -37,13 +37,13 @@
#include <exception>
#include <boost/weak_ptr.hpp>
+#include "util/Clock.h"
#include "util/Debug.h"
#include "util/Exception.h"
#include "util/ScopeGuard.h"
#include "util/Sleep.h"
#include "util/SubString.h"
-#include "Clock.h"
-#include "CommandLine.h"
+#include "CommandLineParser.h"
#include "Core.h"
#include "CoreIncludes.h"
#include "ConfigValueIncludes.h"
@@ -104,7 +104,7 @@
*/
Game::Game(const std::string& cmdLine)
// Destroy factories before the Core!
- : gsFactoryDestroyer_(Game::GameStateFactory::factories_s, &std::map<std::string, shared_ptr<GameStateFactory> >::clear)
+ : gsFactoryDestroyer_(Game::GameStateFactory::getFactories(), &std::map<std::string, shared_ptr<GameStateFactory> >::clear)
{
this->bAbort_ = false;
bChangingState_ = false;
@@ -403,6 +403,8 @@
currentNode = currentNode->parent_.lock();
requestedNodes.push_back(currentNode);
}
+ if (currentNode == NULL)
+ requestedNodes.clear();
}
if (requestedNodes.empty())
@@ -450,12 +452,12 @@
void Game::setStateHierarchy(const std::string& str)
{
// Split string into pieces of the form whitespacesText
- std::vector<std::pair<std::string, unsigned> > stateStrings;
+ std::vector<std::pair<std::string, int> > stateStrings;
size_t pos = 0;
size_t startPos = 0;
while (pos < str.size())
{
- unsigned indentation = 0;
+ int indentation = 0;
while(pos < str.size() && str[pos] == ' ')
++indentation, ++pos;
startPos = pos;
@@ -463,40 +465,49 @@
++pos;
stateStrings.push_back(std::make_pair(str.substr(startPos, pos - startPos), indentation));
}
- unsigned int currentLevel = 0;
- shared_ptr<GameStateTreeNode> currentNode = this->rootStateNode_;
- for (std::vector<std::pair<std::string, unsigned> >::const_iterator it = stateStrings.begin(); it != stateStrings.end(); ++it)
+ if (stateStrings.empty())
+ ThrowException(GameState, "Emtpy GameState hierarchy provided, terminating.");
+ // Add element with large identation to detect the last with just an iterator
+ stateStrings.push_back(std::make_pair("", -1));
+
+ // Parse elements recursively
+ std::vector<std::pair<std::string, int> >::const_iterator begin = stateStrings.begin();
+ parseStates(begin, this->rootStateNode_);
+ }
+
+ /*** Internal ***/
+
+ void Game::parseStates(std::vector<std::pair<std::string, int> >::const_iterator& it, shared_ptr<GameStateTreeNode> currentNode)
{
- std::string newStateName = it->first;
- unsigned newLevel = it->second + 1; // empty root is 0
- if (!this->checkState(newStateName))
- ThrowException(GameState, "GameState with name '" << newStateName << "' not found!");
- if (newStateName == this->rootStateNode_->name_)
+ SubString tokens(it->first, ",");
+ std::vector<std::pair<std::string, int> >::const_iterator startIt = it;
+
+ for (unsigned int i = 0; i < tokens.size(); ++i)
+ {
+ it = startIt; // Reset iterator to the beginning of the sub tree
+ if (!this->checkState(tokens[i]))
+ ThrowException(GameState, "GameState with name '" << tokens[i] << "' not found!");
+ if (tokens[i] == this->rootStateNode_->name_)
ThrowException(GameState, "You shouldn't use 'emptyRootGameState' in the hierarchy...");
- shared_ptr<GameStateTreeNode> newNode(new GameStateTreeNode);
- newNode->name_ = newStateName;
+ shared_ptr<GameStateTreeNode> node(new GameStateTreeNode());
+ node->name_ = tokens[i];
+ node->parent_ = currentNode;
+ currentNode->children_.push_back(node);
- if (newLevel <= currentLevel)
+ int currentLevel = it->second;
+ ++it;
+ while (it->second != -1)
{
- do
- currentNode = currentNode->parent_.lock();
- while (newLevel <= --currentLevel);
- }
- if (newLevel == currentLevel + 1)
- {
- // Add the child
- newNode->parent_ = currentNode;
- currentNode->children_.push_back(newNode);
- }
+ if (it->second <= currentLevel)
+ break;
+ else if (it->second == currentLevel + 1)
+ parseStates(it, node);
else
ThrowException(GameState, "Indentation error while parsing the hierarchy.");
- currentNode = newNode;
- currentLevel = newLevel;
}
}
+ }
- /*** Internal ***/
-
void Game::loadGraphics()
{
}
@@ -565,12 +576,16 @@
this->bChangingState_ = false;
}
- std::map<std::string, shared_ptr<Game::GameStateFactory> > Game::GameStateFactory::factories_s;
+ /*static*/ std::map<std::string, shared_ptr<Game::GameStateFactory> >& Game::GameStateFactory::getFactories()
+ {
+ static std::map<std::string, shared_ptr<GameStateFactory> > factories;
+ return factories;
+ }
/*static*/ shared_ptr<GameState> Game::GameStateFactory::fabricate(const GameStateInfo& info)
{
- std::map<std::string, shared_ptr<Game::GameStateFactory> >::const_iterator it = factories_s.find(info.className);
- assert(it != factories_s.end());
+ std::map<std::string, shared_ptr<Game::GameStateFactory> >::const_iterator it = getFactories().find(info.className);
+ assert(it != getFactories().end());
return it->second->fabricateInternal(info);
}
}
Modified: sandbox/src/libraries/core/Game.h
===================================================================
--- sandbox/src/libraries/core/Game.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/Game.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -116,10 +116,10 @@
static shared_ptr<GameState> fabricate(const GameStateInfo& info);
template <class T>
static void createFactory(const std::string& className)
- { factories_s[className].reset(new TemplateGameStateFactory<T>()); }
+ { getFactories()[className].reset(new TemplateGameStateFactory<T>()); }
virtual shared_ptr<GameState> fabricateInternal(const GameStateInfo& info) = 0;
- static std::map<std::string, shared_ptr<GameStateFactory> > factories_s;
+ static std::map<std::string, shared_ptr<GameStateFactory> >& getFactories();
};
template <class T>
class TemplateGameStateFactory : public GameStateFactory
@@ -142,6 +142,7 @@
void loadGraphics();
void unloadGraphics();
+ void parseStates(std::vector<std::pair<std::string, int> >::const_iterator& it, shared_ptr<GameStateTreeNode> currentNode);
bool checkState(const std::string& name) const;
void loadState(const std::string& name);
void unloadState(const std::string& name);
Modified: sandbox/src/libraries/core/GameState.h
===================================================================
--- sandbox/src/libraries/core/GameState.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/GameState.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -39,6 +39,7 @@
#include <map>
#include <string>
+#include "util/UtilPrereqs.h"
namespace orxonox
{
Modified: sandbox/src/libraries/core/Identifier.cc
===================================================================
--- sandbox/src/libraries/core/Identifier.cc 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/Identifier.cc 2009-11-05 20:22:22 UTC (rev 6038)
@@ -36,8 +36,9 @@
#include <ostream>
#include "util/StringUtils.h"
+#include "BaseObject.h"
#include "ConfigValueContainer.h"
-#include "Factory.h"
+#include "ClassFactory.h"
namespace orxonox
{
@@ -61,8 +62,6 @@
this->bHasConfigValues_ = false;
- this->children_ = new std::set<const Identifier*>();
- this->directChildren_ = new std::set<const Identifier*>();
}
/**
@@ -70,8 +69,6 @@
*/
Identifier::~Identifier()
{
- delete this->children_;
- delete this->directChildren_;
delete this->objects_;
if (this->factory_)
@@ -104,7 +101,7 @@
{
// There is already an entry: return it and delete the proposal
delete proposal;
- return (*it).second;
+ return it->second;
}
else
{
@@ -151,7 +148,7 @@
for (std::set<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it)
{
// Tell the parent we're one of it's children
- (*it)->getChildrenIntern().insert((*it)->getChildrenIntern().end(), this);
+ (*it)->children_.insert((*it)->children_.end(), this);
// Erase all parents of our parent from our direct-parent-list
for (std::set<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1)
@@ -173,12 +170,32 @@
for (std::set<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
{
// Tell the parent we're one of it's direct children
- (*it)->getDirectChildrenIntern().insert((*it)->getDirectChildrenIntern().end(), this);
+ (*it)->directChildren_.insert((*it)->directChildren_.end(), this);
}
}
}
/**
+ @brief Creates the class-hierarchy by creating and destroying one object of each type.
+ */
+ void Identifier::createClassHierarchy()
+ {
+ COUT(3) << "*** Identifier: Create class-hierarchy" << std::endl;
+ Identifier::startCreatingHierarchy();
+ for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMap().begin(); it != Identifier::getStringIdentifierMap().end(); ++it)
+ {
+ // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
+ if (it->second->hasFactory())
+ {
+ BaseObject* temp = it->second->fabricate(0);
+ delete temp;
+ }
+ }
+ Identifier::stopCreatingHierarchy();
+ COUT(3) << "*** Identifier: Finished class-hierarchy creation" << std::endl;
+ }
+
+ /**
@brief Destroys all Identifiers. Called when exiting the program.
*/
void Identifier::destroyAllIdentifiers()
@@ -197,8 +214,8 @@
{
this->name_ = name;
this->bSetName_ = true;
- Identifier::getIdentifierMapIntern()[name] = this;
- Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this;
+ Identifier::getStringIdentifierMapIntern()[name] = this;
+ Identifier::getLowercaseStringIdentifierMapIntern()[getLowercase(name)] = this;
}
}
@@ -218,7 +235,7 @@
COUT(1) << "Error: Cannot fabricate an object of type '" << this->name_ << "'. Class has no factory." << std::endl;
COUT(1) << "Aborting..." << std::endl;
abort();
- return NULL;
+ return 0;
}
}
@@ -264,7 +281,7 @@
*/
bool Identifier::isParentOf(const Identifier* identifier) const
{
- return (this->children_->find(identifier) != this->children_->end());
+ return (this->children_.find(identifier) != this->children_.end());
}
/**
@@ -273,30 +290,68 @@
*/
bool Identifier::isDirectParentOf(const Identifier* identifier) const
{
- return (this->directChildren_->find(identifier) != this->directChildren_->end());
+ return (this->directChildren_.find(identifier) != this->directChildren_.end());
}
/**
- @brief Returns the map that stores all Identifiers.
+ @brief Returns the map that stores all Identifiers with their names.
@return The map
*/
- std::map<std::string, Identifier*>& Identifier::getIdentifierMapIntern()
+ std::map<std::string, Identifier*>& Identifier::getStringIdentifierMapIntern()
{
static std::map<std::string, Identifier*> identifierMap;
return identifierMap;
}
/**
- @brief Returns the map that stores all Identifiers.
+ @brief Returns the map that stores all Identifiers with their names in lowercase.
@return The map
*/
- std::map<std::string, Identifier*>& Identifier::getLowercaseIdentifierMapIntern()
+ std::map<std::string, Identifier*>& Identifier::getLowercaseStringIdentifierMapIntern()
{
static std::map<std::string, Identifier*> lowercaseIdentifierMap;
return lowercaseIdentifierMap;
}
/**
+ @brief Returns the map that stores all Identifiers with their network IDs.
+ @return The map
+ */
+ std::map<uint32_t, Identifier*>& Identifier::getIDIdentifierMapIntern()
+ {
+ static std::map<uint32_t, Identifier*> identifierMap;
+ return identifierMap;
+ }
+
+ /**
+ @brief Returns the Identifier with a given name.
+ @param name The name of the wanted Identifier
+ @return The Identifier
+ */
+ Identifier* Identifier::getIdentifierByString(const std::string& name)
+ {
+ std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapIntern().find(name);
+ if (it != Identifier::getStringIdentifierMapIntern().end())
+ return it->second;
+ else
+ return 0;
+ }
+
+ /**
+ @brief Returns the Identifier with a given name in lowercase.
+ @param name The name of the wanted Identifier
+ @return The Identifier
+ */
+ Identifier* Identifier::getIdentifierByLowercaseString(const std::string& name)
+ {
+ std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseStringIdentifierMapIntern().find(name);
+ if (it != Identifier::getLowercaseStringIdentifierMapIntern().end())
+ return it->second;
+ else
+ return 0;
+ }
+
+ /**
@brief Adds the ConfigValueContainer of a variable, given by the string of its name.
@param varname The name of the variablee
@param container The container
@@ -324,7 +379,7 @@
{
std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_.find(varname);
if (it != configValues_.end())
- return ((*it).second);
+ return it->second;
else
return 0;
}
@@ -338,7 +393,7 @@
{
std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_LC_.find(varname);
if (it != configValues_LC_.end())
- return ((*it).second);
+ return it->second;
else
return 0;
}
@@ -352,7 +407,11 @@
std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list)
{
for (std::set<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it)
- out << (*it)->getName() << " ";
+ {
+ if (it != list.begin())
+ out << " ";
+ out << (*it)->getName();
+ }
return out;
}
Modified: sandbox/src/libraries/core/Identifier.h
===================================================================
--- sandbox/src/libraries/core/Identifier.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/Identifier.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -28,7 +28,7 @@
/**
@file
- @brief Definition of the Identifier, ClassIdentifier and SubclassIdentifier classes, implementation of the ClassIdentifier and SubclassIdentifier classes.
+ @brief Definition of the Identifier class, definition and implementation of the ClassIdentifier class.
The Identifier contains all needed information about the class it belongs to:
- the name
@@ -44,9 +44,6 @@
To create the class-hierarchy, the Identifier has some intern functions and variables.
Every Identifier is in fact a ClassIdentifier, but they are derived from Identifier.
-
- SubclassIdentifier is a separated class, acting like an Identifier, but has a given class.
- You can only assign Identifiers of exactly the given class or of a derivative to a SubclassIdentifier.
*/
#ifndef _Identifier_H__
@@ -88,16 +85,24 @@
*/
class _CoreExport Identifier
{
- template <class T>
- friend class SubclassIdentifier;
+ public:
+ /** @brief Returns the name of the class the Identifier belongs to. @return The name */
+ inline const std::string& getName() const { return this->name_; }
+ void setName(const std::string& name);
- friend class Factory;
+ /** @brief Returns the unique ID of the class */
+ FORCEINLINE unsigned int getClassID() const { return this->classID_; }
- public:
+ /** @brief Returns the list of all existing objects of this class. @return The list */
+ inline ObjectListBase* getObjects() const { return this->objects_; }
+
/** @brief Sets the Factory. @param factory The factory to assign */
- inline void addFactory(BaseFactory* factory) { this->factory_ = factory; }
+ inline void addFactory(Factory* factory) { this->factory_ = factory; }
+ /** @brief Returns true if the Identifier has a Factory. */
+ inline bool hasFactory() const { return (this->factory_ != 0); }
BaseObject* fabricate(BaseObject* creator);
+
bool isA(const Identifier* identifier) const;
bool isExactlyA(const Identifier* identifier) const;
bool isChildOf(const Identifier* identifier) const;
@@ -105,15 +110,14 @@
bool isParentOf(const Identifier* identifier) const;
bool isDirectParentOf(const Identifier* identifier) const;
- /** @brief Returns the list of all existing objects of this class. @return The list */
- inline ObjectListBase* getObjects() const
- { return this->objects_; }
- /** @brief Returns the name of the class the Identifier belongs to. @return The name */
- inline const std::string& getName() const { return this->name_; }
- void setName(const std::string& name);
+ /////////////////////////////
+ ////// Class Hierarchy //////
+ /////////////////////////////
+ static void createClassHierarchy();
- virtual void updateConfigValues(bool updateChildren = true) const = 0;
+ /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */
+ inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }
/** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */
inline const std::set<const Identifier*>& getParents() const { return this->parents_; }
@@ -123,11 +127,11 @@
inline std::set<const Identifier*>::const_iterator getParentsEnd() const { return this->parents_.end(); }
/** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
- inline const std::set<const Identifier*>& getChildren() const { return (*this->children_); }
+ inline const std::set<const Identifier*>& getChildren() const { return this->children_; }
/** @brief Returns the begin-iterator of the children-list. @return The begin-iterator */
- inline std::set<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_->begin(); }
+ inline std::set<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_.begin(); }
/** @brief Returns the end-iterator of the children-list. @return The end-iterator */
- inline std::set<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_->end(); }
+ inline std::set<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_.end(); }
/** @brief Returns the direct parents of the class the Identifier belongs to. @return The list of all direct parents */
inline const std::set<const Identifier*>& getDirectParents() const { return this->directParents_; }
@@ -137,28 +141,54 @@
inline std::set<const Identifier*>::const_iterator getDirectParentsEnd() const { return this->directParents_.end(); }
/** @brief Returns the direct children the class the Identifier belongs to. @return The list of all direct children */
- inline const std::set<const Identifier*>& getDirectChildren() const { return (*this->directChildren_); }
+ inline const std::set<const Identifier*>& getDirectChildren() const { return this->directChildren_; }
/** @brief Returns the begin-iterator of the direct-children-list. @return The begin-iterator */
- inline std::set<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_->begin(); }
+ inline std::set<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_.begin(); }
/** @brief Returns the end-iterator of the direct-children-list. @return The end-iterator */
- inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_->end(); }
+ inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_.end(); }
- /** @brief Returns the map that stores all Identifiers. @return The map */
- static inline const std::map<std::string, Identifier*>& getIdentifierMap() { return Identifier::getIdentifierMapIntern(); }
- /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers. @return The const_iterator */
- static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapBegin() { return Identifier::getIdentifierMap().begin(); }
- /** @brief Returns a const_iterator to the end of the map that stores all Identifiers. @return The const_iterator */
- static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapEnd() { return Identifier::getIdentifierMap().end(); }
+ //////////////////////////
+ ///// Identifier Map /////
+ //////////////////////////
+ static void destroyAllIdentifiers();
+ static Identifier* getIdentifierByString(const std::string& name);
+ static Identifier* getIdentifierByLowercaseString(const std::string& name);
+ static Identifier* getIdentifierByID(uint32_t id);
+
+ static void clearNetworkIDs();
+
+ /** @brief Returns the map that stores all Identifiers with their names. @return The map */
+ static inline const std::map<std::string, Identifier*>& getStringIdentifierMap() { return Identifier::getStringIdentifierMapIntern(); }
+ /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their names. @return The const_iterator */
+ static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapBegin() { return Identifier::getStringIdentifierMap().begin(); }
+ /** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their names. @return The const_iterator */
+ static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapEnd() { return Identifier::getStringIdentifierMap().end(); }
+
/** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */
- static inline const std::map<std::string, Identifier*>& getLowercaseIdentifierMap() { return Identifier::getLowercaseIdentifierMapIntern(); }
+ static inline const std::map<std::string, Identifier*>& getLowercaseStringIdentifierMap() { return Identifier::getLowercaseStringIdentifierMapIntern(); }
/** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */
- static inline std::map<std::string, Identifier*>::const_iterator getLowercaseIdentifierMapBegin() { return Identifier::getLowercaseIdentifierMap().begin(); }
+ static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapBegin() { return Identifier::getLowercaseStringIdentifierMap().begin(); }
/** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */
- static inline std::map<std::string, Identifier*>::const_iterator getLowercaseIdentifierMapEnd() { return Identifier::getLowercaseIdentifierMap().end(); }
+ static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapEnd() { return Identifier::getLowercaseStringIdentifierMap().end(); }
+ /** @brief Returns the map that stores all Identifiers with their IDs. @return The map */
+ static inline const std::map<uint32_t, Identifier*>& getIDIdentifierMap() { return Identifier::getIDIdentifierMapIntern(); }
+ /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their IDs. @return The const_iterator */
+ static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapBegin() { return Identifier::getIDIdentifierMap().begin(); }
+ /** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their IDs. @return The const_iterator */
+ static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapEnd() { return Identifier::getIDIdentifierMap().end(); }
+
+ /////////////////////////
+ ///// Config Values /////
+ /////////////////////////
+ virtual void updateConfigValues(bool updateChildren = true) const = 0;
+
+ /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */
+ inline bool hasConfigValues() const { return this->bHasConfigValues_; }
+
/** @brief Returns the map that stores all config values. @return The const_iterator */
inline const std::map<std::string, ConfigValueContainer*>& getConfigValueMap() const { return this->configValues_; }
/** @brief Returns a const_iterator to the beginning of the map that stores all config values. @return The const_iterator */
@@ -173,24 +203,11 @@
/** @brief Returns a const_iterator to the end of the map that stores all config values with their names in lowercase. @return The const_iterator */
inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapEnd() const { return this->configValues_LC_.end(); }
-
- /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */
- inline bool hasConfigValues() const { return this->bHasConfigValues_; }
-
- /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */
- inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }
-
- /** @brief Returns the unique ID of the class */
- FORCEINLINE unsigned int getClassID() const { return this->classID_; }
-
void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container);
ConfigValueContainer* getConfigValueContainer(const std::string& varname);
ConfigValueContainer* getLowercaseConfigValueContainer(const std::string& varname);
- void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
- static void destroyAllIdentifiers();
-
protected:
Identifier();
Identifier(const Identifier& identifier); // don't copy
@@ -198,51 +215,42 @@
static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal);
- /** @brief Returns the map that stores all Identifiers. @return The map */
- static std::map<std::string, Identifier*>& getIdentifierMapIntern();
+ void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
+
+ /** @brief Returns the map that stores all Identifiers with their names. @return The map */
+ static std::map<std::string, Identifier*>& getStringIdentifierMapIntern();
/** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */
- static std::map<std::string, Identifier*>& getLowercaseIdentifierMapIntern();
+ static std::map<std::string, Identifier*>& getLowercaseStringIdentifierMapIntern();
+ /** @brief Returns the map that stores all Identifiers with their network IDs. @return The map */
+ static std::map<uint32_t, Identifier*>& getIDIdentifierMapIntern();
/** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
- inline std::set<const Identifier*>& getChildrenIntern() const { return (*this->children_); }
+ inline std::set<const Identifier*>& getChildrenIntern() const { return this->children_; }
/** @brief Returns the direct children of the class the Identifier belongs to. @return The list of all direct children */
- inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }
+ inline std::set<const Identifier*>& getDirectChildrenIntern() const { return this->directChildren_; }
ObjectListBase* objects_; //!< The list of all objects of this class
private:
- /**
- @brief Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents.
- */
- inline static void startCreatingHierarchy()
- {
- hierarchyCreatingCounter_s++;
- COUT(4) << "*** Identifier: Increased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl;
- }
+ /** @brief Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents. */
+ inline static void startCreatingHierarchy() { hierarchyCreatingCounter_s++; }
+ /** @brief Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents. */
+ inline static void stopCreatingHierarchy() { hierarchyCreatingCounter_s--; }
- /**
- @brief Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents.
- */
- inline static void stopCreatingHierarchy()
- {
- hierarchyCreatingCounter_s--;
- COUT(4) << "*** Identifier: Decreased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl;
- }
-
static std::map<std::string, Identifier*>& getTypeIDIdentifierMap();
void initialize(std::set<const Identifier*>* parents);
std::set<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to
- std::set<const Identifier*>* children_; //!< The children of the class the Identifier belongs to
+ mutable std::set<const Identifier*> children_; //!< The children of the class the Identifier belongs to
std::set<const Identifier*> directParents_; //!< The direct parents of the class the Identifier belongs to
- std::set<const Identifier*>* directChildren_; //!< The direct children of the class the Identifier belongs to
+ mutable std::set<const Identifier*> directChildren_; //!< The direct children of the class the Identifier belongs to
bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
bool bSetName_; //!< True if the name is set
std::string name_; //!< The name of the class the Identifier belongs to
- BaseFactory* factory_; //!< The Factory, able to create new objects of the given class (if available)
+ Factory* factory_; //!< The Factory, able to create new objects of the given class (if available)
static int hierarchyCreatingCounter_s; //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading)
const unsigned int classID_; //!< Uniquely identifies a class (might not be the same as the networkID_)
static unsigned int classIDCounter_s; //!< Static counter for the unique classIDs
@@ -301,8 +309,8 @@
template <class T>
inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
{
- // check if the static field has already been filled
- if (ClassIdentifier<T>::classIdentifier_s == 0)
+ // check if the Identifier already exists
+ if (!ClassIdentifier<T>::classIdentifier_s)
ClassIdentifier<T>::initialiseIdentifier();
return ClassIdentifier<T>::classIdentifier_s;
@@ -429,131 +437,6 @@
return dynamic_cast<T>(source);
#endif
}
-
-
- // ###############################
- // ### SubclassIdentifier ###
- // ###############################
- //! The SubclassIdentifier acts almost like an Identifier, but has some prerequisites.
- /**
- You can only assign an Identifier that belongs to a class T (or derived) to a SubclassIdentifier<T>.
- If you assign something else, the program aborts.
- Because we know the minimum type, a dynamic_cast is done, which makes it easier to create a new object.
- */
- template <class T>
- class SubclassIdentifier
- {
- public:
- /**
- @brief Constructor: Automaticaly assigns the Identifier of the given class.
- */
- SubclassIdentifier()
- {
- this->identifier_ = ClassIdentifier<T>::getIdentifier();
- }
-
- /**
- @brief Copyconstructor: Assigns the given Identifier.
- @param identifier The Identifier
- */
- SubclassIdentifier(Identifier* identifier)
- {
- this->operator=(identifier);
- }
-
- /**
- @brief Overloading of the = operator: assigns the identifier and checks its type.
- @param identifier The Identifier to assign
- @return The SubclassIdentifier itself
- */
- SubclassIdentifier<T>& operator=(Identifier* identifier)
- {
- if (!identifier || !identifier->isA(ClassIdentifier<T>::getIdentifier()))
- {
- COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
- if (identifier)
- {
- COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
- COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl;
- }
- else
- {
- COUT(1) << "Error: Can't assign NULL identifier" << std::endl;
- }
- }
- else
- {
- this->identifier_ = identifier;
- }
- return *this;
- }
-
- /**
- @brief Overloading of the * operator: returns the assigned identifier.
- */
- inline Identifier* operator*() const
- {
- return this->identifier_;
- }
-
- /**
- @brief Overloading of the -> operator: returns the assigned identifier.
- */
- inline Identifier* operator->() const
- {
- return this->identifier_;
- }
-
- /**
- @brief Returns the assigned identifier. This allows you to assign a SubclassIdentifier to a normal Identifier*.
- */
- inline operator Identifier*() const
- {
- return this->identifier_;
- }
-
- /**
- @brief Creates a new object of the type of the assigned Identifier and dynamic_casts it to the minimal type given by T.
- @return The new object
- */
- T* fabricate(BaseObject* creator) const
- {
- BaseObject* newObject = this->identifier_->fabricate(creator);
-
- // Check if the creation was successful
- if (newObject)
- {
- return orxonox_cast<T*>(newObject);
- }
- else
- {
- // Something went terribly wrong
- if (this->identifier_)
- {
- COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
- COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
- COUT(1) << "Error: Couldn't fabricate a new Object." << std::endl;
- COUT(1) << "Aborting..." << std::endl;
- }
- else
- {
- COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
- COUT(1) << "Error: Couldn't fabricate a new Object - Identifier is undefined." << std::endl;
- COUT(1) << "Aborting..." << std::endl;
- }
-
- assert(false);
- return 0;
- }
- }
-
- /** @brief Returns the assigned identifier. @return The identifier */
- inline Identifier* getIdentifier() const
- { return this->identifier_; }
-
- private:
- Identifier* identifier_; //!< The assigned identifier
- };
}
#endif /* _Identifier_H__ */
Modified: sandbox/src/libraries/core/Iterator.h
===================================================================
--- sandbox/src/libraries/core/Iterator.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/Iterator.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -166,7 +166,6 @@
this->list_->registerIterator(this);
return (*this);
- return *this;
}
/**
@@ -192,8 +191,7 @@
*/
inline const Iterator<T>& operator++()
{
- if (this->element_)
- this->element_ = this->element_->next_;
+ this->element_ = this->element_->next_;
return *this;
}
@@ -204,8 +202,7 @@
inline Iterator<T> operator++(int i)
{
Iterator<T> copy = *this;
- if (this->element_)
- this->element_ = this->element_->next_;
+ this->element_ = this->element_->next_;
return copy;
}
@@ -215,8 +212,7 @@
*/
inline const Iterator<T>& operator--()
{
- if (this->element_)
- this->element_ = this->element_->prev_;
+ this->element_ = this->element_->prev_;
return *this;
}
@@ -227,8 +223,7 @@
inline Iterator<T> operator--(int i)
{
Iterator<T> copy = *this;
- if (this->element_)
- this->element_ = this->element_->prev_;
+ this->element_ = this->element_->prev_;
return copy;
}
@@ -238,10 +233,7 @@
*/
inline T* operator*() const
{
- if (this->element_)
- return orxonox_cast<T*>(this->element_->objectBase_);
- else
- return 0;
+ return orxonox_cast<T*>(this->element_->objectBase_);
}
/**
@@ -250,10 +242,7 @@
*/
inline T* operator->() const
{
- if (this->element_)
- return orxonox_cast<T*>(this->element_->objectBase_);
- else
- return 0;
+ return orxonox_cast<T*>(this->element_->objectBase_);
}
/**
Modified: sandbox/src/libraries/core/Language.cc
===================================================================
--- sandbox/src/libraries/core/Language.cc 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/Language.cc 2009-11-05 20:22:22 UTC (rev 6038)
@@ -34,10 +34,9 @@
#include "Language.h"
#include <fstream>
-#include <boost/filesystem.hpp>
-
#include "util/Debug.h"
#include "Core.h"
+#include "PathConfig.h"
namespace orxonox
{
@@ -199,16 +198,16 @@
{
COUT(4) << "Read default language file." << std::endl;
- boost::filesystem::path filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_));
+ std::string filepath = PathConfig::getConfigPathString() + getFilename(this->defaultLanguage_);
// This creates the file if it's not existing
std::ofstream createFile;
- createFile.open(filepath.string().c_str(), std::fstream::app);
+ createFile.open(filepath.c_str(), std::fstream::app);
createFile.close();
// Open the file
std::ifstream file;
- file.open(filepath.string().c_str(), std::fstream::in);
+ file.open(filepath.c_str(), std::fstream::in);
if (!file.is_open())
{
@@ -248,11 +247,11 @@
{
COUT(4) << "Read translated language file (" << Core::getLanguage() << ")." << std::endl;
- boost::filesystem::path filepath(Core::getConfigPath() / getFilename(Core::getLanguage()));
+ std::string filepath = PathConfig::getConfigPathString() + getFilename(Core::getLanguage());
// Open the file
std::ifstream file;
- file.open(filepath.string().c_str(), std::fstream::in);
+ file.open(filepath.c_str(), std::fstream::in);
if (!file.is_open())
{
@@ -302,11 +301,11 @@
{
COUT(4) << "Language: Write default language file." << std::endl;
- boost::filesystem::path filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_));
+ std::string filepath = PathConfig::getConfigPathString() + getFilename(this->defaultLanguage_);
// Open the file
std::ofstream file;
- file.open(filepath.string().c_str(), std::fstream::out);
+ file.open(filepath.c_str(), std::fstream::out);
if (!file.is_open())
{
Modified: sandbox/src/libraries/core/LuaState.cc
===================================================================
--- sandbox/src/libraries/core/LuaState.cc 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/LuaState.cc 2009-11-05 20:22:22 UTC (rev 6038)
@@ -37,7 +37,7 @@
}
#include "util/Debug.h"
-#include "Core.h"
+#include "PathConfig.h"
#include "ToluaBindCore.h"
namespace orxonox
@@ -105,7 +105,7 @@
shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename)
{
- boost::filesystem::path filepath = Core::getDataPath() / "lua" / filename;
+ boost::filesystem::path filepath = PathConfig::getDataPath() / "lua" / filename;
if (boost::filesystem::exists(filepath))
{
shared_ptr<ResourceInfo> info(new ResourceInfo());
Modified: sandbox/src/libraries/core/ObjectListIterator.h
===================================================================
--- sandbox/src/libraries/core/ObjectListIterator.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/ObjectListIterator.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -122,8 +122,7 @@
*/
inline const ObjectListIterator<T>& operator++()
{
- if (this->element_)
- this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
+ this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
return *this;
}
@@ -134,8 +133,7 @@
inline ObjectListIterator<T> operator++(int i)
{
ObjectListIterator<T> copy = *this;
- if (this->element_)
- this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
+ this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
return copy;
}
@@ -145,8 +143,7 @@
*/
inline const ObjectListIterator<T>& operator--()
{
- if (this->element_)
- this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
+ this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
return *this;
}
@@ -157,8 +154,7 @@
inline ObjectListIterator<T> operator--(int i)
{
ObjectListIterator<T> copy = *this;
- if (this->element_)
- this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
+ this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
return copy;
}
@@ -168,10 +164,7 @@
*/
inline T* operator*() const
{
- if (this->element_)
- return this->element_->object_;
- else
- return 0;
+ return this->element_->object_;
}
/**
@@ -180,10 +173,7 @@
*/
inline T* operator->() const
{
- if (this->element_)
- return this->element_->object_;
- else
- return 0;
+ return this->element_->object_;
}
/**
Modified: sandbox/src/libraries/core/OrxonoxClass.cc
===================================================================
--- sandbox/src/libraries/core/OrxonoxClass.cc 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/OrxonoxClass.cc 2009-11-05 20:22:22 UTC (rev 6038)
@@ -77,46 +77,6 @@
/** @brief Returns true if the objects class is of the given type or a derivative. */
- template <class B> bool OrxonoxClass::isA(const SubclassIdentifier<B>* identifier)
- { return this->getIdentifier()->isA(identifier->getIdentifier()); }
- /** @brief Returns true if the objects class is exactly of the given type. */
- template <class B> bool OrxonoxClass::isExactlyA(const SubclassIdentifier<B>* identifier)
- { return this->getIdentifier()->isExactlyA(identifier->getIdentifier()); }
- /** @brief Returns true if the objects class is a child of the given type. */
- template <class B> bool OrxonoxClass::isChildOf(const SubclassIdentifier<B>* identifier)
- { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); }
- /** @brief Returns true if the objects class is a direct child of the given type. */
- template <class B> bool OrxonoxClass::isDirectChildOf(const SubclassIdentifier<B>* identifier)
- { return this->getIdentifier()->isDirectChildOf(identifier->getIdentifier()); }
- /** @brief Returns true if the objects class is a parent of the given type. */
- template <class B> bool OrxonoxClass::isParentOf(const SubclassIdentifier<B>* identifier)
- { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); }
- /** @brief Returns true if the objects class is a direct parent of the given type. */
- template <class B> bool OrxonoxClass::isDirectParentOf(const SubclassIdentifier<B>* identifier)
- { return this->getIdentifier()->isDirectParentOf(identifier->getIdentifier()); }
-
-
- /** @brief Returns true if the objects class is of the given type or a derivative. */
- template <class B> bool OrxonoxClass::isA(const SubclassIdentifier<B> identifier)
- { return this->getIdentifier()->isA(identifier.getIdentifier()); }
- /** @brief Returns true if the objects class is exactly of the given type. */
- template <class B> bool OrxonoxClass::isExactlyA(const SubclassIdentifier<B> identifier)
- { return this->getIdentifier()->isExactlyA(identifier.getIdentifier()); }
- /** @brief Returns true if the objects class is a child of the given type. */
- template <class B> bool OrxonoxClass::isChildOf(const SubclassIdentifier<B> identifier)
- { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); }
- /** @brief Returns true if the objects class is a direct child of the given type. */
- template <class B> bool OrxonoxClass::isDirectChildOf(const SubclassIdentifier<B> identifier)
- { return this->getIdentifier()->isDirectChildOf(identifier.getIdentifier()); }
- /** @brief Returns true if the objects class is a parent of the given type. */
- template <class B> bool OrxonoxClass::isParentOf(const SubclassIdentifier<B> identifier)
- { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); }
- /** @brief Returns true if the objects class is a direct parent of the given type. */
- template <class B> bool OrxonoxClass::isDirectParentOf(const SubclassIdentifier<B> identifier)
- { return this->getIdentifier()->isDirectParentOf(identifier.getIdentifier()); }
-
-
- /** @brief Returns true if the objects class is of the given type or a derivative. */
bool OrxonoxClass::isA(const OrxonoxClass* object)
{ return this->getIdentifier()->isA(object->getIdentifier()); }
/** @brief Returns true if the objects class is exactly of the given type. */
Modified: sandbox/src/libraries/core/OrxonoxClass.h
===================================================================
--- sandbox/src/libraries/core/OrxonoxClass.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/core/OrxonoxClass.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -71,20 +71,19 @@
bool isParentOf(const Identifier* identifier);
bool isDirectParentOf(const Identifier* identifier);
- template <class B> bool isA(const SubclassIdentifier<B>* identifier);
- template <class B> bool isExactlyA(const SubclassIdentifier<B>* identifier);
- template <class B> bool isChildOf(const SubclassIdentifier<B>* identifier);
- template <class B> bool isDirectChildOf(const SubclassIdentifier<B>* identifier);
- template <class B> bool isParentOf(const SubclassIdentifier<B>* identifier);
- template <class B> bool isDirectParentOf(const SubclassIdentifier<B>* identifier);
+ template <class B> inline bool isA(const SubclassIdentifier<B>* identifier)
+ { return this->isA(*identifier); }
+ template <class B> inline bool isExactlyA(const SubclassIdentifier<B>* identifier)
+ { return this->isExactlyA(*identifier); }
+ template <class B> inline bool isChildOf(const SubclassIdentifier<B>* identifier)
+ { return this->isChildOf(*identifier); }
+ template <class B> inline bool isDirectChildOf(const SubclassIdentifier<B>* identifier)
+ { return this->isDirectChildOf(*identifier); }
+ template <class B> inline bool isParentOf(const SubclassIdentifier<B>* identifier)
+ { return this->isParentOf(*identifier); }
+ template <class B> inline bool isDirectParentOf(const SubclassIdentifier<B>* identifier)
+ { return this->isDirectParentOf(*identifier); }
- template <class B> bool isA(const SubclassIdentifier<B> identifier);
- template <class B> bool isExactlyA(const SubclassIdentifier<B> identifier);
- template <class B> bool isChildOf(const SubclassIdentifier<B> identifier);
- template <class B> bool isDirectChildOf(const SubclassIdentifier<B> identifier);
- template <class B> bool isParentOf(const SubclassIdentifier<B> identifier);
- template <class B> bool isDirectParentOf(const SubclassIdentifier<B> identifier);
-
bool isA(const OrxonoxClass* object);
bool isExactlyA(const OrxonoxClass* object);
bool isChildOf(const OrxonoxClass* object);
@@ -99,23 +98,23 @@
@return
Returns NULL if the no pointer was found.
*/
- template <class T>
- FORCEINLINE T* getDerivedPointer(unsigned int classID)
+ FORCEINLINE void* getDerivedPointer(unsigned int classID)
{
for (int i = this->objectPointers_.size() - 1; i >= 0; --i)
{
if (this->objectPointers_[i].first == classID)
- return static_cast<T*>(this->objectPointers_[i].second);
+ return this->objectPointers_[i].second;
}
return NULL;
}
- //! Const version of getDerivedPointer
- template <class T>
- FORCEINLINE const T* getDerivedPointer(unsigned int classID) const
- {
- return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID);
- }
+ //! Version of getDerivedPointer with template
+ template <class T> FORCEINLINE T* getDerivedPointer(unsigned int classID)
+ { return static_cast<T*>(this->getDerivedPointer(classID)); }
+ //! Const version of getDerivedPointer with template
+ template <class T> FORCEINLINE const T* getDerivedPointer(unsigned int classID) const
+ { return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID); }
+
private:
Identifier* identifier_; //!< The Identifier of the object
std::set<const Identifier*>* parents_; //!< List of all parents of the object
Copied: sandbox/src/libraries/core/PathConfig.cc (from rev 6035, code/trunk/src/libraries/core/PathConfig.cc)
===================================================================
--- sandbox/src/libraries/core/PathConfig.cc (rev 0)
+++ sandbox/src/libraries/core/PathConfig.cc 2009-11-05 20:22:22 UTC (rev 6038)
@@ -0,0 +1,309 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "PathConfig.h"
+
+#include <cassert>
+#include <cstdlib>
+#include <cstdio>
+#include <vector>
+#include <boost/version.hpp>
+#include <boost/filesystem.hpp>
+
+#ifdef ORXONOX_PLATFORM_WINDOWS
+# ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+# endif
+# include <windows.h>
+# undef min
+# undef max
+#elif defined(ORXONOX_PLATFORM_APPLE)
+# include <sys/param.h>
+# include <mach-o/dyld.h>
+#else /* Linux */
+# include <sys/types.h>
+# include <unistd.h>
+#endif
+
+#include "SpecialConfig.h"
+#include "util/Debug.h"
+#include "util/Exception.h"
+#include "CommandLineParser.h"
+
+// Boost 1.36 has some issues with deprecated functions that have been omitted
+#if (BOOST_VERSION == 103600)
+# define BOOST_LEAF_FUNCTION filename
+#else
+# define BOOST_LEAF_FUNCTION leaf
+#endif
+
+namespace orxonox
+{
+ namespace bf = boost::filesystem;
+
+ //! Static pointer to the singleton
+ PathConfig* PathConfig::singletonPtr_s = 0;
+
+ SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
+
+ PathConfig::PathConfig()
+ : rootPath_(*(new bf::path()))
+ , executablePath_(*(new bf::path()))
+ , modulePath_(*(new bf::path()))
+ , dataPath_(*(new bf::path()))
+ , configPath_(*(new bf::path()))
+ , logPath_(*(new bf::path()))
+ , bDevRun_(false)
+ {
+ //////////////////////////
+ // FIND EXECUTABLE PATH //
+ //////////////////////////
+
+#ifdef ORXONOX_PLATFORM_WINDOWS
+ // get executable module
+ TCHAR buffer[1024];
+ if (GetModuleFileName(NULL, buffer, 1024) == 0)
+ ThrowException(General, "Could not retrieve executable path.");
+
+#elif defined(ORXONOX_PLATFORM_APPLE)
+ char buffer[1024];
+ unsigned long path_len = 1023;
+ if (_NSGetExecutablePath(buffer, &path_len))
+ ThrowException(General, "Could not retrieve executable path.");
+
+#else /* Linux */
+ /* written by Nicolai Haehnle <prefect_ at gmx.net> */
+
+ /* Get our PID and build the name of the link in /proc */
+ char linkname[64]; /* /proc/<pid>/exe */
+ if (snprintf(linkname, sizeof(linkname), "/proc/%i/exe", getpid()) < 0)
+ {
+ /* This should only happen on large word systems. I'm not sure
+ what the proper response is here.
+ Since it really is an assert-like condition, aborting the
+ program seems to be in order. */
+ assert(false);
+ }
+
+ /* Now read the symbolic link */
+ char buffer[1024];
+ int ret;
+ ret = readlink(linkname, buffer, 1024);
+ /* In case of an error, leave the handling up to the caller */
+ if (ret == -1)
+ ThrowException(General, "Could not retrieve executable path.");
+
+ /* Ensure proper NUL termination */
+ buffer[ret] = 0;
+#endif
+
+ executablePath_ = bf::path(buffer);
+#ifndef ORXONOX_PLATFORM_APPLE
+ executablePath_ = executablePath_.branch_path(); // remove executable name
+#endif
+
+ /////////////////////
+ // SET MODULE PATH //
+ /////////////////////
+
+ if (bf::exists(executablePath_ / "orxonox_dev_build.keep_me"))
+ {
+ COUT(1) << "Running from the build tree." << std::endl;
+ PathConfig::bDevRun_ = true;
+ modulePath_ = specialConfig::moduleDevDirectory;
+ }
+ else
+ {
+
+#ifdef INSTALL_COPYABLE // --> relative paths
+
+ // Also set the root path
+ bf::path relativeExecutablePath(specialConfig::defaultRuntimePath);
+ rootPath_ = executablePath_;
+ while (!bf::equivalent(rootPath_ / relativeExecutablePath, executablePath_) && !rootPath_.empty())
+ rootPath_ = rootPath_.branch_path();
+ if (rootPath_.empty())
+ ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");
+
+ // Module path is fixed as well
+ modulePath_ = rootPath_ / specialConfig::defaultModulePath;
+
+#else
+
+ // There is no root path, so don't set it at all
+ // Module path is fixed as well
+ modulePath_ = specialConfig::moduleInstallDirectory;
+
+#endif
+ }
+ }
+
+ PathConfig::~PathConfig()
+ {
+ delete &rootPath_;
+ delete &executablePath_;
+ delete &modulePath_;
+ delete &dataPath_;
+ delete &configPath_;
+ delete &logPath_;
+ }
+
+ void PathConfig::setConfigurablePaths()
+ {
+ if (bDevRun_)
+ {
+ dataPath_ = specialConfig::dataDevDirectory;
+ configPath_ = specialConfig::configDevDirectory;
+ logPath_ = specialConfig::logDevDirectory;
+ }
+ else
+ {
+
+#ifdef INSTALL_COPYABLE // --> relative paths
+
+ // Using paths relative to the install prefix, complete them
+ dataPath_ = rootPath_ / specialConfig::defaultDataPath;
+ configPath_ = rootPath_ / specialConfig::defaultConfigPath;
+ logPath_ = rootPath_ / specialConfig::defaultLogPath;
+
+#else
+
+ dataPath_ = specialConfig::dataInstallDirectory;
+
+ // Get user directory
+# ifdef ORXONOX_PLATFORM_UNIX /* Apple? */
+ char* userDataPathPtr(getenv("HOME"));
+# else
+ char* userDataPathPtr(getenv("APPDATA"));
+# endif
+ if (userDataPathPtr == NULL)
+ ThrowException(General, "Could not retrieve user data path.");
+ bf::path userDataPath(userDataPathPtr);
+ userDataPath /= ".orxonox";
+
+ configPath_ = userDataPath / specialConfig::defaultConfigPath;
+ logPath_ = userDataPath / specialConfig::defaultLogPath;
+
+#endif
+
+ }
+
+ // Option to put all the config and log files in a separate folder
+ if (!CommandLineParser::getArgument("writingPathSuffix")->hasDefaultValue())
+ {
+ std::string directory(CommandLineParser::getValue("writingPathSuffix").getString());
+ configPath_ = configPath_ / directory;
+ logPath_ = logPath_ / directory;
+ }
+
+ // Create directories to avoid problems when opening files in non existent folders.
+ std::vector<std::pair<bf::path, std::string> > directories;
+ directories.push_back(std::make_pair(bf::path(configPath_), "config"));
+ directories.push_back(std::make_pair(bf::path(logPath_), "log"));
+
+ for (std::vector<std::pair<bf::path, std::string> >::iterator it = directories.begin();
+ it != directories.end(); ++it)
+ {
+ if (bf::exists(it->first) && !bf::is_directory(it->first))
+ {
+ ThrowException(General, std::string("The ") + it->second + " directory has been preoccupied by a file! \
+ Please remove " + it->first.string());
+ }
+ if (bf::create_directories(it->first)) // function may not return true at all (bug?)
+ {
+ COUT(4) << "Created " << it->second << " directory" << std::endl;
+ }
+ }
+ }
+
+ std::vector<std::string> PathConfig::getModulePaths()
+ {
+ std::vector<std::string> modulePaths;
+
+ // We search for helper files with the following extension
+ std::string moduleextension = specialConfig::moduleExtension;
+ size_t moduleextensionlength = moduleextension.size();
+
+ // Add that path to the PATH variable in case a module depends on another one
+ std::string pathVariable = getenv("PATH");
+ putenv(const_cast<char*>(("PATH=" + pathVariable + ";" + modulePath_.string()).c_str()));
+
+ boost::filesystem::directory_iterator file(modulePath_);
+ boost::filesystem::directory_iterator end;
+
+ // Iterate through all files
+ while (file != end)
+ {
+ std::string filename = file->BOOST_LEAF_FUNCTION();
+
+ // Check if the file ends with the exension in question
+ if (filename.size() > moduleextensionlength)
+ {
+ if (filename.substr(filename.size() - moduleextensionlength) == moduleextension)
+ {
+ // We've found a helper file
+ std::string library = filename.substr(0, filename.size() - moduleextensionlength);
+ modulePaths.push_back((modulePath_ / library).file_string());
+ }
+ }
+ ++file;
+ }
+
+ return modulePaths;
+ }
+
+ /*static*/ std::string PathConfig::getRootPathString()
+ {
+ return getInstance().rootPath_.string() + '/';
+ }
+
+ /*static*/ std::string PathConfig::getExecutablePathString()
+ {
+ return getInstance().executablePath_.string() + '/';
+ }
+
+ /*static*/ std::string PathConfig::getDataPathString()
+ {
+ return getInstance().dataPath_.string() + '/';
+ }
+
+ /*static*/ std::string PathConfig::getConfigPathString()
+ {
+ return getInstance().configPath_.string() + '/';
+ }
+
+ /*static*/ std::string PathConfig::getLogPathString()
+ {
+ return getInstance().logPath_.string() + '/';
+ }
+
+ /*static*/ std::string PathConfig::getModulePathString()
+ {
+ return getInstance().modulePath_.string() + '/';
+ }
+}
Copied: sandbox/src/libraries/core/PathConfig.h (from rev 6035, code/trunk/src/libraries/core/PathConfig.h)
===================================================================
--- sandbox/src/libraries/core/PathConfig.h (rev 0)
+++ sandbox/src/libraries/core/PathConfig.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -0,0 +1,131 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _PathConfig_H__
+#define _PathConfig_H__
+
+#include "CorePrereqs.h"
+
+#include <string>
+#include <vector>
+#include "util/Singleton.h"
+
+namespace orxonox
+{
+ /**
+ @brief
+ The PathConfig class is a singleton used to configure different paths.
+ @details
+ The class provides information about the data, config, log, executable,
+ root and module path.
+ It determines those by the use of platform specific functions.
+ @remarks
+ Not all paths are always available:
+ - root only when installed copyable
+ - externalData only for development builds in the build tree
+ */
+ class _CoreExport PathConfig : public Singleton<PathConfig>
+ {
+ friend class Singleton<PathConfig>;
+ friend class Core;
+
+ public:
+ /**
+ @brief
+ Retrievs the executable path and sets all hard coded fixed paths (currently only the module path)
+ Also checks for "orxonox_dev_build.keep_me" in the executable diretory.
+ If found it means that this is not an installed run, hence we
+ don't write the logs and config files to ~/.orxonox
+ @throw
+ GeneralException
+ */
+ PathConfig();
+ ~PathConfig();
+
+ //! Returns the path to the root folder as boost::filesystem::path
+ static const boost::filesystem::path& getRootPath()
+ { return getInstance().rootPath_; }
+ //! Returns the path to the executable folder as boost::filesystem::path
+ static const boost::filesystem::path& getExecutablePath()
+ { return getInstance().executablePath_; }
+ //! Returns the path to the data files as boost::filesystem::path
+ static const boost::filesystem::path& getDataPath()
+ { return getInstance().dataPath_; }
+ //! Returns the path to the config files as boost::filesystem::path
+ static const boost::filesystem::path& getConfigPath()
+ { return getInstance().configPath_; }
+ //! Returns the path to the log files as boost::filesystem::path
+ static const boost::filesystem::path& getLogPath()
+ { return getInstance().logPath_; }
+ //! Returns the path to the modules as boost::filesystem::path
+ static const boost::filesystem::path& getModulePath()
+ { return getInstance().modulePath_; }
+
+ //! Returns the path to the root folder as std::string
+ static std::string getRootPathString();
+ //! Returns the path to the executable folder as std::string
+ static std::string getExecutablePathString();
+ //! Returns the path to the data files as std::string
+ static std::string getDataPathString();
+ //! Returns the path to the config files as std::string
+ static std::string getConfigPathString();
+ //! Returns the path to the log files as std::string
+ static std::string getLogPathString();
+ //! Returns the path to the modules as std::string
+ static std::string getModulePathString();
+
+ //! Return trrue for runs in the build directory (not installed)
+ static bool isDevelopmentRun() { return getInstance().bDevRun_; }
+
+ private:
+ PathConfig(const PathConfig&); //!< Don't use (undefined symbol)
+
+ /**
+ @brief
+ Sets config, log and media path and creates the folders if necessary.
+ @throws
+ GeneralException
+ */
+ void setConfigurablePaths();
+ //! Returns a list with all modules declared by a *.module file in the module folder.
+ std::vector<std::string> getModulePaths();
+
+ //! Path to the parent directory of the ones above if program was installed with relativ paths
+ boost::filesystem::path& rootPath_;
+ boost::filesystem::path& executablePath_; //!< Path to the executable
+ boost::filesystem::path& modulePath_; //!< Path to the modules
+ boost::filesystem::path& dataPath_; //!< Path to the data files folder
+ boost::filesystem::path& configPath_; //!< Path to the config files folder
+ boost::filesystem::path& logPath_; //!< Path to the log files folder
+
+ bool bDevRun_; //!< True for runs in the build directory (not installed)
+ static PathConfig* singletonPtr_s;
+ };
+}
+
+#endif /* _PathConfig_H__ */
Modified: sandbox/src/libraries/util/CMakeLists.txt
===================================================================
--- sandbox/src/libraries/util/CMakeLists.txt 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/util/CMakeLists.txt 2009-11-05 20:22:22 UTC (rev 6038)
@@ -18,18 +18,21 @@
#
SET_SOURCE_FILES(UTIL_SRC_FILES
- CRC32.cc
Exception.cc
- ExprParser.cc
Math.cc
MultiType.cc
+ Scope.cc
+ StringUtils.cc
+COMPILATION_BEGIN StableCompilation.cc
+ Clock.cc
+ CRC32.cc
+ ExprParser.cc
OutputBuffer.cc
OutputHandler.cc
- Scope.cc
SignalHandler.cc
Sleep.cc
- StringUtils.cc
SubString.cc
+COMPILATION_END
)
IF(GCC_NO_SYSTEM_HEADER_SUPPORT)
Copied: sandbox/src/libraries/util/Clock.cc (from rev 6035, code/trunk/src/libraries/util/Clock.cc)
===================================================================
--- sandbox/src/libraries/util/Clock.cc (rev 0)
+++ sandbox/src/libraries/util/Clock.cc 2009-11-05 20:22:22 UTC (rev 6038)
@@ -0,0 +1,73 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "Clock.h"
+#include <OgreTimer.h>
+
+namespace orxonox
+{
+ Clock::Clock()
+ : timer_(new Ogre::Timer())
+ , storedTime_(0)
+ , tickTime_(0)
+ , tickDt_(0)
+ , tickDtFloat_(0.0f)
+ , lastTimersTime_(0)
+ {
+ }
+
+ Clock::~Clock()
+ {
+ delete timer_;
+ }
+
+ void Clock::capture()
+ {
+ unsigned long timersTime = timer_->getMicroseconds();
+ tickTime_ = storedTime_ + timersTime;
+ tickDt_ = timersTime - lastTimersTime_;
+ tickDtFloat_ = static_cast<float>(tickDt_) / 1000000.0f;
+
+ if (timersTime > 0xFFFFFFFF/4)
+ {
+ // Ogre timer will overflow at 2^32 microseconds if unsigned long is 32 bit
+ storedTime_ += timersTime;
+ lastTimersTime_ = 0;
+ timer_->reset();
+ }
+ else
+ {
+ lastTimersTime_ = timersTime;
+ }
+ }
+
+ unsigned long long Clock::getRealMicroseconds() const
+ {
+ return this->timer_->getMicroseconds() + this->storedTime_;
+ }
+}
Copied: sandbox/src/libraries/util/Clock.h (from rev 6035, code/trunk/src/libraries/util/Clock.h)
===================================================================
--- sandbox/src/libraries/util/Clock.h (rev 0)
+++ sandbox/src/libraries/util/Clock.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -0,0 +1,68 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _Clock_H__
+#define _Clock_H__
+
+#include "UtilPrereqs.h"
+
+namespace Ogre { class Timer; }
+
+namespace orxonox
+{
+ class _UtilExport Clock
+ {
+ public:
+ Clock();
+ ~Clock();
+
+ void capture();
+
+ unsigned long long getMicroseconds() const { return tickTime_; }
+ unsigned long long getMilliseconds() const { return tickTime_ / 1000; }
+ unsigned long getSeconds() const { return static_cast<long> (tickTime_ / 1000000); }
+ float getSecondsPrecise() const { return static_cast<float>(tickTime_ / 1000000.0f); }
+
+ float getDeltaTime() const { return tickDtFloat_; }
+ long getDeltaTimeMicroseconds() const { return tickDt_; }
+
+ unsigned long long getRealMicroseconds() const;
+
+ private:
+ Clock(const Clock& instance);
+
+ Ogre::Timer* timer_;
+ unsigned long long storedTime_;
+ unsigned long long tickTime_;
+ long tickDt_;
+ float tickDtFloat_;
+ unsigned long lastTimersTime_;
+ };
+}
+
+#endif /* _Clock_H__ */
Modified: sandbox/src/libraries/util/Scope.h
===================================================================
--- sandbox/src/libraries/util/Scope.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/util/Scope.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -30,28 +30,16 @@
#define __Util_Scope_H__
#include "UtilPrereqs.h"
+
#include <cassert>
+#include <map>
#include <set>
-#include <map>
+
#include "Debug.h"
+#include "ScopeGuard.h"
namespace orxonox
{
- namespace ScopeID
- {
- /**
- @brief A list of available scopes for the Scope template.
- */
- enum Value
- {
- GSRoot,
- GSGraphics,
- GSLevel
- };
- }
-
- class ScopeListener; // Forward declaration
-
/**
@brief The ScopeManager stores the variables of the scope templates in a statically linked context.
*/
@@ -76,7 +64,7 @@
protected:
//! Constructor: Registers the instance.
- ScopeListener(ScopeID::Value scope) : scope_(scope)
+ ScopeListener(ScopeID::Value scope) : scope_(scope), bActivated_(false)
{ ScopeManager::listeners_s[this->scope_].insert(this); }
//! Destructor: Unregisters the instance.
virtual ~ScopeListener()
@@ -89,6 +77,7 @@
private:
ScopeID::Value scope_; //!< Store the scope to unregister on destruction
+ bool bActivated_;
};
/**
@@ -104,13 +93,26 @@
//! Constructor: Increases the instance counter and activates the scope if the count went from 0 to 1. Counts >1 don't change anything.
Scope()
{
- ScopeManager::instanceCounts_s[scope]++;
- assert(ScopeManager::instanceCounts_s[scope] > 0);
- if (ScopeManager::instanceCounts_s[scope] == 1)
+ try
{
- for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); )
- (*(it++))->activated();
+ ScopeManager::instanceCounts_s[scope]++;
+ assert(ScopeManager::instanceCounts_s[scope] > 0);
+ if (ScopeManager::instanceCounts_s[scope] == 1)
+ {
+ Loki::ScopeGuard deactivator = Loki::MakeObjGuard(*this, &Scope::deactivateListeners);
+ for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); )
+ {
+ (*it)->activated();
+ (*(it++))->bActivated_ = true;
+ }
+ deactivator.Dismiss();
+ }
}
+ catch (...)
+ {
+ ScopeManager::instanceCounts_s[scope]--;
+ throw;
+ }
}
//! Destructor: Decreases the instance counter and deactivates the scope if the count went from 1 to 0. Counts >0 don't change anything.
@@ -124,9 +126,23 @@
ScopeManager::instanceCounts_s[scope] = 0;
if (ScopeManager::instanceCounts_s[scope] == 0)
+ this->deactivateListeners();
+ }
+
+ void deactivateListeners()
+ {
+ for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); )
{
- for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); )
- (*(it++))->deactivated();
+ if ((*it)->bActivated_)
+ {
+ try
+ { (*it)->deactivated(); }
+ catch (...)
+ { COUT(0) << "ScopeListener::deactivated() failed! This MUST NOT happen, fix it!" << std::endl; }
+ (*(it++))->bActivated_ = false;
+ }
+ else
+ ++it;
}
}
Deleted: sandbox/src/libraries/util/ScopedSingleton.h
===================================================================
--- sandbox/src/libraries/util/ScopedSingleton.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/util/ScopedSingleton.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -1,102 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-#ifndef __Util_ScopedSingleton_H__
-#define __Util_ScopedSingleton_H__
-
-#include "UtilPrereqs.h"
-#include <cassert>
-
-#include "Scope.h"
-
-namespace orxonox
-{
- /**
- @brief
- Base for scoped singleton classes.
- A Scoped singleton creates itself if the scope is active and getInstance() is called.
- Destroys itself if the scope is deactivated.
-
- Usage:
- Inherit publicly from ScopedSingleton<MyClass, scope> and provide access to
- MyClass::singletonPtr_s.
- This can easily be done with a friend declaration.
-
- See @ref UtilPrereqs.h for a list of scopes (ScopeID::Value).
- */
- template <class T, ScopeID::Value scope>
- class ScopedSingleton : public ScopeListener
- {
- public:
- //! Returns a reference to the singleton instance
- static T& getInstance()
- {
- assert(Scope<scope>::isActive());
-
- if (!T::singletonPtr_s && Scope<scope>::isActive())
- T::singletonPtr_s = new T();
-
- return *T::singletonPtr_s;
- }
-
- protected:
- //! Constructor sets the singleton instance pointer
- ScopedSingleton() : ScopeListener(scope)
- {
- assert(T::singletonPtr_s == 0);
- T::singletonPtr_s = static_cast<T*>(this);
- }
-
- //! Constructor resets the singleton instance pointer
- ~ScopedSingleton()
- {
- assert(T::singletonPtr_s != 0);
- T::singletonPtr_s = 0;
- }
-
- private:
- //! Called if the Scope of this Singleton gets active (no instance should be active then)
- void activated()
- {
- // The ScopedSingleton shouldn't be active bevor the scope is activated -> always assertion failed
- assert(T::singletonPtr_s == 0 && false);
- }
-
- //! Called if the Scope of this Singleton gets deactivated (destroys the instance)
- void deactivated()
- {
- if (T::singletonPtr_s)
- {
- delete T::singletonPtr_s;
- T::singletonPtr_s = 0;
- }
- }
- };
-}
-
-#endif /* __Util_ScopedSingleton_H__ */
Modified: sandbox/src/libraries/util/UtilPrereqs.h
===================================================================
--- sandbox/src/libraries/util/UtilPrereqs.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/libraries/util/UtilPrereqs.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -27,8 +27,9 @@
*/
/**
- @file
- @brief Contains all the necessary forward declarations for all classes and structs.
+ at file
+ at brief
+ Shared library macros, enums, constants and forward declarations for the util library
*/
#ifndef _UtilPrereqs_H__
@@ -39,6 +40,7 @@
//-----------------------------------------------------------------------
// Shared library settings
//-----------------------------------------------------------------------
+
#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined( UTIL_STATIC_BUILD )
# ifdef UTIL_SHARED_BUILD
# define _UtilExport __declspec(dllexport)
@@ -55,13 +57,30 @@
# define _UtilExport
#endif
+//-----------------------------------------------------------------------
+// Enums
+//-----------------------------------------------------------------------
+namespace orxonox
+{
+ namespace ScopeID
+ {
+ //!A list of available scopes for the Scope template.
+ enum Value
+ {
+ Root,
+ Graphics
+ };
+ }
+}
+
//-----------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------
namespace orxonox
{
+ class Clock;
class Exception;
class ExprParser;
class IntVector2;
@@ -70,7 +89,14 @@
class OutputBuffer;
class OutputBufferListener;
class OutputHandler;
+ template <ScopeID::Value>
+ class Scope;
+ template <class, ScopeID::Value>
+ class ScopedSingleton;
+ class ScopeListener;
class SignalHandler;
+ template <class T>
+ class Singleton;
class SubString;
}
Modified: sandbox/src/orxonox/GSRoot.cc
===================================================================
--- sandbox/src/orxonox/GSRoot.cc 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/orxonox/GSRoot.cc 2009-11-05 20:22:22 UTC (rev 6038)
@@ -28,7 +28,7 @@
#include "GSRoot.h"
-#include "core/Clock.h"
+#include "util/Clock.h"
#include "core/Game.h"
namespace orxonox
Modified: sandbox/src/orxonox/Main.cc
===================================================================
--- sandbox/src/orxonox/Main.cc 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/orxonox/Main.cc 2009-11-05 20:22:22 UTC (rev 6038)
@@ -30,14 +30,12 @@
/**
@file
@brief
- The main function of Orxonox.
+ The main function of Orxonox (but not the entry point of the program!)
*/
#include "OrxonoxPrereqs.h"
-#include "SpecialConfig.h"
-#include "util/Exception.h"
-#include "core/CommandLine.h"
+#include "core/CommandLineParser.h"
#include "core/Game.h"
#include "core/LuaState.h"
#include "Main.h"
@@ -46,7 +44,7 @@
{
/**
@brief
- Main method. Game starts here (except for static initialisations).
+ Starting point of orxonox (however not the entry point of the program!)
*/
int main(const std::string& strCmdLine)
{
Modified: sandbox/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- sandbox/src/orxonox/OrxonoxPrereqs.h 2009-11-05 12:31:31 UTC (rev 6037)
+++ sandbox/src/orxonox/OrxonoxPrereqs.h 2009-11-05 20:22:22 UTC (rev 6038)
@@ -27,18 +27,19 @@
*/
/**
- @file
- @brief Contains all the necessary forward declarations for all classes and structs.
+ at file
+ at brief
+ Shared library macros, enums, constants and forward declarations for the orxonox library
*/
#ifndef _OrxonoxPrereqs_H__
#define _OrxonoxPrereqs_H__
#include "OrxonoxConfig.h"
-
//-----------------------------------------------------------------------
// Shared library settings
//-----------------------------------------------------------------------
+
#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(ORXONOX_STATIC_BUILD)
# ifdef ORXONOX_SHARED_BUILD
# define _OrxonoxExport __declspec(dllexport)
@@ -62,71 +63,75 @@
namespace orxonox
{
class CameraManager;
+ class Level;
class LevelManager;
class PawnManager;
class PlayerManager;
-
- class Level;
+ class Radar;
class Scene;
- class Tickable;
- // interfaces
- class GametypeMessageListener;
- class NotificationListener;
- class PawnListener;
- class PlayerTrigger;
- class RadarListener;
- class RadarViewable;
- class Rewardable;
- class Teamcolourable;
+ // collisionshapes
+ class CollisionShape;
+ class CompoundCollisionShape;
+ class WorldEntityCollisionShape;
- // worldentities
- class WorldEntity;
- class StaticEntity;
- class MobileEntity;
- class ControllableEntity;
- class MovableEntity;
+ // controllers
+ class AIController;
+ class ArtificialController;
+ class Controller;
+ class HumanController;
+ class ScriptController;
+ class WaypointController;
+ class WaypointPatrolController;
+ // gametypes
+ class Asteroids;
+ class Deathmatch;
+ class Gametype;
+ class TeamBaseMatch;
+ class TeamDeathmatch;
+ class UnderAttack;
+
// graphics
- class Model;
+ class Backlight;
class Billboard;
class BlinkingBillboard;
- class BigExplosion;
- class ExplosionChunk;
+ class Camera;
class FadingBillboard;
class GlobalShader;
class Light;
- class Backlight;
+ class Model;
class ParticleEmitter;
class ParticleSpawner;
- class Camera;
- // mixed
- class SpawnPoint;
- class TeamSpawnPoint;
+ // infos
+ class Bot;
+ class GametypeInfo;
+ class HumanPlayer;
+ class Info;
+ class PlayerInfo;
- class CameraPosition;
- class Sublevel;
- class Radar;
+ // interfaces
+ class GametypeMessageListener;
+ class NotificationListener;
+ class PlayerTrigger;
+ class RadarListener;
+ class RadarViewable;
+ class Rewardable;
+ class TeamColourable;
- class Test;
+ // items
+ class Engine;
+ class Item;
+ class MultiStateEngine;
- // pawns
- class Spectator;
- class Pawn;
- class SpaceShip;
- class TeamBaseMatchBase;
- class Destroyer;
+ // overlays
+ class InGameConsole;
+ class Map;
+ class OrxonoxOverlay;
+ class OverlayGroup;
- // gametypes
- class Gametype;
- class Deathmatch;
- class TeamDeathmatch;
- class Asteroids;
- class TeamBaseMatch;
- class UnderAttack;
-
- // pickups
+ // pickup
class BaseItem;
class DroppedItem;
class EquipmentItem;
@@ -136,60 +141,44 @@
class PickupInventory;
class PickupSpawner;
class UsableItem;
-
- class Jump;
+ // pickup, items
+ class HealthImmediate;
class HealthUsable;
- class PassiveItem;
+ class Jump;
- // items
- class Item;
- class Engine;
- class MultiStateEngine;
- class RotatingEngine;
+ //sound
+ class AmbientSound;
+ class BaseSound;
+ class SoundManager;
+ class WorldSound;
// weaponsystem
- class WeaponSystem;
- class WeaponSet;
- class WeaponSlot;
- class WeaponPack;
- class Weapon;
- class WeaponMode;
class DefaultWeaponmodeLink;
class Munition;
+ class Weapon;
+ class WeaponMode;
+ class WeaponPack;
+ class WeaponSet;
+ class WeaponSlot;
+ class WeaponSystem;
- // controller
- class Controller;
- class HumanController;
- class ArtificialController;
- class AIController;
- class ScriptController;
- class WaypointController;
- class WaypointPatrolController;
-
- // infos
- class Info;
- class PlayerInfo;
- class HumanPlayer;
- class Bot;
- class GametypeInfo;
-
- // collision
- class CollisionShape;
- class CompoundCollisionShape;
- class WorldEntityCollisionShape;
-
- // overlays
- class OverlayGroup;
- class OrxonoxOverlay;
- class Notification;
- class NotificationManager;
- class InGameConsole;
- class Map;
-
- //sound
- class SoundBase;
- class SoundManager;
- class SoundMainMenu;
+ // worldentities
+ class BigExplosion;
+ class CameraPosition;
+ class ControllableEntity;
+ class ExplosionChunk;
+ class MobileEntity;
+ class MovableEntity;
+ class SpawnPoint;
+ class StaticEntity;
+ class TeamSpawnPoint;
+ class WorldEntity;
+ // worldentities, pawns
+ class Destroyer;
+ class Pawn;
+ class SpaceShip;
+ class Spectator;
+ class TeamBaseMatchBase;
}
// Bullet Physics Engine
More information about the Orxonox-commit
mailing list