# HG changeset patch # User Max Samukha # Date 1273828477 -10800 # Node ID 96a75b1e5b2694be7531e990c81cdf9103e4a185 # Parent 552647ec0f828a4696b745511aa5ae9cd591c68a project structure changes diff -r 552647ec0f82 -r 96a75b1e5b26 CMakeLists.txt --- a/CMakeLists.txt Thu May 13 21:01:24 2010 +0300 +++ b/CMakeLists.txt Fri May 14 12:14:37 2010 +0300 @@ -1,27 +1,43 @@ cmake_minimum_required(VERSION 2.6) PROJECT(qtd CXX C) +# Debug and release flags. +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif (NOT CMAKE_BUILD_TYPE) + +if(${CMAKE_BUILD_TYPE} MATCHES [dD][eE][bB][uU][gG]) + set(CMAKE_BUILD_TYPE Debug) + #set( SUFFIXLIB "${SUFFIXLIB}-debug" ) + #set( SUFFIXBIN "${SUFFIXBIN}-debug" ) + add_definitions(-DDEBUG) +elseif (NOT ${CMAKE_BUILD_TYPE} MATCHES [rR][eE][lL][eE][aA][sS]) + message(STATUS "Only debug and release configurations are supproted. The configuration is changed to 'Release'") + set(CMAKE_BUILD_TYPE Release) +endif (${CMAKE_BUILD_TYPE} MATCHES [dD][eE][bB][uU][gG]) + +if (${CMAKE_BUILD_TYPE} MATCHES [rR][eE][lL][eE][aA][sS]) + #add_definitions(-UNO_DEBUG) +endif(${CMAKE_BUILD_TYPE} MATCHES [rR][eE][lL][eE][aA][sS] ) + ########################################################## ## Build generator. ########################################################## -if(NOT SECOND_RUN) +if (NOT SECOND_RUN) option(ALLOW_IN_SOURCE_BUILDS "Allow in-source builds" "OFF") -if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT ALLOW_IN_SOURCE_BUILDS) - message(FATAL_ERROR "In-source builds are not allowed. - Please create a directory and run cmake from there, passing the path -to this source directory as the last argument. - This process created the file `CMakeCache.txt` and the directory `CMakeFiles'. -Please delete them. - - Or you can restart cmake with `-DALLOW_IN_SOURCE_BUILDS=1`, but it is not -recommended. -") -endif(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT ALLOW_IN_SOURCE_BUILDS) +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT ALLOW_IN_SOURCE_BUILDS) + message(FATAL_ERROR "In-source builds are not allowed. " + "Please create a directory and run cmake from there, passing the path" + "to this source directory as the last argument. " + "This process created the file `CMakeCache.txt` and the directory `CMakeFiles'. Please delete them. " + "Or you can restart cmake with `-DALLOW_IN_SOURCE_BUILDS=1`, but it is not recommended." + ) +endif (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT ALLOW_IN_SOURCE_BUILDS) FIND_PACKAGE(Qt4 REQUIRED) -set (QT_USE_QTMAIN false) -set (QT_USE_QTGUI false) +set(QT_USE_QTMAIN false) +set(QT_USE_QTGUI false) ##-------------------------------------------- ## Settings. @@ -32,10 +48,10 @@ option(BUILD_SHARED_LIBRARIES "Build shared library (very experemental and only for ldc)" "OFF") option(BUILD_TOOLS "Build tools" "ON") #option(GENERATE_DI_FILES "Generate *.di files with DC -H command" "OFF") -set(GENERATE_DI_FILES OFF) ## Very experemental option. Temporary disabled. +set(GENERATE_DI_FILES OFF) ## Very experimental option. Temporarily disabled. option(VERBOSE_DEBUG "Verbose debug" "OFF") -set(all_packages Core Gui OpenGL Xml Svg Network WebKit CACHE INTERNAL "") +set(all_packages Core Gui OpenGL Xml Svg Network WebKit CACHE INTERNAL "") ## Init D toolkit. set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) @@ -43,60 +59,43 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR "${CMAKE_INSTALL_PREFIX}" STREQUAL "") set(CMAKE_INSTALL_PREFIX - ${DC_PATH} CACHE PATH "QtD install prefix" + ${DC_PATH} CACHE PATH "QtD install prefix" ) endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR "${CMAKE_INSTALL_PREFIX}" STREQUAL "") # Check D compiler version if(D_VERSION EQUAL "1") if (D_FRONTEND LESS "050") - message(STATUS "Minimum required version of D compiler is 1.050 (or compiler based on this version)") + message(STATUS "Minimum required version of D compiler is 1.050 (or compiler based on this version)") endif(D_FRONTEND LESS "050") - set(D_TARGET d1-tango CACHE INTERNAL "") + set(D_TARGET d1-tango CACHE INTERNAL "") elseif(D_VERSION EQUAL "2") set(D_TARGET d2-phobos CACHE INTERNAL "") endif(D_VERSION EQUAL "1") -# Debug and release flags. -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release) -endif (NOT CMAKE_BUILD_TYPE) -if(${CMAKE_BUILD_TYPE} MATCHES [dD][eE][bB][uU][gG]) - set(CMAKE_BUILD_TYPE Debug) - #set( SUFFIXLIB "${SUFFIXLIB}-debug" ) - #set( SUFFIXBIN "${SUFFIXBIN}-debug" ) - add_definitions(-DDEBUG) -elseif (NOT ${CMAKE_BUILD_TYPE} MATCHES [rR][eE][lL][eE][aA][sS]) - message(STATUS "Only debug and release configurations are supproted. The configuration is changed to 'Release'") - set(CMAKE_BUILD_TYPE Release) -endif (${CMAKE_BUILD_TYPE} MATCHES [dD][eE][bB][uU][gG]) -if (${CMAKE_BUILD_TYPE} MATCHES [rR][eE][lL][eE][aA][sS]) - #add_definitions(-UNO_DEBUG) -endif(${CMAKE_BUILD_TYPE} MATCHES [rR][eE][lL][eE][aA][sS] ) - # System specific settings. if(CMAKE_HOST_WIN32) set(implib implib) find_program(IMPLIB ${implib}) if (NOT IMPLIB) - message(FATAL_ERROR "implib is not found. You can donwload it from http://ftp.digitalmars.com/bup.zip") + message(FATAL_ERROR "implib is not found. You can donwload it from http://ftp.digitalmars.com/bup.zip") endif (NOT IMPLIB) if(D_IS_MARS) set(GEN_OPT ${GEN_OPT} --cpp_shared) add_definitions(-DCPP_SHARED) endif(D_IS_MARS) -endif(CMAKE_HOST_WIN32) +endif(CMAKE_HOST_WIN32) set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ./) set(GEN_OPT ${GEN_OPT} --d-target=${D_TARGET}) set(packages CACHE INTERNAL "") foreach(package_big ${all_packages}) - string(TOLOWER ${package_big} package) - string(TOUPPER ${package_big} package_upper) + string(TOLOWER ${package_big} package) + string(TOUPPER ${package_big} package_upper) option(BUILD_QT_${package_upper} "Build Qt${package_big}" "ON") if(BUILD_QT_${package_upper}) - set(packages ${packages} ${package_big}) + set(packages ${packages} ${package_big}) endif(BUILD_QT_${package_upper}) endforeach(package_big ${all_packages}) @@ -121,25 +120,25 @@ endif(${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR}) make_native_path(cd_path) -add_custom_command(TARGET main POST_BUILD - COMMAND ${CMAKE_COMMAND} ARGS -E make_directory ${CMAKE_BINARY_DIR}/build - COMMAND cd ARGS ${cd_path} && ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} -DSECOND_RUN=1 ${CMAKE_SOURCE_DIR} && ${make_util} - COMMENT "" - ) +add_custom_command(TARGET main POST_BUILD + COMMAND ${CMAKE_COMMAND} ARGS -E make_directory ${CMAKE_BINARY_DIR}/build + COMMAND cd ARGS ${cd_path} && ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} -DSECOND_RUN=1 ${CMAKE_SOURCE_DIR} && ${make_util} + COMMENT "" + ) ## "Make install" command. set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_BINARY_DIR}/build) add_custom_target(install - COMMAND cd ${CMAKE_BINARY_DIR}/build && ${make_util} install - COMMENT "" - ) + COMMAND cd ${CMAKE_BINARY_DIR}/build && ${make_util} install + COMMENT "" + ) add_dependencies(install preinstall) ##-------------------------------------------- ## CPack. ##-------------------------------------------- set(CPACK_PACKAGE_VERSION_PATCH 1) -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "QtD is a D binding to the Qt application and UI framework. +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "QtD is a D binding to the Qt application and UI framework. This package installs binding and static library for qt port on D programming language. ") SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/changelog.txt") @@ -178,29 +177,34 @@ # System specifc settings. if(CMAKE_HOST_WIN32) string(REGEX REPLACE ".dll([A-Za-z\\.0-9]+)" "\\1" CMAKE_IMPORT_LIBRARY_SUFFIX "${CMAKE_IMPORT_LIBRARY_SUFFIX}") -endif(CMAKE_HOST_WIN32) +endif(CMAKE_HOST_WIN32) if(CMAKE_HOST_WIN32 AND D_IS_MARS) set(CPP_SHARED 1 CACHE INTERNAL "") endif(CMAKE_HOST_WIN32 AND D_IS_MARS) if(D_IS_MARS) - set(D_FLAGS -version=cpp_shared) + set(D_FLAGS -version=cpp_shared) add_definitions(-DCPP_SHARED) endif(D_IS_MARS) if(UNITTEST) add_d_versions(QtdUnittest) + set(D_FLAGS ${D_FLAGS} -unittest) endif(UNITTEST) if(VERBOSE_DEBUG) add_d_debugs(QtdVerbose) endif(VERBOSE_DEBUG) +if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + add_d_debugs(QtdDebug) +endif(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + ## Bootstrap settings for QtD. set(DRCC ${CMAKE_BINARY_DIR}/tools/drcc/drcc CACHE INTERNAL "") set(DUIC ${CMAKE_BINARY_DIR}/tools/duic/duic CACHE INTERNAL "") -set(QTD_IMPORT_PATH ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/qt/d${D_VERSION} CACHE INTERNAL "") +set(QTD_IMPORT_PATH ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/d${D_VERSION} CACHE INTERNAL "") set(QTD_LIBRARIES_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "") ##-------------------------------------------- @@ -215,117 +219,117 @@ set (params NAME OPTIONS) qtd_parse_params (RESOURCES params ${ARGN}) if(NAME_tmp) - set(OPTIONS_tmp ${OPTIONS_tmp} -name ${NAME_tmp}) + set(OPTIONS_tmp ${OPTIONS_tmp} -name ${NAME_tmp}) endif(NAME_tmp) - qtd_command ("${output}" "${DRCC}" "${OPTIONS_tmp}" "qrc_" - "Generate" ${RESOURCES_tmp}) + qtd_command ("${output}" "${DRCC}" "${OPTIONS_tmp}" "qrc_" + "Generate" ${RESOURCES_tmp}) endmacro(qtd_add_resource output) macro(qtd_wrap_ui output) set (params OPTIONS) qtd_parse_params (UI params ${ARGN}) - qtd_command ("${output}" "${DUIC}" "${OPTIONS_tmp}" "uic_" - "Generate" ${UI_tmp}) + qtd_command ("${output}" "${DUIC}" "${OPTIONS_tmp}" "uic_" + "Generate" ${UI_tmp}) endmacro(qtd_wrap_ui output) macro(qtd_command output command options prefix comment) foreach(file "${ARGN}") - ## Test an exist of the input file. - get_filename_component(file_path ${file} PATH) - get_filename_component(file_name ${file} NAME_WE) - get_filename_component(file_ext ${file} EXT) + ## Test if the input file exists + get_filename_component(file_path ${file} PATH) + get_filename_component(file_name ${file} NAME_WE) + get_filename_component(file_ext ${file} EXT) - set(out ${CMAKE_CURRENT_BINARY_DIR}/${file_path}${prefix}${file_name}.d) - add_custom_command(OUTPUT "${out}" - COMMAND "${command}" - ARGS ${options} ${file} -o ${out} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - DEPENDS ${file} - COMMENT "${comment} ${file}" - ) - set(${output} ${${output}} ${out}) + set(out ${CMAKE_CURRENT_BINARY_DIR}/${file_path}${prefix}${file_name}.d) + add_custom_command(OUTPUT "${out}" + COMMAND "${command}" + ARGS ${options} ${file} -o ${out} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${file} + COMMENT "${comment} ${file}" + ) + set(${output} ${${output}} ${out}) endforeach(file "${ARGN}") endmacro(qtd_command output command options files prefix comment) ## Parses the parameters list. macro(qtd_parse_params default params) set(type_tmp ${default}) - set(params_tmp ${default} ${${params}}) - foreach(param_tmp ${params_tmp}) - set(${param_tmp}_tmp ) + set(params_tmp ${default} ${${params}}) + foreach(param_tmp ${params_tmp}) + set(${param_tmp}_tmp ) endforeach(param_tmp ${params_tmp}) foreach(arg_tmp ${ARGN}) - set(found_type_tmp) - if(NOT found_type_tmp) - foreach(param_tmp ${params_tmp}) - if(arg_tmp STREQUAL param_tmp) - set(type_tmp ${param_tmp}) - set(found_type_tmp 1) - break(param_tmp ${params_tmp}) - endif(arg_tmp STREQUAL param_tmp) - endforeach(param_tmp ${params_tmp}) - endif(NOT found_type_tmp) - if(NOT found_type_tmp) - set(${type_tmp}_tmp ${${type_tmp}_tmp} ${arg_tmp}) - endif(NOT found_type_tmp) + set(found_type_tmp) + if(NOT found_type_tmp) + foreach(param_tmp ${params_tmp}) + if(arg_tmp STREQUAL param_tmp) + set(type_tmp ${param_tmp}) + set(found_type_tmp 1) + break(param_tmp ${params_tmp}) + endif(arg_tmp STREQUAL param_tmp) + endforeach(param_tmp ${params_tmp}) + endif(NOT found_type_tmp) + if(NOT found_type_tmp) + set(${type_tmp}_tmp ${${type_tmp}_tmp} ${arg_tmp}) + endif(NOT found_type_tmp) endforeach(arg_tmp ${ARGN}) endmacro(qtd_parse_params default) ## Adds a new example. ## name -- example name. ## Options: -## PACKAGES -- list of packages for link to example (for example, QtCore QtGui QtOpenGL). -## Default value is "QtCore QtGui". +## PACKAGES -- list of packages for link to example (for example, QtCore QtGui QtOpenGL). +## Default value is "QtCore QtGui". ## params -- sources d files. ## Usage: -## build_example(ExampleName PACKAGES QtCore QtGui QtXml main.d another_d_file.d) +## build_example(ExampleName PACKAGES QtCore QtGui QtXml main.d another_d_file.d) macro(build_example name) set (params UIC RESOURCES PACKAGES) qtd_parse_params (SOURCES params ${ARGN}) if(NOT PACKAGES_tmp) - set(PACKAGES_tmp QtCore QtGui) + set(PACKAGES_tmp QtCore QtGui) endif(NOT PACKAGES_tmp) - + if(RESOURCES_tmp) - if(NOT BUILD_TOOLS) - message(STATUS "Example '${name}' requires drcc. Example will not be built") - return(build_example name) - endif(NOT BUILD_TOOLS) - qtd_add_resource(res_sources ${RESOURCES_tmp} NAME ${name} ) + if(NOT BUILD_TOOLS) + message(STATUS "Example '${name}' requires drcc. Example will not be built") + return(build_example name) + endif(NOT BUILD_TOOLS) + qtd_add_resource(res_sources ${RESOURCES_tmp} NAME ${name} ) endif(RESOURCES_tmp) if(UIC_tmp) - if(NOT BUILD_TOOLS) - message(STATUS "Example '${name}' requires drcc. Example will not be built") - return(build_example name) - endif(NOT BUILD_TOOLS) - qtd_wrap_ui(uic_sources ${UIC_tmp}) + if(NOT BUILD_TOOLS) + message(STATUS "Example '${name}' requires drcc. Example will not be built") + return(build_example name) + endif(NOT BUILD_TOOLS) + qtd_wrap_ui(uic_sources ${UIC_tmp}) endif(UIC_tmp) foreach(package ${PACKAGES_tmp}) - string(REGEX REPLACE "Qt([A-Za-z0-9])" "\\1" req "${package}") - set(is_founded) - foreach(package_big ${packages_big}) - string(TOLOWER ${package_big} package) - if(${req} STREQUAL ${package_big}) - set(is_founded 1) - break(package_big ${packages_big}) - endif(${req} STREQUAL ${package_big}) - endforeach(package_big ${packages_big}) - if(NOT is_founded) - message(STATUS "Example '${name}' requires the package '${req}', but it is not active. Example will not be built") - return(build_example name) - else(NOT is_founded) - set(qtd_libs ${${package}_lib_param} ${qtd_libs}) - endif(NOT is_founded) - endforeach(package ${PACKAGES_tmp}) + string(REGEX REPLACE "Qt([A-Za-z0-9])" "\\1" req "${package}") + set(is_found) + foreach(package_big ${packages_big}) + string(TOLOWER ${package_big} package) + if(${req} STREQUAL ${package_big}) + set(is_found 1) + break(package_big ${packages_big}) + endif(${req} STREQUAL ${package_big}) + endforeach(package_big ${packages_big}) + if(NOT is_found) + message(STATUS "Example '${name}' requires the package '${req}', but it is not active. Example will not be built") + return(build_example name) + else(NOT is_found) + set(qtd_libs ${${package}_lib_param} ${qtd_libs}) + endif(NOT is_found) + endforeach(package ${PACKAGES_tmp}) add_d_program(${name} ${SOURCES_tmp} NO_DEPS_SOURCES ${res_sources} ${uic_sources} - DEPENDS ${res_sources} INCLUDES ${QTD_IMPORT_PATH} ${CMAKE_CURRENT_BINARY_DIR} - LIB_PATHS ${QTD_LIBRARIES_PATH} ${CMAKE_SOURCE_DIR}/lib ${QT_LIBRARY_DIR} LIBS ${qtd_libs}) + DEPENDS ${res_sources} INCLUDES ${QTD_IMPORT_PATH} ${CMAKE_CURRENT_BINARY_DIR} + LIB_PATHS ${QTD_LIBRARIES_PATH} ${CMAKE_SOURCE_DIR}/lib ${QT_LIBRARY_DIR} LIBS ${qtd_libs}) ## TODO: Uncomment. #if(STRIP AND ${CMAKE_BUILD_TYPE} EQUAL "Release" AND CMAKE_HOST_UNIX) ## - # add_custom_command(TARGET example_${name} POST_BUILD COMMAND "${STRIP}" ARGS "${output}") + # add_custom_command(TARGET example_${name} POST_BUILD COMMAND "${STRIP}" ARGS "${output}") #endif(STRIP AND ${CMAKE_BUILD_TYPE} EQUAL "Release" AND CMAKE_HOST_UNIX) add_dependencies(examples ${name}) add_dependencies(${name} allpackages tools) @@ -340,7 +344,7 @@ link_directories(${CMAKE_BINARY_DIR}/CMakeFiles) foreach(package_big ${all_packages}) - string(TOLOWER ${package_big} package) + string(TOLOWER ${package_big} package) string(TOUPPER ${package} package_upper) ## Load settings for the package. set(required) @@ -353,210 +357,210 @@ set(link_d) set(cpp_files) set(cpp_generated_files) - set(d_files) + set(d_qt_files) + set(d_qtd_files) set(classes) set(d_generated_files) - set(d_version_files) set(link_example) - include (${CMAKE_SOURCE_DIR}/build/${package}.txt) + include (${CMAKE_SOURCE_DIR}/build/${package}.txt) set(all_req_found 1) if(BUILD_QT_${package_upper}) - foreach(req ${required}) - set(req_found) - foreach(pack ${packages_big}) - if(${pack} STREQUAL ${req}) - set(req_found 1) - endif(${pack} STREQUAL ${req}) - endforeach(pack ${packages}) - if(NOT req_found) - set(req_found) - foreach(pack ${all_packages}) - if(${pack} STREQUAL ${req}) - set(req_found 1) - endif(${pack} STREQUAL ${req}) - endforeach(pack ${all_packages}) - if(req_found) - message(STATUS "Package '${package_big}' requires '${req}', but it is not active") - else(req_found) - message(STATUS "Package '${package_big}' requires '${req}', but it is not found") - endif(req_found) - set(all_req_found) - endif(NOT req_found) - endforeach(req ${required}) + foreach(req ${required}) + set(req_found) + foreach(pack ${packages_big}) + if(${pack} STREQUAL ${req}) + set(req_found 1) + endif(${pack} STREQUAL ${req}) + endforeach(pack ${packages}) + if(NOT req_found) + set(req_found) + foreach(pack ${all_packages}) + if(${pack} STREQUAL ${req}) + set(req_found 1) + endif(${pack} STREQUAL ${req}) + endforeach(pack ${all_packages}) + if(req_found) + message(STATUS "Package '${package_big}' requires '${req}', but it is not active") + else(req_found) + message(STATUS "Package '${package_big}' requires '${req}', but it is not found") + endif(req_found) + set(all_req_found) + endif(NOT req_found) + endforeach(req ${required}) else(BUILD_QT_${package_upper}) - set(all_req_found) + set(all_req_found) endif(BUILD_QT_${package_upper}) - + if("${all_req_found}" EQUAL 1) - set(packages_big ${packages_big} ${package_big}) - set(packages ${packages} ${package}) - ## Load a package sources list. - foreach(d_source ${package}/ArrayOps2 ${d_generated_files}) - set(d_sources ${d_sources} ${CMAKE_BINARY_DIR}/qt/${d_source}.d) - if(EXISTS ${CMAKE_BINARY_DIR}/qt/${d_source}_aux.d) - set(d_sources ${d_sources} ${CMAKE_BINARY_DIR}/qt/${d_source}_aux.d) - endif(EXISTS ${CMAKE_BINARY_DIR}/qt/${d_source}_aux.d) - endforeach(d_source ${d_generated_files}) - set(classes ArrayOps ${classes}) - foreach(class ${classes}) - set(d_sources ${d_sources} ${CMAKE_BINARY_DIR}/qt/${package}/${class}.d) - set(cpp_sources ${cpp_sources} ${CMAKE_BINARY_DIR}/cpp/qt_${package}/${class}_shell.cpp) - if(EXISTS ${CMAKE_BINARY_DIR}/qt/${package}/${class}_aux.d) - set(d_sources ${d_sources} ${CMAKE_BINARY_DIR}/qt/${package}/${class}_aux.d) - endif(EXISTS ${CMAKE_BINARY_DIR}/qt/${package}/${class}_aux.d) - endforeach(class ${classes}) - set(files_for_gen ${files_for_gen} ${cpp_sources} ${d_sources}) + set(packages_big ${packages_big} ${package_big}) + set(packages ${packages} ${package}) + ## Load a package sources list. + foreach(d_source ${package}/ArrayOps2 ${d_generated_files}) + set(d_sources ${d_sources} ${CMAKE_BINARY_DIR}/qt/${d_source}.d) + if(EXISTS ${CMAKE_BINARY_DIR}/qt/${d_source}_aux.d) + set(d_sources ${d_sources} ${CMAKE_BINARY_DIR}/qt/${d_source}_aux.d) + endif(EXISTS ${CMAKE_BINARY_DIR}/qt/${d_source}_aux.d) + endforeach(d_source ${d_generated_files}) + set(classes ArrayOps ${classes}) + foreach(class ${classes}) + set(d_sources ${d_sources} ${CMAKE_BINARY_DIR}/qt/${package}/${class}.d) + set(cpp_sources ${cpp_sources} ${CMAKE_BINARY_DIR}/cpp/qt_${package}/${class}_shell.cpp) + if(EXISTS ${CMAKE_BINARY_DIR}/qt/${package}/${class}_aux.d) + set(d_sources ${d_sources} ${CMAKE_BINARY_DIR}/qt/${package}/${class}_aux.d) + endif(EXISTS ${CMAKE_BINARY_DIR}/qt/${package}/${class}_aux.d) + endforeach(class ${classes}) + set(files_for_gen ${files_for_gen} ${cpp_sources} ${d_sources}) + + foreach (cpp_source ${cpp_files}) + set(cpp_sources ${cpp_sources} ${CMAKE_SOURCE_DIR}/cpp/${cpp_source}.cpp) + endforeach(cpp_source ${cpp_files}) + foreach (cpp_source ${cpp_generated_files}) + set(cpp_sources ${cpp_sources} ${CMAKE_BINARY_DIR}/cpp/${cpp_source}.cpp) + endforeach(cpp_source ${cpp_generated_files}) + foreach(d_source ${d_qt_files}) + set(d_sources ${d_sources} ${CMAKE_SOURCE_DIR}/d${D_VERSION}/qt/${d_source}.d) + endforeach(d_source ${d_qt_files}) + foreach(d_source ${d_qtd_files}) + set(d_sources ${d_sources} ${CMAKE_SOURCE_DIR}/d${D_VERSION}/qtd/${d_source}.d) + endforeach(d_source ${d_qtd_files}) - foreach (cpp_source ${cpp_files}) - set(cpp_sources ${cpp_sources} ${CMAKE_SOURCE_DIR}/cpp/${cpp_source}.cpp) - endforeach(cpp_source ${cpp_files}) - foreach (cpp_source ${cpp_generated_files}) - set(cpp_sources ${cpp_sources} ${CMAKE_BINARY_DIR}/cpp/${cpp_source}.cpp) - endforeach(cpp_source ${cpp_generated_files}) - foreach(d_source ${d_version_files}) - set(d_sources ${d_sources} ${CMAKE_SOURCE_DIR}/qt/d${D_VERSION}/qt/${d_source}.d) - endforeach(d_source ${d_version_files}) - foreach(d_source ${d_files}) - set(d_sources ${d_sources} ${CMAKE_SOURCE_DIR}/qt/${d_source}.d) - endforeach(d_source ${d_files}) + if(NOT GENERATE_DI_FILES) + foreach(d_source ${d_sources}) + get_filename_component(path ${d_source} PATH) + get_filename_component(name ${d_source} NAME_WE) + regex_safe_string(cbd_safe_tmp ${CMAKE_CURRENT_BINARY_DIR}) + regex_safe_string(csd_safe_tmp ${CMAKE_CURRENT_SOURCE_DIR}) + regex_safe_string(ver_safe_tmp ${CMAKE_CURRENT_SOURCE_DIR}/qt/d${D_VERSION}) + set(regexp_str_tmp "(${ver_safe_tmp}/|${cbd_safe_tmp}/|${csd_safe_tmp}/|)(.+)") + string(REGEX REPLACE ${regexp_str_tmp} "\\2" ins_path "${path}") + install(FILES ${d_source} DESTINATION include/d/${ins_path} COMPONENT qtd RENAME ${name}.di) + endforeach(d_source ${d_sources}) + endif(NOT GENERATE_DI_FILES) - if(NOT GENERATE_DI_FILES) - foreach(d_source ${d_sources}) - get_filename_component(path ${d_source} PATH) - get_filename_component(name ${d_source} NAME_WE) - regex_safe_string(cbd_safe_tmp ${CMAKE_CURRENT_BINARY_DIR}) - regex_safe_string(csd_safe_tmp ${CMAKE_CURRENT_SOURCE_DIR}) - regex_safe_string(ver_safe_tmp ${CMAKE_CURRENT_SOURCE_DIR}/qt/d${D_VERSION}) - set(regexp_str_tmp "(${ver_safe_tmp}/|${cbd_safe_tmp}/|${csd_safe_tmp}/|)(.+)") - string(REGEX REPLACE ${regexp_str_tmp} "\\2" ins_path "${path}") - install(FILES ${d_source} DESTINATION include/d/${ins_path} COMPONENT qtd RENAME ${name}.di) - endforeach(d_source ${d_sources}) - endif(NOT GENERATE_DI_FILES) + ## Build the CPP part. + if(CPP_SHARED) + set(cpp_method SHARED) + else(CPP_SHARED) + set(cpp_method STATIC) + endif(CPP_SHARED) + add_library(cpp_${package} ${cpp_method} ${cpp_sources}) + set_property(TARGET cpp_${package} PROPERTY RUNTIME_OUTPUT_DIRECTORY lib) + set_property(TARGET cpp_${package} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/CMakeFiles) + set(link_cpp ${link_cpp} ${QT_QT${package_upper}_LIBRARY}) + if(CPP_SHARED) + else(CPP_SHARED) + ## Get an objects list. It will be used in building the D part. + foreach(cpp_source ${cpp_sources}) + set(cpp_source ${cpp_source}) + obj_path(cpp_source) + set(cpp_objs ${cpp_objs} ${CMAKE_BINARY_DIR}/CMakeFiles/cpp_${package}.dir/${cpp_source}${CMAKE_CXX_OUTPUT_EXTENSION}) + endforeach(cpp_source ${cpp_sources}) + endif(CPP_SHARED) - ## Build the CPP part. - if(CPP_SHARED) - set(cpp_method SHARED) - else(CPP_SHARED) - set(cpp_method STATIC) - endif(CPP_SHARED) - add_library(cpp_${package} ${cpp_method} ${cpp_sources}) - set_property(TARGET cpp_${package} PROPERTY RUNTIME_OUTPUT_DIRECTORY lib) - set_property(TARGET cpp_${package} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/CMakeFiles) - set(link_cpp ${link_cpp} ${QT_QT${package_upper}_LIBRARY}) - if(CPP_SHARED) - else(CPP_SHARED) - ## Get an objects list. It will be used in building the D part. - foreach(cpp_source ${cpp_sources}) - set(cpp_source ${cpp_source}) - obj_path(cpp_source) - set(cpp_objs ${cpp_objs} ${CMAKE_BINARY_DIR}/CMakeFiles/cpp_${package}.dir/${cpp_source}${CMAKE_CXX_OUTPUT_EXTENSION}) - endforeach(cpp_source ${cpp_sources}) - endif(CPP_SHARED) - - ## Settings for the D part. - set(lib_name qtd${package}) - if(BUILD_SHARED_LIBRARIES) - set(lib lib/${CMAKE_SHARED_LIBRARY_PREFIX}${lib_name}${CMAKE_SHARED_LIBRARY_SUFFIX}) - set(build_type SHARED) - else(BUILD_SHARED_LIBRARIES) - set(lib lib/${D_LIB_PREFIX}${lib_name}${D_LIB_SUFFIX}) - set(build_type STATIC) - endif(BUILD_SHARED_LIBRARIES) + ## Settings for the D part. + set(lib_name qtd${package}) + if(BUILD_SHARED_LIBRARIES) + set(lib lib/${CMAKE_SHARED_LIBRARY_PREFIX}${lib_name}${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(build_type SHARED) + else(BUILD_SHARED_LIBRARIES) + set(lib lib/${D_LIB_PREFIX}${lib_name}${D_LIB_SUFFIX}) + set(build_type STATIC) + endif(BUILD_SHARED_LIBRARIES) - ## Package dependencies. - foreach(req ${required}) - set(is_found) - foreach(pack ${packages_big}) - if("${pack}" STREQUAL "${req}") - set(is_found 1) - break(pack ${packages_big}) - endif("${pack}" STREQUAL "${req}") - endforeach(pack ${packages_big}) - if(NOT is_found) - message(FATAL_ERROR "Package ${package_big} requires ${req}, but it is not found") - endif(NOT is_found) - string(TOUPPER ${req} req_upper) - string(TOLOWER ${req} req_lower) - set(link_cpp ${link_cpp} cpp_${req_lower} ${QT_QT${req_upper}_LIBRARY}) - endforeach(req ${require}) - target_link_libraries(cpp_${package} ${link_cpp} ) - set(d_objs ${d_objs} ${objects}) + ## Package dependencies. + foreach(req ${required}) + set(is_found) + foreach(pack ${packages_big}) + if("${pack}" STREQUAL "${req}") + set(is_found 1) + break(pack ${packages_big}) + endif("${pack}" STREQUAL "${req}") + endforeach(pack ${packages_big}) + if(NOT is_found) + message(FATAL_ERROR "Package ${package_big} requires ${req}, but it is not found") + endif(NOT is_found) + string(TOUPPER ${req} req_upper) + string(TOLOWER ${req} req_lower) + set(link_cpp ${link_cpp} cpp_${req_lower} ${QT_QT${req_upper}_LIBRARY}) + endforeach(req ${require}) + target_link_libraries(cpp_${package} ${link_cpp} ) + set(d_objs ${d_objs} ${objects}) - if(CPP_SHARED) - ## Create an implib library which will be linked to the D part. - set(cpp_lib ${CMAKE_BINARY_DIR}/lib/libcpp_${package}.dll) - set(cpp_lib_native ${cpp_lib}) - make_native_path(cpp_lib_native) - set(d_implib ${CMAKE_BINARY_DIR}/CMakeFiles/${package}.dir/cpp_${package}.lib) - set(d_implib_native ${d_implib}) - make_native_path(d_implib_native) - add_custom_command( - OUTPUT "${d_implib}" - COMMAND "${IMPLIB}" - ARGS /system /PAGESIZE:32 ${d_implib_native} ${cpp_lib_native} - DEPENDS "cpp_${package}" - COMMENT "Creating implib ${lib_name}" - ) - install(FILES ${cpp_lib} COMPONENT qtd DESTINATION lib) - else(CPP_SHARED) - set(${package}_lib_param Qt${package_big}) - endif(CPP_SHARED) - ## Link the D part. - add_d_target(${lib_name} NOT_DETECT_DEPENDS TYPE ${build_type} INCLUDES ${QTD_IMPORT_PATH} SOURCES ${d_sources} OBJECTS ${cpp_objs} ${d_implib} - OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib DEPENDS ${d_implib} ) - install(FILES ${CMAKE_BINARY_DIR}/${lib} COMPONENT qtd DESTINATION lib) - ## Paths for the QtD libs. It is necessary for examples. - set(${package}_lib_param qtd${package} ${${package}_lib_param} ${link_example}) + if(CPP_SHARED) + ## Create an implib library which will be linked to the D part. + set(cpp_lib ${CMAKE_BINARY_DIR}/lib/libcpp_${package}.dll) + set(cpp_lib_native ${cpp_lib}) + make_native_path(cpp_lib_native) + set(d_implib ${CMAKE_BINARY_DIR}/CMakeFiles/${package}.dir/cpp_${package}.lib) + set(d_implib_native ${d_implib}) + make_native_path(d_implib_native) + add_custom_command( + OUTPUT "${d_implib}" + COMMAND "${IMPLIB}" + ARGS /system /PAGESIZE:32 ${d_implib_native} ${cpp_lib_native} + DEPENDS "cpp_${package}" + COMMENT "Creating implib ${lib_name}" + ) + install(FILES ${cpp_lib} COMPONENT qtd DESTINATION lib) + else(CPP_SHARED) + set(${package}_lib_param Qt${package_big}) + endif(CPP_SHARED) + ## Link the D part. + add_d_target(${lib_name} NOT_DETECT_DEPENDS TYPE ${build_type} INCLUDES ${QTD_IMPORT_PATH} SOURCES ${d_sources} OBJECTS ${cpp_objs} ${d_implib} + OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib DEPENDS ${d_implib} ) + install(FILES ${CMAKE_BINARY_DIR}/${lib} COMPONENT qtd DESTINATION lib) + ## Paths for the QtD libs. It is necessary for examples. + set(${package}_lib_param qtd${package} ${${package}_lib_param} ${link_example}) - ## Generate dependences for make (or nmake). - add_custom_target(${package}) - add_dependencies(${package} ${lib_name}) - add_dependencies(${lib_name} cpp_${package}) - foreach(depend ${required}) - string(TOLOWER ${depend} depend) - add_dependencies(cpp_${package} cpp_${depend}) - add_dependencies(${package} ${depend}) - endforeach(depend ${required}) - add_dependencies(allpackages ${package}) - - ## TODO: Do we need generating of *.di files? - if(GENERATE_DI_FILES) - regexseafestring(cbd_safe ${CMAKE_BINARY_DIR}) - regexseafestring(csd_safe ${CMAKE_SOURCE_DIR}) - set(regexp_str "(${csd}/qt/d${D_VERSION}|${csd_safe}|${cbd_safe})/([A-Za-z0-9\\-_\\\\/]+)[/]+([A-Za-z0-9\\-_\\\\]+).d") - foreach(source ${d_sources}) - # find_file(source ${source} PATHS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} - # ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}) - string(REGEX REPLACE ${regexp_str} "\\2" inc_path "${source}") - string(REGEX REPLACE ${regexp_str} "\\3" file_name "${source}") - set(interface_file_path ${CMAKE_BINARY_DIR}/d/${inc_path}) - set(interface_file "${interface_file_path}/${file_name}.di") - if(NOT "${file_name}" STREQUAL "QGlobal") - add_custom_command(OUTPUT "${interface_file}" - COMMAND "${DC}" - ARGS ${D_FLAGS} -o- -H -Hd${interface_file_path} ${source} - COMMENT "Generating header for ${source}" - DEPENDS ${source} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - ) - else(NOT "${file_name}" STREQUAL "QGlobal") ## The DMD frontend crashes on this file. - add_custom_command(OUTPUT "${interface_file}" - COMMAND ${CMAKE_COMMAND} -E make_directory ${interface_file_path} - COMMAND ${CMAKE_COMMAND} -E remove -f ${interface_file} - COMMAND ${CMAKE_COMMAND} -E copy ${source} ${interface_file} - COMMENT "" - DEPENDS ${source} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - ) - endif(NOT "${file_name}" STREQUAL "QGlobal" AND GENERATE_DI_FILES) - set(interfaces_list ${interfaces_list} ${interface_file_path}/${file_name}.di) - install(FILES ${interface_file} COMPONENT qtd DESTINATION include/d/${inc_path}) - endforeach(source) - endif(GENERATE_DI_FILES) + ## Generate dependences for make (or nmake). + add_custom_target(${package}) + add_dependencies(${package} ${lib_name}) + add_dependencies(${lib_name} cpp_${package}) + foreach(depend ${required}) + string(TOLOWER ${depend} depend) + add_dependencies(cpp_${package} cpp_${depend}) + add_dependencies(${package} ${depend}) + endforeach(depend ${required}) + add_dependencies(allpackages ${package}) + + ## TODO: Do we need generating of *.di files? + if(GENERATE_DI_FILES) + regexseafestring(cbd_safe ${CMAKE_BINARY_DIR}) + regexseafestring(csd_safe ${CMAKE_SOURCE_DIR}) + set(regexp_str "(${csd}/qt/d${D_VERSION}|${csd_safe}|${cbd_safe})/([A-Za-z0-9\\-_\\\\/]+)[/]+([A-Za-z0-9\\-_\\\\]+).d") + foreach(source ${d_sources}) + # find_file(source ${source} PATHS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} + # ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}) + string(REGEX REPLACE ${regexp_str} "\\2" inc_path "${source}") + string(REGEX REPLACE ${regexp_str} "\\3" file_name "${source}") + set(interface_file_path ${CMAKE_BINARY_DIR}/d/${inc_path}) + set(interface_file "${interface_file_path}/${file_name}.di") + if(NOT "${file_name}" STREQUAL "QGlobal") + add_custom_command(OUTPUT "${interface_file}" + COMMAND "${DC}" + ARGS ${D_FLAGS} -o- -H -Hd${interface_file_path} ${source} + COMMENT "Generating header for ${source}" + DEPENDS ${source} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + else(NOT "${file_name}" STREQUAL "QGlobal") ## The DMD frontend crashes on this file. + add_custom_command(OUTPUT "${interface_file}" + COMMAND ${CMAKE_COMMAND} -E make_directory ${interface_file_path} + COMMAND ${CMAKE_COMMAND} -E remove -f ${interface_file} + COMMAND ${CMAKE_COMMAND} -E copy ${source} ${interface_file} + COMMENT "" + DEPENDS ${source} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + endif(NOT "${file_name}" STREQUAL "QGlobal" AND GENERATE_DI_FILES) + set(interfaces_list ${interfaces_list} ${interface_file_path}/${file_name}.di) + install(FILES ${interface_file} COMPONENT qtd DESTINATION include/d/${inc_path}) + endforeach(source) + endif(GENERATE_DI_FILES) endif("${all_req_found}" EQUAL 1) endforeach(package_big ${packages_big}) -if(GENERATE_DI_FILES) +if(GENERATE_DI_FILES) add_custom_target(generate_headers ALL DEPENDS ${interfaces_list}) endif(GENERATE_DI_FILES) @@ -581,4 +585,4 @@ set(SECOND_RUN 0 CACHE INTERNAL "") -endif(NOT SECOND_RUN) +endif(NOT SECOND_RUN) diff -r 552647ec0f82 -r 96a75b1e5b26 boost-license-1.0.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/boost-license-1.0.txt Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff -r 552647ec0f82 -r 96a75b1e5b26 build/core.txt --- a/build/core.txt Thu May 13 21:01:24 2010 +0300 +++ b/build/core.txt Fri May 14 12:14:37 2010 +0300 @@ -1,4 +1,4 @@ -configure_file(qt/QDefines.d.inc qt/QDefines.d) +configure_file(d${D_VERSION}/qt/QDefines.d.inc qt/QDefines.d) ## Module specific cpp files. set (cpp_files qt_qtd/qtd_core qt_qtd/ArrayOpsPrimitive_shell @@ -10,38 +10,38 @@ qt_core/QModelIndex_shell qt_core/QMetaType_shell qt_core/QMetaObject_shell) ## Module specific d files. -set (d_files +set (d_qt_files QGlobal - qtd/Array - qtd/ArrayOpsPrimitive - qtd/Traits core/QString core/QMetaType core/QMetaObject - core/QTypeInfo core/QList - qtd/Atomic - qtd/MetaMarshall - qtd/MOC - qtd/Meta - qtd/util/Tuple - qtd/ctfe/Integer - qtd/ctfe/String - qtd/ctfe/Format - ) -set (d_version_files - QtdObject - Signal qtd/Str core/QLine core/QLineF core/QModelIndex core/QRect core/QRectF core/QSize core/QSizeF core/QPoint core/QPointF - core/QVariant) + core/QVariant + ) +set (d_qtd_files + QtdObject + Signal + Str + Atomic + MetaMarshall + MOC + Meta + Array + ArrayOpsPrimitive + util/Tuple + ctfe/Integer + ctfe/String + ctfe/Format + ) set (d_generated_files core/Qt QDefines) ## Classes. -set (classes +set (classes QChildEvent QCoreApplication QEvent @@ -81,5 +81,6 @@ QLibraryInfo QXmlStreamEntityResolver QFileSystemWatcher + QDynamicPropertyChangeEvent ) - + diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/CMakeLists.txt Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,23 @@ +project (qt_d D) + +set(QT_SRCS_D +QtdObject.d +QGlobal.d + +core/QChildEvent.d +core/QCoreApplication.d +core/QEvent.d +core/QEventLoop.d +core/QObject.d +core/QTimerEvent.d +core/QTranslator.d +core/Qt.d + +qtd/Str.d +) + +#add_subdirectory(core) +#add_subdirectory(qtd) + +#add_library(qt_d STATIC ${QT_CORE_SRCS_D} ${QT_QTD_SRCS_D} ${QT_SRCS_D}) +add_library(qt_d STATIC ${QT_SRCS_D}) diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/QDefines.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/QDefines.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,4 @@ +module qt.QDefines; + +const char[] QT_VERSION_STR = "4.5.2"; +const int QT_VERSION = 263426; diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/QDefines.d.inc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/QDefines.d.inc Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,4 @@ +module qt.QDefines; + +const char[] QT_VERSION_STR = "@QTD_VERSION_STR@"; +const int QT_VERSION = @QTD_VERSION@; \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/QGlobal.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/QGlobal.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,746 @@ +module qt.QGlobal; + +public import qt.qtd.Str; +public import qt.QDefines; + +version (Tango) +{ + import tango.io.Stdout; + void writeln(string s) + { + Stdout(s).newline; + } + package import tango.stdc.stdlib, + tango.core.Memory; +} +else +{ + import std.stdio; + package import std.c.stdlib, + core.memory; +} + +T static_cast(T, U)(U obj) +{ + return cast(T)cast(void*)obj; +} + +template QT_BEGIN_NAMESPACE() { +} + +template QT_END_NAMESPACE() { +} + +template QT_BEGIN_HEADER() { +} + +template QT_END_HEADER() { +} + +mixin QT_BEGIN_HEADER; +mixin QT_BEGIN_NAMESPACE; + +//TODO: this sucks +extern(C) void qtd_dummy() {} +// Defined in QObject.d +extern(C) void qtd_delete_d_qobject(void* dPtr); + +version(cpp_shared) +{ + extern (C) void qtd_core_initCallBacks(void* toUtf8, void* dummy); + static this() { + qtd_core_initCallBacks(&qtd_toUtf8, &qtd_dummy); + } + + extern (C) void qtd_QObjectEntity_initCallBacks(void* del_d_obj); + static this() { + qtd_QObjectEntity_initCallBacks(&qtd_delete_d_qobject); + } +} + +string tr(string arg) { + return arg; +} + +/* + can be used like #if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0)) +*/ +bool QT_VERSION_CHECK( ushort major, ushort minor, ushort patch ) +{ + return cast(bool)((major<<16)|(minor<<8)|(patch)); +} +//TODO(katrina) get this from the C++ side +const char[] QT_PACKAGEDATE_STR = "2008-09-27"; +//TODO(katrina) get this from the C++ side +const char[] QT_PACKAGE_TAG = "gc9953de622c6a0f655322e0d9f5bd6dc2803b470"; + +/* + Size-dependent types (architechture-dependent byte order) + + Make sure to update QMetaType when changing these typedefs +*/ + +alias char qint8; /* 8 bit signed */ +alias char quint8; /* 8 bit unsigned */ +alias short qint16; /* 16 bit signed */ +alias ushort quint16; /* 16 bit unsigned */ +alias int qint32; /* 32 bit signed */ +alias uint quint32; /* 32 bit unsigned */ +alias long qint64; /* 64 bit signed */ +alias ulong quint64; /* 64 bit unsigned */ + +version (X86) +{ + alias quint32 quintptr; + alias qint32 qptrdiff; +} +else version (X86_64) +{ + alias quint64 quintptr; + alias qint64 qptrdiff; +} + +const byte QT_POINTER_SIZE = 8; + +alias int QNoImplicitBoolCast; + +alias double qreal; + + +/* + Utility macros and inline functions + TODO(katrina) see if we need to do anything to make these + able to be evaluated at compile time +*/ + +T qAbs(T)(T t) { return t >= 0 ? t : -t; } + +int qRound(qreal d) +{ return d >= 0.0 ? cast(int)(d + 0.5) : cast(int)(d - cast(int)(d-1) + 0.5) + cast(int)(d-1); } + +qint64 qRound64(qreal d) +{ return d >= 0.0 ? cast(qint64)(d + 0.5) : cast(qint64)(d - cast(qint64)(d-1) + 0.5) + cast(qint64)(d-1); } + +T qMin(T)(T a,T b) { if (a < b) return a; return b; } +T qMax(T)(T a, T b) { if (a < b) return b; return a; } +T qBound(T)(T min, T val,T max) { return qMax(min, qMin(max, val)); } + +/* + Data stream functions are provided by many classes (defined in qdatastream.h) +*/ + +//class QDataStream; + +/* + System information +*/ + +class QSysInfo { +public: + enum Sizes { + WordSize = ((void *).sizeof<<3) + }; + + enum Endian { + BigEndian, + LittleEndian, + ByteOrder = BigEndian + }; + /* needed to bootstrap qmake */ + static const int ByteOrder; + + enum WinVersion { + WV_32s = 0x0001, + WV_95 = 0x0002, + WV_98 = 0x0003, + WV_Me = 0x0004, + WV_DOS_based= 0x000f, + + WV_NT = 0x0010, + WV_2000 = 0x0020, + WV_XP = 0x0030, + WV_2003 = 0x0040, + WV_VISTA = 0x0080, + WV_NT_based = 0x00f0, + + WV_CE = 0x0100, + WV_CENET = 0x0200, + WV_CE_5 = 0x0300, + WV_CE_6 = 0x0400, + WV_CE_based = 0x0f00 + }; + static const WinVersion WindowsVersion; + static WinVersion windowsVersion(); + + enum MacVersion { + MV_Unknown = 0x0000, + + /* version */ + MV_9 = 0x0001, + MV_10_0 = 0x0002, + MV_10_1 = 0x0003, + MV_10_2 = 0x0004, + MV_10_3 = 0x0005, + MV_10_4 = 0x0006, + MV_10_5 = 0x0007, + + /* codenames */ + MV_CHEETAH = MV_10_0, + MV_PUMA = MV_10_1, + MV_JAGUAR = MV_10_2, + MV_PANTHER = MV_10_3, + MV_TIGER = MV_10_4, + MV_LEOPARD = MV_10_5 + }; + static const MacVersion MacintoshVersion; +}; + + +extern(C) stringz qtd_qVersion(); +/// +string qVersion() +{ + return fromStringz(qtd_qVersion); +} + +extern(C) bool qtd_qSharedBuild(); +/// +bool qSharedBuild() +{ + return qtd_qSharedBuild; +} + +/// +int qMacVersion() { return QSysInfo.MacintoshVersion; } + +/// +void qUnused(T)(T x) { cast(void) x; } +/// +void Q_UNUSED(T)(T x) { qUnused(x); } + +/* + Debugging and error handling +*/ + +//class QString; +//char[] qPrintable(QString string) { string.toLocal8Bit().constData(); } +//TODO(katrina) These should probably actually call into the c++ functions +void qFatal(string str) +{ + throw new Exception(str); +} + +void qDebug( char[] str ) /* print debug message */ +{ writeln(str); } + +extern (C) void Qt_qWarning( char * ); + +void qWarning(char[] str) /* print warning message */ +{ writeln(str); } + +//QString qt_error_string(int errorCode = -1); +void qCritical(char[] str) /* print critical message */ +{ writeln(str); } + +/* + Forward declarations only. + + In order to use the qDebug() stream, you must #include +*/ +//class QDebug; +//class QNoDebug; +//QDebug qDebug(); +//QDebug qWarning(); +//QDebug qCritical(); + +void qt_noop() {} +//TODO(katrina) Implement these +void qt_assert(char[] assertion, char[] file, int line); + +void qt_assert_x(char[] where, char[] what, char[] file, int line); + +void qt_check_pointer(char[], int); + +enum QtMsgType { QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg, QtSystemMsg = QtCriticalMsg }; + +void qt_message_output(QtMsgType, char[] buf); +//class QtMsgHandler; +//QtMsgHandler qInstallMsgHandler(QtMsgHandler); + +// forward declaration, since qatomic.h needs qglobal.h +class QBasicAtomicPointer(T); + +// POD for Q_GLOBAL_STATIC +class QGlobalStatic(T) +{ +public: + QBasicAtomicPointer!(T) pointer; + bool destroyed; +}; + +// Created as a function-local static to delete a QGlobalStatic +class QGlobalStaticDeleter(T) +{ +public: + QGlobalStatic!(T) globalStatic; + this(QGlobalStatic!(T) _globalStatic) { + globalStatic(_globalStatic); + } + + ~this() + { + delete globalStatic.pointer; + globalStatic.pointer = 0; + globalStatic.destroyed = true; + } +}; + +class QBool +{ + bool b; + +public: + this(bool B) { b = B; } +// void *() const +// { return b ? static_cast(this) : static_cast(0); } +} + +bool qFuzzyCompare(double p1, double p2) +{ + return (qAbs(p1 - p2) <= 0.000000000001 * qMin(qAbs(p1), qAbs(p2))); +} + +bool qFuzzyCompare(float p1, float p2) +{ + return (qAbs(p1 - p2) <= 0.00001f * qMin(qAbs(p1), qAbs(p2))); +} + +/* + This function tests a double for a null value. It doesn't + check whether the actual value is 0 or close to 0, but whether + it is binary 0. +*/ +bool qIsNull(double d) +{ + union U { + double d; + quint64 u; + }; + U val; + val.d = d; + return val.u == cast(quint64)(0); +} + +/* + This function tests a float for a null value. It doesn't + check whether the actual value is 0 or close to 0, but whether + it is binary 0. +*/ +bool qIsNull(float f) +{ + union U { + float f; + quint32 u; + }; + U val; + val.f = f; + return val.u == 0u; +} + +/* + Compilers which follow outdated template instantiation rules + require a class to have a comparison operator to exist when + a QList of this type is instantiated. It's not actually + used in the list, though. Hence the dummy implementation. + Just in case other code relies on it we better trigger a warning + mandating a real implementation. +*/ + + +/* + QTypeInfo - type trait functionality + qIsDetached - data sharing functionality +*/ + +/* + The catch-all template. +*/ +/* +bool qIsDetached(T)(T) { return true; } + +class QTypeInfossss(T) +{ +public: + enum { + isPointer = false, + isComplex = true, + isStatic = true, + isLarge = ((T).sizeof>(void*).sizeof), + isDummy = false + }; +}; + +class QTypeInfo(T) +{ +public: + enum { + isPointer = true, + isComplex = false, + isStatic = false, + isLarge = false, + isDummy = false + }; +}; +*/ + +/* + Specialize a specific type with: + + Q_DECLARE_TYPEINFO(type, flags); + + where 'type' is the name of the type to specialize and 'flags' is + logically-OR'ed combination of the flags below. +*/ +enum { /* TYPEINFO flags */ + Q_COMPLEX_TYPE = 0, + Q_PRIMITIVE_TYPE = 0x1, + Q_STATIC_TYPE = 0, + Q_MOVABLE_TYPE = 0x2, + Q_DUMMY_TYPE = 0x4 +}; + +/* + Specialize a shared type with: + + Q_DECLARE_SHARED(type); + + where 'type' is the name of the type to specialize. NOTE: shared + types must declare a 'bool isDetached(void) const;' member for this + to work. +*/ +void qSwap_helper(T)(ref T value1, ref T value2, T*) +{ + T t = value1; + value1 = value2; + value2 = t; +} +bool qIsDetached(T)(ref T t) { return t.isDetached(); } +void qSwap_helper(T)(ref T value1, ref T value2, T*) +{ + const T.DataPtr t = value1.data_ptr(); + value1.data_ptr() = value2.data_ptr(); + value2.data_ptr() = t; +} + +void qSwap(T)(ref T value1, ref T value2) +{ + T t = value1; + value1 = value2; + value2 = t; +} + +/* + QTypeInfo primitive specializations + TODO(katrina) Find out what we need to do here +*/ +/* +Q_DECLARE_TYPEINFO(bool, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(char, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(signed char, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(uchar, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(short, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(ushort, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(int, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(uint, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(long, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(ulong, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(qint64, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(quint64, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(float, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(double, Q_PRIMITIVE_TYPE); +#ifndef Q_OS_DARWIN +Q_DECLARE_TYPEINFO(long double, Q_PRIMITIVE_TYPE); +#endif +*/ +/* + These functions make it possible to use standard C++ functions with + a similar name from Qt header files (especially template classes). + TODO(katrina) Implement these +*/ +void * qMalloc(size_t size); +void qFree(void * ptr); +void * qRealloc(void * ptr, size_t size); +void * qMemCopy(void * dest, void * src, size_t n); +void * qMemSet(void * dest, int c, size_t n); + +struct QFlags(Enum) +{ +private: + alias void **Zero; + int i; + +public: + alias Enum enum_type; + + public static QFlags!(Enum) opCall(Enum)(QFlags f) { + QFlags!(Enum) res; + res.i = f.i; + return res; + } + + public static QFlags opCall(Enum)(Enum f) { + QFlags!(Enum) res; + res.i = f; + return res; + } + + public static QFlags opCall(Enum)(int f) { + QFlags!(Enum) res; + res.i = cast(Enum) f; + return res; + } + +// this(Zero = 0) : i(0) {} +// this(QFlag f) : i(f) {} + +// QFlags!(Enum) opAssign(QFlags f) { i = f.i; return *this; } + QFlags!(Enum) opAssign(int f) { i = f; return *this; } + QFlags!(Enum) opAndAssign(int mask) { i &= mask; return *this; } + QFlags!(Enum) opAndAssign(uint mask) { i &= mask; return *this; } + QFlags!(Enum) opOrAssign(QFlags f) { i |= f.i; return *this; } + QFlags!(Enum) opOrAssign(Enum f) { i |= f; return *this; } + QFlags!(Enum) opXorAssign(QFlags f) { i ^= f.i; return *this; } + QFlags!(Enum) opXorAssign(Enum f) { i ^= f; return *this; } + + int toInt() { return i; } + + QFlags!(Enum) opOr(QFlags f) { QFlags g; g.i = i | f.i; return g; } + QFlags!(Enum) opOr(Enum f) { QFlags g; g.i = i | f; return g; } + QFlags!(Enum) opXor(QFlags f) { QFlags g; g.i = i ^ f.i; return g; } + QFlags!(Enum) opXor(Enum f) { QFlags g; g.i = i ^ f; return g; } + QFlags!(Enum) opAnd(int mask) { QFlags g; g.i = i & mask; return g; } + QFlags!(Enum) opAnd(uint mask) { QFlags g; g.i = i & mask; return g; } + QFlags!(Enum) opAnd(Enum f) { QFlags g; g.i = i & f; return g; } + QFlags!(Enum) opCom() { QFlags g; g.i = ~i; return g; } + +// bool operator!() { return !i; } + +// bool testFlag(Enum f) { return i & f; } +} + +/* TODO typesafety +#define Q_DECLARE_FLAGS(Flags, Enum)\ +typedef QFlags Flags; +#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags) \ +QFlags operator|(Flags::enum_type f1, Flags::enum_type f2) \ +{ return QFlags(f1) | f2; } \ +QFlags operator|(Flags::enum_type f1, QFlags f2) \ +{ return f2 | f1; } +*/ + +char[] QT_TR_NOOP(char[] x) { return x; } +char[] QT_TRANSLATE_NOOP(char[] s, char[] x) { return x; } +char[] QT_TRANSLATE_NOOP3(char[] s, char[] x, char[] comment) { return x; } + +//class QByteArray; +//QByteArray qgetenv(char[] varName); +//bool qputenv(char[] varName, QByteArray value); + +int qIntCast(double f) { return cast(int)(f); } +int qIntCast(float f) { return cast(int)(f); } + +/* + Reentrant versions of basic rand() functions for random number generation +*/ +void qsrand(uint seed); +int qrand(); + + +/* + This gives us the possibility to check which modules the user can + use. These are purely compile time checks and will generate no code. +*/ + +/* Qt modules */ + +const ushort QT_MODULE_CORE = 0x0001; +const ushort QT_MODULE_GUI = 0x0002; +const ushort QT_MODULE_NETWORK = 0x0004; +const ushort QT_MODULE_OPENGL = 0x0008; +const ushort QT_MODULE_SQL = 0x0010; +const ushort QT_MODULE_XML = 0x0020; +const ushort QT_MODULE_QT3SUPPORTLIGHT = 0x0040; +const ushort QT_MODULE_QT3SUPPORT = 0x0080; +const ushort QT_MODULE_SVG = 0x0100; +const ushort QT_MODULE_ACTIVEQT = 0x0200; +const ushort QT_MODULE_GRAPHICSVIEW = 0x0400; +const ushort QT_MODULE_SCRIPT = 0x0800; +const ushort QT_MODULE_XMLPATTERNS = 0x1000; +const ushort QT_MODULE_HELP = 0x2000; +const ushort QT_MODULE_TEST = 0x4000; +const ushort QT_MODULE_DBUS = 0x8000; + +/* Qt editions */ + +const ushort QT_EDITION_CONSOLE = (QT_MODULE_CORE + | QT_MODULE_NETWORK + | QT_MODULE_SQL + | QT_MODULE_SCRIPT + | QT_MODULE_XML + | QT_MODULE_XMLPATTERNS + | QT_MODULE_TEST + | QT_MODULE_DBUS); +const ushort QT_EDITION_DESKTOPLIGHT = (QT_MODULE_CORE + | QT_MODULE_GUI + | QT_MODULE_QT3SUPPORTLIGHT + | QT_MODULE_TEST + | QT_MODULE_DBUS); +const ushort QT_EDITION_OPENSOURCE = (QT_MODULE_CORE + | QT_MODULE_GUI + | QT_MODULE_NETWORK + | QT_MODULE_OPENGL + | QT_MODULE_SQL + | QT_MODULE_XML + | QT_MODULE_XMLPATTERNS + | QT_MODULE_SCRIPT + | QT_MODULE_QT3SUPPORTLIGHT + | QT_MODULE_QT3SUPPORT + | QT_MODULE_SVG + | QT_MODULE_GRAPHICSVIEW + | QT_MODULE_HELP + | QT_MODULE_TEST + | QT_MODULE_DBUS); +const ushort QT_EDITION_DESKTOP = (QT_EDITION_OPENSOURCE + | QT_MODULE_ACTIVEQT); +const ushort QT_EDITION_UNIVERSAL = QT_EDITION_DESKTOP; +const ushort QT_EDITION_ACADEMIC = QT_EDITION_DESKTOP; +const ushort QT_EDITION_EDUCATIONAL = QT_EDITION_DESKTOP; +const ushort QT_EDITION_EVALUATION = QT_EDITION_DESKTOP; + +mixin QT_END_NAMESPACE; + +private +struct Align +{ + ubyte a; + void* b; +} + +private +const PTR_ALIGN = Align.tupleof[1].alignof; + +private +template AlignPad(size_t base, size_t aligned) +{ + static if( aligned == 0 ) + const AlignPad = base; + else + const AlignPad = ((base+PTR_ALIGN-1)/PTR_ALIGN)*PTR_ALIGN + + aligned; +} + +template InstanceSize(T) +{ + static if( is( T == Object ) ) + const InstanceSize = 2*(void*).sizeof; + else + const InstanceSize = Max!( + AlignPad!( + InstanceSize!(Super!(T)), + InterfaceCount!(T)*(void*).sizeof), + + AlignPad!( + InstanceSizeImpl!(T, 0), + + InterfaceCount!(T)*(void*).sizeof)); +} + +private +template Super(T) +{ + static if( is( T S == super ) ) + alias First!(S) Super; + else + static assert(false, "Can't get super of "~T.mangleof); +} + +private +template First(T) +{ + alias T First; +} + +private +template First(T, Ts...) +{ + alias T First; +} + +private +template InstanceSizeImpl(T, size_t i) +{ + static if( i < T.tupleof.length ) + const InstanceSizeImpl = Max!( + T.tupleof[i].offsetof + T.tupleof[i].sizeof, + InstanceSizeImpl!(T, i+1)); + else + // This is necessary to account for classes without member + // variables. + const InstanceSizeImpl = 2*(void*).sizeof; +} + +private +template Max(size_t a, size_t b) +{ + static if( a > b ) + const Max = a; + else + const Max = b; +} + +private +template InterfaceCount(T) +{ + static if( is( T == Object ) ) + const InterfaceCount = 0u; + else static if( is( T S == super ) ) + const InterfaceCount = InterfaceCountImpl!(S); +} + +private +template InterfaceCountImpl(TBase, TInterfaces...) +{ + const InterfaceCountImpl = TInterfaces.length; +} + +/+ +scope class StackObject(C) +{ + byte[InstanceSize!(C)] data; + bool constructed; + + C opCall(A...)(A args) + { + assert(!constructed); + + auto r = new(&data)C(args); + r.__stackAllocated = true; + constructed = true; + + return r; + } + + ~this() + { + if (constructed) + { + auto obj = cast(C)&data; + delete obj; + } + } +} ++/ + +alias void DArray; + +mixin QT_END_HEADER; + diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/QObjectDefs.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/QObjectDefs.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,262 @@ +module qt.QObjectDefs; + +//import qt.core.QGlobal; +//import qt.core.Qt; +import QGlobal; + +const byte Q_MOC_OUTPUT_REVISION = 59; + +template QT_TR_FUNCTIONS_NOUTF8() +{ + static QString tr(char[] s, char[] c = null) + { return staticMetaObject.tr(s, c); } + static QString tr(char[] s, char[] c, int n) + { return staticMetaObject.tr(s, c, n); } +} + +template QT_TR_FUNCTIONS_UTF8() +{ + static QString trUtf8(char[] s, char[] c = null) + { return staticMetaObject.trUtf8(s, c); } + static QString trUtf8(char[] s, char[] c, int n) + { return staticMetaObject.trUtf8(s, c, n); } +} + +template QT_TR_FUNCTIONS() +{ + mixin QT_TR_FUNCTIONS_NOUTF8; + mixin QT_TR_FUNCTIONS_UTF8; +} + +template Q_OBJECT_CHECK() +{ + void qt_check_for_QOBJECT_macro(T)(T _q_argument) const + { int i = qYouForgotTheQ_OBJECT_Macro(this, _q_argument); i = i; } +} + +int qYouForgotTheQ_OBJECT_Macro(T)(T, T) { return 0; } + +void qYouForgotTheQ_OBJECT_Macro(T1,T2)(T1, T2) {} + +template Q_OBJECT() +{ + public mixin Q_OBJECT_CHECK; + public static const QMetaObject staticMetaObject; + public const QMetaObject *metaObject() const{} + public void *qt_metacast(const char *){} + public mixin QT_TR_FUNCTIONS; + public int qt_metacall(QMetaObject.Call, int, void **){} +} + +template Q_OBJECT_FAKE() +{ + mixin Q_OBJECT; +} + +template Q_GADGET() +{ + public static const QMetaObject staticMetaObject; +} + +char[] METHOD( char[] a ) { return "0"~a; } +char[] SLOT( char[] a ) { return "1"~a; } +char[] SIGNAL( char[] a ) { return "2"~a; } + +version(QT3_SUPPORT) { + const byte METHOD_CODE = 0; // member type codes + const byte SLOT_CODE = 1; + const byte SIGNAL_CODE = 2; +} + +const byte QMETHOD_CODE = 0; // member type codes +const byte QSLOT_CODE = 1; +const byte QSIGNAL_CODE = 2; + +QArgument!(T) Q_ARG(T)(char [] type, T data) + { return QArgument!(T)(type, data); } + +QReturnArgument!(T) Q_RETURN_ARG(T)(char [] type, T data) + { return QReturnArgument!(T)(type, data); } + +class QGenericArgument +{ +public: + this(char[] aName = null, const void *aData = null) + { _data = aData; _name = aName; } + void *data() const { return cast(void *)(_data); } + char[] name() { return _name; } + +private: + const void *_data; + char[] _name; +}; + +class QGenericReturnArgument : QGenericArgument +{ +}; + +class QArgument(T) : QGenericArgument +{ +public: + this(char[] aName, T aData) + { this(aName, cast(void *)aData); } +}; + +class QReturnArgument(T) : QGenericReturnArgument +{ +public: + this(char[] aName, T aData) + { this(aName, cast(void *)aData); } +}; + +//TODO(katrina) enable this when all the classes it uses are available +/*struct QMetaObject +{ + char[] className() const; + const QMetaObject *superClass() const; + + //TODO(katrina) enable QObject cast(QObject obj) const; + + // ### Qt 4: Merge overloads + QString tr(const char *s, const char *c) const; + QString trUtf8(const char *s, const char *c) const; + QString tr(const char *s, const char *c, int n) const; + QString trUtf8(const char *s, const char *c, int n) const; + + int methodOffset() const; + int enumeratorOffset() const; + int propertyOffset() const; + int classInfoOffset() const; + + int methodCount() const; + int enumeratorCount() const; + int propertyCount() const; + int classInfoCount() const; + + int indexOfMethod(const char *method) const; + int indexOfSignal(const char *signal) const; + int indexOfSlot(const char *slot) const; + int indexOfEnumerator(const char *name) const; + int indexOfProperty(const char *name) const; + int indexOfClassInfo(const char *name) const; + + QMetaMethod method(int index) const; + QMetaEnum enumerator(int index) const; + QMetaProperty property(int index) const; + QMetaClassInfo classInfo(int index) const; + QMetaProperty userProperty() const; + + static bool checkConnectArgs(const char *signal, const char *method); + static QByteArray normalizedSignature(const char *method); + static QByteArray normalizedType(const char *type); + + // internal index-based connect + static bool connect(const QObject *sender, int signal_index, + const QObject *receiver, int method_index, + int type = 0, int *types = 0); + // internal index-based disconnect + static bool disconnect(const QObject *sender, int signal_index, + const QObject *receiver, int method_index); + // internal slot-name based connect + static void connectSlotsByName(QObject *o); + + // internal index-based signal activation + static void activate(QObject *sender, int signal_index, void **argv); + static void activate(QObject *sender, int from_signal_index, int to_signal_index, void **argv); + static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv); + static void activate(QObject *sender, const QMetaObject *, int from_local_signal_index, int to_local_signal_index, void **argv); + // internal guarded pointers + static void addGuard(QObject **ptr); + static void removeGuard(QObject **ptr); + static void changeGuard(QObject **ptr, QObject *o); + + static bool invokeMethod(QObject *obj, const char *member, + qt.core.Qt.ConnectionType, + QGenericReturnArgument ret, + QGenericArgument val0 = QGenericArgument(0), + QGenericArgument val1 = QGenericArgument(), + QGenericArgument val2 = QGenericArgument(), + QGenericArgument val3 = QGenericArgument(), + QGenericArgument val4 = QGenericArgument(), + QGenericArgument val5 = QGenericArgument(), + QGenericArgument val6 = QGenericArgument(), + QGenericArgument val7 = QGenericArgument(), + QGenericArgument val8 = QGenericArgument(), + QGenericArgument val9 = QGenericArgument()); + + static bool invokeMethod(QObject *obj, const char *member, + QGenericReturnArgument ret, + QGenericArgument val0 = QGenericArgument(0), + QGenericArgument val1 = QGenericArgument(), + QGenericArgument val2 = QGenericArgument(), + QGenericArgument val3 = QGenericArgument(), + QGenericArgument val4 = QGenericArgument(), + QGenericArgument val5 = QGenericArgument(), + QGenericArgument val6 = QGenericArgument(), + QGenericArgument val7 = QGenericArgument(), + QGenericArgument val8 = QGenericArgument(), + QGenericArgument val9 = QGenericArgument()) + { + return invokeMethod(obj, member, qt.core.Qt.AutoConnection, ret, val0, val1, val2, val3, + val4, val5, val6, val7, val8, val9); + } + + static bool invokeMethod(QObject *obj, const char *member, + qt.core.Qt.ConnectionType type, + QGenericArgument val0 = QGenericArgument(0), + QGenericArgument val1 = QGenericArgument(), + QGenericArgument val2 = QGenericArgument(), + QGenericArgument val3 = QGenericArgument(), + QGenericArgument val4 = QGenericArgument(), + QGenericArgument val5 = QGenericArgument(), + QGenericArgument val6 = QGenericArgument(), + QGenericArgument val7 = QGenericArgument(), + QGenericArgument val8 = QGenericArgument(), + QGenericArgument val9 = QGenericArgument()) + { + return invokeMethod(obj, member, type, QGenericReturnArgument(), val0, val1, val2, + val3, val4, val5, val6, val7, val8, val9); + } + + + static bool invokeMethod(QObject *obj, const char *member, + QGenericArgument val0 = QGenericArgument(0), + QGenericArgument val1 = QGenericArgument(), + QGenericArgument val2 = QGenericArgument(), + QGenericArgument val3 = QGenericArgument(), + QGenericArgument val4 = QGenericArgument(), + QGenericArgument val5 = QGenericArgument(), + QGenericArgument val6 = QGenericArgument(), + QGenericArgument val7 = QGenericArgument(), + QGenericArgument val8 = QGenericArgument(), + QGenericArgument val9 = QGenericArgument()) + { + return invokeMethod(obj, member, qt.core.Qt.AutoConnection, QGenericReturnArgument(), val0, + val1, val2, val3, val4, val5, val6, val7, val8, val9); + } + + enum Call { + InvokeMetaMethod, + ReadProperty, + WriteProperty, + ResetProperty, + QueryPropertyDesignable, + QueryPropertyScriptable, + QueryPropertyStored, + QueryPropertyEditable, + QueryPropertyUser + }; + +version(QT3_SUPPORT) { + const char *superClassName() const; +} + + struct d_struct{ // private data + const QMetaObject *superdata; + const char *stringdata; + const uint *data; + const QMetaObject **extradata; + }; + d_struct d; +}; +*/ diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/QtdObject.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/QtdObject.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,71 @@ +/** +* +* Copyright: Copyright QtD Team, 2008-2009 +* License: = connections.length) + connections.length = signalId + 1; + auto slot = connections[signalId].addSlot!(slotListId)(SlotType!(slotListId)(receiver, invoker, flags)); + + static if (slot.isDelegate) + { + if (!(flags & ConnectionFlags.NoObject)) + receivers.add(_d_toObject(receiver.context), &onReceiverDisposed); + } + + if (signalEvent && connections[signalId].slotCount == 1) + signalEvent(signalId, SignalEventId.firstSlotConnected); + + return slot; + } + + void onReceiverDisposed(Object receiver) + { + synchronized(this) + { + foreach(ref c; connections) + c.onReceiverDisposed(receiver); + receivers.removeAll(receiver); + } + } + + private void removeSlot(int slotListId)(int signalId, int slotId) + { + auto slot = connections[signalId].getSlotList!(slotListId).get(slotId); + static if (slot.isDelegate) + { + if (auto obj = slot.getObject) + receivers.remove(obj, &onReceiverDisposed); + } + + connections[signalId].removeSlot!(slotListId)(slotId); + + if (signalEvent && !connections[signalId].slotCount) + signalEvent(signalId, SignalEventId.lastSlotDisconnected); + } + + + size_t slotCount(int signalId) + { + synchronized(this) + { + auto con = getConnections(signalId); + if (con) + return con.slotCount; + return 0; + } + } + + void connect(Receiver)(int signalId, Receiver receiver, + Dg invoker, ConnectionFlags flags) + { + synchronized(this) + { + static if (is(typeof(receiver.context))) + { + Object obj; + if ((flags & ConnectionFlags.NoObject)) + { + // strong by default + if (flags & ConnectionFlags.Weak) + addSlot!(SlotListId.Weak)(signalId, receiver, invoker, flags); + else + addSlot!(SlotListId.Strong)(signalId, receiver, invoker, flags); + } + else + { + // weak by default + if (flags & ConnectionFlags.Strong) + addSlot!(SlotListId.Strong)(signalId, receiver, invoker, flags); + else + addSlot!(SlotListId.Weak)(signalId, receiver, invoker, flags); + } + } + else + { + flags |= ConnectionFlags.NoObject; + addSlot!(SlotListId.Func)(signalId, receiver, invoker, flags); + } + } + } + + void disconnect(Receiver)(int signalId, Receiver receiver) + { + synchronized(this) + { + auto cons = getConnections(signalId); + if (!cons) + return; + + // if called from a slot being executed by this signal, delay disconnection + // until all slots has been called. + if (cons.isInUse) + { + cons.addDelayedDisconnect(receiver); + return; + } + + TOP: + foreach (slotListId, e; cons.slotLists.tupleof) + { + /// COMPILER BUG: ReceiverType is evaluated to expression instead of type. + static if (is(typeof(cons.ReceiverType!(slotListId)) == Receiver)) + { + auto slotList = cons.getSlotList!(slotListId); + for (int slotId; slotId < slotList.length;) + { + auto slot = slotList.get(slotId); + static if (slot.isDelegate) + { + if (slot.isDisposed) + { + removeSlot!(slotListId)(signalId, slotId); + continue; + } + } + + if (slot.receiver == receiver) + { + removeSlot!(slotListId)(signalId, slotId); + break TOP; + } + + slotId++; + } + } + } + } + } + + void emit(A...)(size_t signalId, A args) + { + synchronized(this) + { + if (signalId >= connections.length || blocked) + return; + auto cons = &connections[signalId]; + + if (cons.hasSlots) + { + { + cons.isInUse = true; + signalSender_.val = owner; + scope(exit) + { + cons.isInUse = false; + signalSender_.val = null; + } + + // Store the lengths to avoid calling new slots + // connected in the slots being called. + // dmd bug: int[cons.slotListCount] fails + static const c = cons.slotListCount; + int[c] lengths = void; + cons.slotListLengths(lengths); + + foreach (slotListId, e; cons.slotLists.tupleof) + { + auto slotList = cons.getSlotList!(slotListId); + for (size_t slotId; slotId < lengths[slotListId];) + { + auto slot = slotList.get(slotId); + static if (slot.isDelegate) + { + if (slot.isDisposed) + { + removeSlot!(slotListId)(signalId, slotId); + lengths[slotListId]--; + continue; + } + } + + slot.invoker.call!(void)(slot.receiver, args); + ++slotId; + } + } + } + + + // process delayed disconnects if any + foreach(i, e; cons.delayedDisconnects.tupleof) + { + if (cons.delayedDisconnects.at!(i).length) + { + foreach (d; cons.delayedDisconnects.at!(i)) + disconnect(signalId, d); + cons.delayedDisconnects.at!(i).length = 0; + } + } + } + } + } + + // Adjusts signal arguments and calls the slot. S - slot signature, A - signal arguments + private void invokeSlot(S, Receiver, A...)(Receiver r, A args) + { + r.get!(S)()(args[0..ParameterTupleOf!(S).length]); + } + + void blockSignals() + { + synchronized(this) + blocked++; + } + + void unblockSignals() + { + synchronized(this) + { + if(!blocked) + throw new SignalException("Signals are not blocked"); + blocked--; + } + } + + ~this() + { + receivers.free(&onReceiverDisposed); + foreach(ref c; connections) + c.free; + } +} + +public template SignalHandlerOps() +{ + static assert (is(typeof(this.signalHandler)), + "SignalHandlerOps is already instantiated in " ~ typeof(this).stringof ~ " or one of its base classes"); + +protected: + SignalHandler signalHandler_; // manages signal-to-slot connections + + final SignalHandler signalHandler() + { + if (!signalHandler_) + { + signalHandler_ = new SignalHandler(this); + onSignalHandlerCreated(signalHandler_); + } + return signalHandler_; + } + + void onSignalHandlerCreated(ref SignalHandler sh) + { + } + +public: + final void blockSignals() + { + signalHandler.blockSignals(); + } + + final void unblockSignals() + { + signalHandler.unblockSignals(); + } + + template connect(string signalName, A...) + { + static void connect(T, Func)(T sender, Func func, ConnectionFlags flags = ConnectionFlags.None) + { + static if (isFnOrDg!(Func)) // D1 has no constraints + { + alias findSignal!(T, signalName, Func, A).result sig; + auto sh = sender.signalHandler(); + static if (isFn!(Func)) + alias Fn Callable; + else + alias Dg Callable; + auto invoker = Dg(&sh.invokeSlot!(typeof(func), Callable, sig[2..$])); + sh.connect(sig[1], Callable(func), invoker, flags); + } + else + { + static assert(false, "The slot must be a function or delegate type."); + } + } + } + + template disconnect(string signalName, A...) + { + static void connect(T, Func)(T sender, Func func, ConnectionFlags flags = ConnectionFlags.None) + { + static if (isFnOrDg!(Func)) // D1 has no constraints + { + alias findSignal!(T, signalName, Func, A).result sig; + auto sh = sender.signalHandler(); + static if (isFn!(Func)) + alias Fn Callable; + else + alias Dg Callable; + sh.disconnect(sig[1], Callable(func)); + } + else + { + static assert(false, "The slot must be a function or delegate type."); + } + } + } +/* + template slotCount(string signalName, A...) + { + debug static void slotCount(T)(T sender) + { + alias findSignal!(T, signalName, Func, A).result sig; + auto sh = sender.signalHandler(); + return sh.slotCount(sig[1]); + } + } + */ +} + +/** + New implementation. +*/ + +const string signalPrefix = "__signal"; + +template TupleWrapper(A...) { alias A at; } + +template isDg(Dg) +{ + enum { isDg = is(Dg == delegate) } +} + +template isFn(Fn) +{ + enum { isFn = is(typeof(*Fn.init) == function) } +} + +template isFnOrDg(Dg) +{ + enum { isFnOrDg = isFn!(Dg) || isDg!(Dg) } +} + +string joinArgs(A...)() +{ + string res = ""; + static if(A.length) + { + res = A[0].stringof; + foreach(k; A[1..$]) + res ~= "," ~ k.stringof; + } + return res; +} + +template SlotPred(T1, T2) +{ + enum { SlotPred = is(T1 : T2) } +} + +template CheckSlot(alias Needle, alias Source) +{ + static if(Needle.at.length <= Source.at.length) + enum { CheckSlot = CheckArgs!(Needle, Source, SlotPred, 0).value } + else + enum { CheckSlot = false } +} + +template SignalPred(T1, T2) +{ + enum { SignalPred = is(T1 == T2) } +} + +template CheckSignal(alias Needle, alias Source) +{ + static if(Needle.at.length == Source.at.length) + enum { CheckSignal = CheckArgs!(Needle, Source, SignalPred, 0).value } + else + enum { CheckSignal = false } +} + +template CheckArgs(alias Needle, alias Source, alias pred, int i) +{ + static if (i < Needle.at.length) + { + static if (pred!(Needle.at[i], Source.at[i])) + enum { value = CheckArgs!(Needle, Source, pred, i + 1).value } + else + enum { value = false } + } + else + { + enum { value = true } + } +} + +template SigByNamePred(string name, SlotArgs...) +{ + template SigByNamePred(source...) + { + static if (source[0] == name) // only instantiate CheckSlot if names match + enum { SigByNamePred = CheckSlot!(TupleWrapper!(SlotArgs), TupleWrapper!(source[2 .. $])) } + else + enum { SigByNamePred = false } + } +} + +template SigBySignPred(string name, SigArgs...) +{ + template SigBySignPred(source...) + { + static if (source[0] == name) // only instantiate CheckSignal if names match + enum { SigBySignPred = CheckSignal!(TupleWrapper!(SigArgs), TupleWrapper!(source[2 .. $])) } + else + enum { SigBySignPred = false } + } +} + +template staticSymbolName(string prefix, int id) +{ + const string staticSymbolName = prefix ~ ToString!(id); +} + +template signatureString(string name, A...) +{ + const string signatureString = name ~ "(" ~ joinArgs!(A) ~ ")"; +} + +template findSymbolImpl(string prefix, C, int id, alias pred) +{ + static if ( is(typeof(mixin("C." ~ staticSymbolName!(prefix, id)))) ) + { + mixin ("alias C." ~ staticSymbolName!(prefix, id) ~ " current;"); + static if (pred!(current)) + alias current result; + else + alias findSymbolImpl!(prefix, C, id + 1, pred).result result; + } + else + { + alias void result; + } +} + +template findSymbol(string prefix, C, alias pred) +{ + alias findSymbolImpl!(prefix, C, 0, pred).result findSymbol; +} + +template findSignal(C, string name, Receiver, SigArgs...) +{ + alias TupleWrapper!(ParameterTupleOf!(Receiver)) SlotArgsWr; + static if (SigArgs.length > 0) + { + alias findSymbol!(signalPrefix, C, SigBySignPred!(name, SigArgs)) result; + static if (is(result == void)) + static assert(0, "Signal " ~ name ~ "(" ~ joinArgs!(SigArgs)() ~ ") was not found."); + else + static if (!CheckSlot!(SlotArgsWr, TupleWrapper!(result[2 .. $]))) + static assert(0, "Signature of slot is incompatible with signal " ~ name ~ "."); + } + else + { + alias findSymbol!(signalPrefix, C, SigByNamePred!(name, SlotArgsWr.at)) result; + static if (is(result == void)) + static assert(0, "Signal " ~ name ~ " was not found."); + } +} + + +public string SignalEmitter(A...)(SignalType signalType, string name, int index) +{ + string fullArgs, args; + static if (A.length) + { + fullArgs = A[0].stringof ~ " a0"; + args = ", a0"; + foreach(i, _; A[1..$]) + { + fullArgs ~= ", " ~ A[i+1].stringof ~ " a" ~ __toString(i+1); + args ~= ", a" ~ __toString(i+1); + } + } + string attribute; + string sigName = name; + if (signalType == SignalType.BindQtSignal) + name ~= "_emit"; + else + attribute = "protected "; + string str = attribute ~ "void " ~ name ~ "(" ~ fullArgs ~ ")" ~ + "{ this.signalHandler.emit(" ~ __toString(index) ~ args ~ "); }"; + return str; +} + +/** + Examples: +---- +struct Args +{ + bool cancel; +} + +class C +{ + private int _x; + // reference parameters are not supported yet, + // so we pass arguments by pointer. + mixin Signal!("xChanging", int, Args*); + mixin Signal!("xChanged"); + + void x(int v) + { + if (v != _x) + { + Args args; + xChanging.emit(v, &args); + if (!args.cancel) + { + _x = v; + xChanged.emit; + } + } + } +} +---- +*/ + +enum SignalType +{ + BindQtSignal, + NewSignal +} + +template BindQtSignal(string name, A...) +{ + mixin SignalImpl!(0, name, SignalType.BindQtSignal, A); +} + +template Signal(string name, A...) +{ + mixin SignalImpl!(0, name, SignalType.NewSignal, A); +} + +template SignalImpl(int index, string name, SignalType signalType, A...) +{ + static if (is(typeof(mixin(typeof(this).stringof ~ ".__signal" ~ ToString!(index))))) + mixin SignalImpl!(index + 1, name, signalType, A); + else + { + // mixed-in once + static if (!is(typeof(this.signalHandler))) + mixin SignalHandlerOps; + + mixin (SignalEmitter!(A)(signalType, name, index)); + mixin("public alias Tuple!(\"" ~ name ~ "\", index, A) __signal" ~ ToString!(index) ~ ";"); + } +} + +extern(C) alias void function(void*) SlotConnector; + +debug (UnitTest) +{ + class A + { + mixin Signal!("scorched", int); + + int signalId1 = -1; + int signalId2 = -1; + + void onFirstConnect(int sId) + { + signalId1 = sId; + } + + void onLastDisconnect(int sId) + { + signalId2 = sId; + } + + this() + { + signalHandler.firstSlotConnected = &onFirstConnect; + signalHandler.lastSlotDisconnected = &onLastDisconnect; + } + } + + class B : A + { + mixin Signal!("booed", int); + + int bazSum; + void baz(int i) + { + bazSum += i; + } + } + + class C : A + { + mixin Signal!("cooked"); + } +} + +unittest +{ + static int fooSum; + static int barSum; + + static void foo(int i) + { + fooSum += i; + } + + void bar(long i) + { + barSum += i; + } + + auto a = new A; + auto b = new B; + auto c = new C; + assert(b.scorched.signalId == 0); + assert(b.booed.signalId == 1); + assert(c.cooked.signalId == 1); + + auto sh = b.signalHandler; + + b.scorched.connect(&foo); + assert(sh.connections.length == 1); + assert(b.signalId1 == 0); + auto scCons = &sh.connections[0]; + + assert(scCons.getSlotList!(SlotListId.Func).length == 1); + b.scorched.emit(1); + assert(fooSum == 1); + + b.scorched.connect(&bar, ConnectionFlags.NoObject); + assert(sh.connections.length == 1); + assert(scCons.getSlotList!(SlotListId.Strong).length == 1); + b.scorched.emit(1); + assert (fooSum == 2 && barSum == 1); + + b.scorched.connect(&b.baz); + assert(scCons.getSlotList!(SlotListId.Weak).length == 1); + b.scorched.emit(1); + assert (fooSum == 3 && barSum == 2 && b.bazSum == 1); + + b.scorched.disconnect(&bar); + assert(scCons.slotCount == 2); + b.scorched.disconnect(&b.baz); + assert(scCons.slotCount == 1); + b.scorched.disconnect(&foo); + assert(scCons.slotCount == 0); + assert(b.signalId2 == 0); + + fooSum = 0; + void connectFoo() + { + b.scorched.connect(&foo); + b.scorched.disconnect(&connectFoo); + } + + b.scorched.connect(&connectFoo, ConnectionFlags.NoObject); + b.scorched.emit(1); + assert(scCons.getSlotList!(SlotListId.Func).length == 1); + assert(scCons.getSlotList!(SlotListId.Strong).length == 0); + assert(!fooSum); + + auto r = new B(); + b.scorched.connect(&r.baz); + assert(scCons.getSlotList!(SlotListId.Weak).length == 1); + b.scorched.emit(1); + assert(r.bazSum == 1); + assert(fooSum == 1); + + delete(r); + assert(scCons.getSlotList!(SlotListId.Weak).length == 1); + b.scorched.emit(1); + assert(scCons.getSlotList!(SlotListId.Weak).length == 0); +} \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/core/CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/core/CMakeLists.txt Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,10 @@ +set(QT_CORE_SRCS_D +Qt.d +QChildEvent.d +QCoreApplication.d +QEvent.d +QEventLoop.d +QObject.d +QTimerEvent.d +QTranslator.d +) diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/core/QLine.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/core/QLine.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,400 @@ +module qt.core.QLine; + +public import qt.QGlobal; +public import qt.core.Qt; +public import qt.core.QPoint; +public import qt.core.QDataStream; + + +public struct QLine +{ + public static QLine opCall() { + QLine ln; + ln.pt1 = QPoint(); + ln.pt2 = QPoint(); + return ln; + } + + public static QLine opCall(in QPoint pt1_, in QPoint pt2_) { + QLine ln; + ln.pt1 = pt1_; + ln.pt2 = pt2_; + return ln; + } + + public static QLine opCall(int x1pos, int y1pos, int x2pos, int y2pos) { + QLine ln; + ln.pt1 = QPoint(x1pos, y1pos); + ln.pt2 = QPoint(x2pos, y2pos); + return ln; + } + + bool isNull() // const + { + return pt1 == pt2; + } + + int x1() // const + { + return pt1.x(); + } + + int y1() // const + { + return pt1.y(); + } + + int x2() // const + { + return pt2.x(); + } + + int y2() // const + { + return pt2.y(); + } + + QPoint p1() // const + { + return pt1; + } + + QPoint p2() // const + { + return pt2; + } + + int dx() // const + { + return pt2.x() - pt1.x(); + } + + int dy() // const + { + return pt2.y() - pt1.y(); + } + + void translate(in QPoint point) + { + pt1 += point; + pt2 += point; + } + + void translate(int adx, int ady) + { + translate(QPoint(adx, ady)); + } + + QLine translated(in QPoint p) // const + { + return QLine(pt1 + p, pt2 + p); + } + + QLine translated(int adx, int ady) // const + { + return translated(QPoint(adx, ady)); + } + + void p1(in QPoint aP1) + { + pt1 = aP1; + } + + void p2(in QPoint aP2) + { + pt2 = aP2; + } + + void setP1(in QPoint aP1) // for convenience + { + pt1 = aP1; + } + + void setP2(in QPoint aP2) // for convenience + { + pt2 = aP2; + } + + void setPoints(in QPoint aP1, in QPoint aP2) + { + pt1 = aP1; + pt2 = aP2; + } + + void setLine(int aX1, int aY1, int aX2, int aY2) + { + pt1 = QPoint(aX1, aY1); + pt2 = QPoint(aX2, aY2); + } + + bool opEquals(in QLine d) // const + { + return pt1 == d.pt1 && pt2 == d.pt2; + } + + public final void writeTo(QDataStream arg__1) { + qtd_QLine_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final void readFrom(QDataStream arg__1) { + qtd_QLine_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); + } + +private: + QPoint pt1, pt2; +} + + +public enum QLineF_IntersectType { + NoIntersection = 0, + BoundedIntersection = 1, + UnboundedIntersection = 2 +} + +public struct QLineF +{ + + alias QLineF_IntersectType IntersectType; + + alias QLineF_IntersectType.NoIntersection NoIntersection; + alias QLineF_IntersectType.BoundedIntersection BoundedIntersection; + alias QLineF_IntersectType.UnboundedIntersection UnboundedIntersection; + + public static QLineF opCall() { + QLineF ln; + ln.pt1 = QPointF(); + ln.pt2 = QPointF(); + return ln; + } + + public static QLineF opCall(in QPointF apt1, in QPointF apt2) { + QLineF ln; + ln.pt1 = apt1; + ln.pt2 = apt2; + return ln; + } + + public static QLineF opCall(qreal x1pos, qreal y1pos, qreal x2pos, qreal y2pos) { + QLineF ln; + ln.pt1 = QPointF(x1pos, y1pos); + ln.pt2 = QPointF(x2pos, y2pos); + return ln; + } + + public static QLineF opCall(in QLine line){ + QLineF ln; + ln.pt1 = QPointF(line.p1()); + ln.pt2 = QPointF(line.p2()); + return ln; + } + + public final bool isNull() // const + { + return qtd_QLineF_isNull(this); + } + + qreal x1() // const + { + return pt1.x(); + } + + qreal y1() // const + { + return pt1.y(); + } + + qreal x2() // const + { + return pt2.x(); + } + + qreal y2() // const + { + return pt2.y(); + } + + QPointF p1() // const + { + return pt1; + } + + QPointF p2() // const + { + return pt2; + } + + qreal dx() // const + { + return pt2.x() - pt1.x(); + } + + qreal dy() // const + { + return pt2.y() - pt1.y(); + } + + QLineF normalVector() // const + { + return QLineF(p1(), p1() + QPointF(dy(), -dx())); + } + + void translate(in QPointF point) + { + pt1 += point; + pt2 += point; + } + + void translate(qreal adx, qreal ady) + { + this.translate(QPointF(adx, ady)); + } + + QLineF translated(in QPointF p) // const + { + return QLineF(pt1 + p, pt2 + p); + } + + QLineF translated(qreal adx, qreal ady) // const + { + return translated(QPointF(adx, ady)); + } + + void setLength(qreal len) + { + if (isNull()) + return; + QLineF v = unitVector(); + pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len); + } + + void length(qreal len) + { + if (isNull()) + return; + QLineF v = unitVector(); + pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len); + } + + QPointF pointAt(qreal t) // const + { + qreal vx = pt2.x() - pt1.x(); + qreal vy = pt2.y() - pt1.y(); + return QPointF(pt1.x() + vx * t, pt1.y() + vy * t); + } + + QLine toLine() // const + { + return QLine(pt1.toPoint(), pt2.toPoint()); + } + + void setP1(in QPointF aP1) + { + pt1 = aP1; + } + + void setP2(in QPointF aP2) + { + pt2 = aP2; + } + + void p1(in QPointF aP1) + { + pt1 = aP1; + } + + void p2(in QPointF aP2) + { + pt2 = aP2; + } + + void setPoints(in QPointF aP1, in QPointF aP2) + { + pt1 = aP1; + pt2 = aP2; + } + + void setLine(qreal aX1, qreal aY1, qreal aX2, qreal aY2) + { + pt1 = QPointF(aX1, aY1); + pt2 = QPointF(aX2, aY2); + } + + bool opEquals(in QLineF d) // const + { + return pt1 == d.pt1 && pt2 == d.pt2; + } + + public final double angle() { + return qtd_QLineF_angle(this); + } + + public final double angle(in QLineF l) { + return qtd_QLineF_angle_QLineF(this, &l); + } + + public final double angleTo(in QLineF l) { + return qtd_QLineF_angleTo_QLineF(this, &l); + } + + // ### Qt 5: rename intersects() or intersection() and rename IntersectType IntersectionType + private final QLineF_IntersectType intersect(in QLineF l, QPointF* intersectionPoint) { + return cast(QLineF_IntersectType) qtd_QLineF_intersect_QLineF_nativepointerQPointF(this, &l, intersectionPoint); + } + + public final double length() { + return qtd_QLineF_length(this); + } + + public final void writeTo(QDataStream arg__1) { + qtd_QLineF_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final void readFrom(QDataStream arg__1) { + qtd_QLineF_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final void setAngle(double angle) { + qtd_QLineF_setAngle_double(this, angle); + } + + public final QLineF unitVector() { + return qtd_QLineF_unitVector(this); + } + + public static QLineF fromPolar(double length, double angle) { + return qtd_QLineF_fromPolar_double_double(length, angle); + } + + private: + QPointF pt1, pt2; +} + + +// C wrappers +// QLine +private extern(C) void qtd_QLine_writeTo_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void qtd_QLine_readFrom_QDataStream(void* __this_nativeId, + void* arg__1); + +// QLineF +private extern(C) bool qtd_QLineF_isNull(void* __this_nativeId); +private extern(C) double qtd_QLineF_angle(void* __this_nativeId); +private extern(C) double qtd_QLineF_angle_QLineF(void* __this_nativeId, + void* l0); +private extern(C) double qtd_QLineF_angleTo_QLineF(void* __this_nativeId, + void* l0); +private extern(C) int qtd_QLineF_intersect_QLineF_nativepointerQPointF(void* __this_nativeId, + void* l0, + void* intersectionPoint1); +private extern(C) double qtd_QLineF_length(void* __this_nativeId); +private extern(C) void qtd_QLineF_writeTo_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void qtd_QLineF_readFrom_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void qtd_QLineF_setAngle_double(void* __this_nativeId, + double angle0); + +private extern(C) QLineF qtd_QLineF_unitVector(void* __this_nativeId); +private extern(C) QLineF qtd_QLineF_fromPolar_double_double(double length0, + double angle1); diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/core/QLineF.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/core/QLineF.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,4 @@ +module qt.core.QLineF; +/* dummy */ + +public import qt.core.QLine; \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/core/QList.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/core/QList.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,627 @@ +module qt.core.QList; + +import qt.QGlobal; +import qt.QtdObject; +import qt.qtd.Atomic; +import qt.qtd.MetaMarshall; +import qt.core.QTypeInfo; +import qt.core.QString; + +import core.stdc.stdlib : qRealloc = realloc, qFree = free, qMalloc = malloc; +import core.stdc.string : memcpy, memmove; + +import std.traits; + +enum INT_MAX = int.max; + +bool isComplex(T)() + if (is(T.QTypeInfo)) +{ + return T.QTypeInfo.isComplex; +} + +bool isStatic(T)() + if (is(T.QTypeInfo)) +{ + return T.QTypeInfo.isStatic; +} + +bool isLarge(T)() + if (is(T.QTypeInfo)) +{ + return T.QTypeInfo.isLarge; +} + +template isQtReference(T) +{ + enum isQtReference = isQObjectType!T || isObjectType!T || isValueType!T || is(T == string); +} + +int qAllocMore(int alloc, int extra) +{ + if (alloc == 0 && extra == 0) + return 0; + const int page = 1 << 12; + int nalloc; + alloc += extra; + if (alloc < 1<<6) { + nalloc = (1<<3) + ((alloc >>3) << 3); + } else { + // don't do anything if the loop will overflow signed int. + if (alloc >= INT_MAX/2) + return INT_MAX; + nalloc = (alloc < page) ? 1 << 3 : page; + while (nalloc < alloc) { + if (nalloc <= 0) + return INT_MAX; + nalloc *= 2; + } + } + return nalloc - extra; +} + +void q_new_at(T)(T* ptr, const ref T t) +{ + memcpy(ptr, &t, T.sizeof); +/* static if (__traits(compiles, ptr.__postblit())) DMD bug #3539 + ptr.__postblit();*/ +} + +T* q_new(T)(const ref T t) +{ + T* ptr = cast(T*) qMalloc(T.sizeof); + q_new_at!T(ptr, t); + return ptr; +} + +void q_delete(T)(T* t) +{ + static if (__traits(compiles, t.__dtor())) + t.__dtor(); + qFree(t); +} + +private int grow(int size) +{ + // dear compiler: don't optimize me out. +// synchronized { + int x = qAllocMore(size * (void*).sizeof, QListData.DataHeaderSize) / (void*).sizeof; + return x; +// } +} + +struct QListData { +private: + struct Data { + Atomic!int ref_; + int alloc, begin, end; + uint sharable; + void*[1] array; + } + + enum { DataHeaderSize = Data.sizeof - (void*).sizeof } + + static Data shared_null; + Data *d; + + static this() + { + shared_null = Data(Atomic!int(1), 0, 0, 0, true, [null]); + } + + +// Data *detach(); // remove in 5.0 + + Data* detach2() + { + Data* x = d; + d = cast(Data*)(qMalloc(DataHeaderSize + x.alloc * (void*).sizeof)); + if (!d) + qFatal("QList: Out of memory"); + + memcpy(d, x, DataHeaderSize + x.alloc * (void*).sizeof); + d.alloc = x.alloc; + d.ref_.store(1); + d.sharable = true; + if (!d.alloc) + d.begin = d.end = 0; + + return x; + } + + void realloc(int alloc) + { +// assert(d.ref_ == 1); + Data* x = cast(Data*)(qRealloc(d, DataHeaderSize + alloc * (void*).sizeof)); + if (!x) + qFatal("QList: Out of memory"); + + d = x; + d.alloc = alloc; + if (!alloc) + d.begin = d.end = 0; + } + + void** append() + { +// #TODO Q_ASSERT(d.ref_ == 1); + if (d.end == d.alloc) { + int n = d.end - d.begin; + if (d.begin > 2 * d.alloc / 3) { + memcpy(d.array.ptr + n, d.array.ptr + d.begin, n * (void*).sizeof); + d.begin = n; + d.end = n * 2; + } else { + realloc(grow(d.alloc + 1)); + } + } + return d.array.ptr + d.end++; + } + + void **append(const ref QListData l) + { +// Q_ASSERT(d.ref_ == 1); + int e = d.end; + int n = l.d.end - l.d.begin; + if (n) { + if (e + n > d.alloc) + realloc(grow(e + l.d.end - l.d.begin)); + memcpy(d.array.ptr + d.end, l.d.array.ptr + l.d.begin, n * (void*).sizeof); + d.end += n; + } + return d.array.ptr + e; + } + + void **prepend() + { +// Q_ASSERT(d.ref_ == 1); + if (d.begin == 0) { + if (d.end >= d.alloc / 3) + realloc(grow(d.alloc + 1)); + + if (d.end < d.alloc / 3) + d.begin = d.alloc - 2 * d.end; + else + d.begin = d.alloc - d.end; + + memmove(d.array.ptr + d.begin, d.array.ptr, d.end * (void*).sizeof); + d.end += d.begin; + } + return d.array.ptr + --d.begin; + } + + void **insert(int i) + { +// Q_ASSERT(d.ref_ == 1); + if (i <= 0) + return prepend(); + if (i >= d.end - d.begin) + return append(); + + bool leftward = false; + int size = d.end - d.begin; + + if (d.begin == 0) { + if (d.end == d.alloc) { + // If the array is full, we expand it and move some items rightward + realloc(grow(d.alloc + 1)); + } else { + // If there is free space at the end of the array, we move some items rightward + } + } else { + if (d.end == d.alloc) { + // If there is free space at the beginning of the array, we move some items leftward + leftward = true; + } else { + // If there is free space at both ends, we move as few items as possible + leftward = (i < size - i); + } + } + + if (leftward) { + --d.begin; + memmove(d.array.ptr + d.begin, d.array.ptr + d.begin + 1, i * (void*).sizeof); + } else { + memmove(d.array.ptr + d.begin + i + 1, d.array.ptr + d.begin + i, + (size - i) * (void*).sizeof); + ++d.end; + } + return d.array.ptr + d.begin + i; + } + + void remove(int i) + { +// Q_ASSERT(d.ref_ == 1); + i += d.begin; + if (i - d.begin < d.end - i) { + if (int offset = i - d.begin) + memmove(d.array.ptr + d.begin + 1, d.array.ptr + d.begin, offset * (void*).sizeof); + d.begin++; + } else { + if (int offset = d.end - i - 1) + memmove(d.array.ptr + i, d.array.ptr + i + 1, offset * (void*).sizeof); + d.end--; + } + } + + void remove(int i, int n) + { +// Q_ASSERT(d.ref_ == 1); + i += d.begin; + int middle = i + n/2; + if (middle - d.begin < d.end - middle) { + memmove(d.array.ptr + d.begin + n, d.array.ptr + d.begin, + (i - d.begin) * (void*).sizeof); + d.begin += n; + } else { + memmove(d.array.ptr + i, d.array.ptr + i + n, + (d.end - i - n) * (void*).sizeof); + d.end -= n; + } + } + + void move(int from, int to) + { +// Q_ASSERT(d.ref_ == 1); + if (from == to) + return; + + from += d.begin; + to += d.begin; + void *t = d.array.ptr[from]; + + if (from < to) { + if (d.end == d.alloc || 3 * (to - from) < 2 * (d.end - d.begin)) { + memmove(d.array.ptr + from, d.array.ptr + from + 1, (to - from) * (void*).sizeof); + } else { + // optimization + if (int offset = from - d.begin) + memmove(d.array.ptr + d.begin + 1, d.array.ptr + d.begin, offset * (void*).sizeof); + if (int offset = d.end - (to + 1)) + memmove(d.array.ptr + to + 2, d.array.ptr + to + 1, offset * (void*).sizeof); + ++d.begin; + ++d.end; + ++to; + } + } else { + if (d.begin == 0 || 3 * (from - to) < 2 * (d.end - d.begin)) { + memmove(d.array.ptr + to + 1, d.array.ptr + to, (from - to) * (void*).sizeof); + } else { + // optimization + if (int offset = to - d.begin) + memmove(d.array.ptr + d.begin - 1, d.array.ptr + d.begin, offset * (void*).sizeof); + if (int offset = d.end - (from + 1)) + memmove(d.array.ptr + from, d.array.ptr + from + 1, offset * (void*).sizeof); + --d.begin; + --d.end; + --to; + } + } + d.array.ptr[to] = t; + } + + void **erase(void **xi) + { +// Q_ASSERT(d.ref_ == 1); + int i = xi - (d.array.ptr + d.begin); + remove(i); + return d.array.ptr + d.begin + i; + } + + int size() const { return d.end - d.begin; } + bool isEmpty() const { return d.end == d.begin; } + const (void*)* at(int i) const { return d.array.ptr + d.begin + i; } + const (void*)* begin() const { return d.array.ptr + d.begin; } + const (void*)* end() const { return d.array.ptr + d.end; } +} + +import std.stdio; +import std.conv; + +alias void Dummy; // DMD bug #3538 + +struct QList(T, alias Default = Dummy) +{ + static if (is(Default == Dummy)) + alias QTypeInfo!T TI; + else + alias Default TI; + + struct Node + { + void *v; + + static if (isQObjectType!T || isObjectType!T || isValueType!T || is(T == string)) // binded Qt types + { + T t() + { + static if(is(T == string)) + { + void* ptr = cast(void*)(TI.isLarge || TI.isStatic ? v : &this); + return QStringUtil.toNativeString(ptr); + } + else static if (isValueType!T) + { + void* ptr = cast(void*)(isLarge!T() || isStatic!T() ? v : &this); + return new T(ptr, QtdObjectFlags.nativeOwnership); + } + else + { + return T.__getObject( *cast(void**)(&this) ); + } + } + } + else // native types + { + ref T t() + { + static if(TI.isLarge || TI.isStatic) + return *cast(T*)(this.v); + else + return *cast(T*)(&this); + } + } + } + + union { + QListData p; + QListData.Data* d; + } + +public: + /* + void output() + { + writeln("QList atomic ", d.ref_.load()); + } + */ + + static QList!T opCall() + { + QList!T res; +// writeln("QList opCall"); + + res.d = &QListData.shared_null; + res.d.ref_.increment(); + + return res; + } + + this(this) + { +// writeln("QList postblit"); + d.ref_.increment(); + if (!d.sharable) + detach_helper(); + } + + ~this() + { +// writeln("QList ~this"); + if (d && !d.ref_.decrement()) + free(d); + } + + ref QList!T opAssign(const ref QList!T l) + { +// writeln("QList opAssign"); + if (d != l.d) { + QListData.Data* nd = cast(QListData.Data*)l.d; + nd.ref_.increment(); + if (!d.ref_.decrement()) + free(d); + d = nd; + if (!d.sharable) + detach_helper(); + } + return this; + } + + int length() const { return p.size(); } + int size() const { return length; } + + void detach() { if (d.ref_.load() != 1) detach_helper(); } + + private void detach_helper() + { + Node *n = cast(Node*)(p.begin()); + QListData.Data* x = p.detach2(); + node_copy(cast(Node*)(p.begin()), cast(Node*)(p.end()), n); + if (!x.ref_.decrement()) + free(x); + } + + void append(const T t) // fix to const ref for complex types TODO + { + detach(); + static if (isQObjectType!T || isObjectType!T || isValueType!T) + { + node_construct(cast(Node*)(p.append()), t); + } + else + { + const T cpy = t; + node_construct(cast(Node*)(p.append()), cpy); + } + } + + alias append opCatAssign; + + static if (isQObjectType!T || isObjectType!T || isValueType!T || is(T == string)) + { + T at(int i) const + { + assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); + return (cast(Node*)(p.at(i))).t(); + } + T opIndex(int i) + { + assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); + return (cast(Node*)(p.at(i))).t(); + } + } + else + { + const (T) at(int i) const // DMD BUG + { + assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); + return (cast(Node*)(p.at(i))).t(); + } + ref T opIndex(int i) + { + assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); + return (cast(Node*)(p.at(i))).t(); + } + } + + static if (isQObjectType!T || isObjectType!T || isValueType!T) //binded types + void node_construct(Node *n, const T t) + { + static if (isValueType!T) + { + if (isLarge!T() || isStatic!T()) // TODO should be static if + n.v = T.__constructNativeCopy(t.__nativeId); // n.v = new T(t); + else if (isComplex!T()) + T.__constructPlacedNativeCopy(t.__nativeId, n); // new (n) T(t); + else + T.__constructPlacedNativeCopy(t.__nativeId, n); // TODO should be *cast(T*)(n) = cast(T)(t); as it is a primitive type. fix when they are implemented with structs + } + else // in case of QObject or Object Qt types we place a pointer to a native object in the node + n = cast(Node*) t.__nativeId; + } + else static if (is(T == string)) + { + void node_construct(Node *n, T t) + { + QString.__constructPlacedQString(n, t); + } + } + else // native types + void node_construct(Node *n, const ref T t) + { + static if (TI.isLarge || TI.isStatic) + n.v = q_new!T(t); // n.v = new T(t); + else static if (TI.isComplex) + q_new_at(n, t); // new (n) T(t); + else + *cast(T*)(n) = cast(T)(t); + } + + void node_copy(Node *from, Node *to, Node *src) + { +// writeln("QList node_copy"); + static if (isQObjectType!T || isObjectType!T) + {} // ensure to do nothing. copying only a pointer + else static if(is(T == string)) + { + while(from != to) // TODO when porting to Qt 5 ensure that QTypeInfo.isLarge and .isStatic == false + QString.__constructPlacedNativeCopy(src++, from++); // new (from++) T(*reinterpret_cast(src++)); + } + else static if (isValueType!T) + { + if (TI.isLarge || TI.isStatic) // TODO should be static if + while(from != to) + (from++).v = T.__constructNativeCopy((src++).v); // (from++)->v = new T(*reinterpret_cast((src++)->v)); + else if (TI.isComplex) + while(from != to) + T.__constructPlacedNativeCopy(src++, from++); // new (from++) T(*reinterpret_cast(src++)); + } + else static if (TI.isLarge || TI.isStatic) + while(from != to) + (from++).v = q_new!T(*cast(T*)((src++).v)); + else static if (TI.isComplex) + while(from != to) + q_new_at(from++, *cast(T*)(src++)); + } + + T[] toArray() + { + T[] res; + res.length = this.length; + for(int i = 0; i < res.length; ++i) + { + static if (isValueType!T) + res[i] = new T(T.__constructNativeCopy(this.at(i).__nativeId)); // Node should probably provide a ptr method to directly extract pointer to the native value stored in the list to avoid creating a dummy D object in t() + else + res[i] = this.opIndex(i); + } + return res; + } + + void free(QListData.Data* data) + { +// writeln("QList data destroyed"); + node_destruct(cast(Node*)(data.array.ptr + data.begin), + cast(Node*)(data.array.ptr + data.end)); + if (data.ref_.load() == 0) + qFree(data); + } + + void node_destruct(Node *from, Node *to) + { + static if (isQObjectType!T || isObjectType!T) //binded types + {} // removing just pointers, do nothing + else static if (is(T == string)) + { + while (from != to) + --to, QString.__callNativeDestructor(to); + } + else static if (isValueType!T) //binded value types + { + if (isLarge!T() || isStatic!T()) // TODO should be static if + while (from != to) + --to, T.__deleteNativeObject(to.v); + else if (isComplex!T()) + while (from != to) + --to, T.__callNativeDestructor(to); + } + else + { + static if (TI.isLarge || TI.isStatic) + while (from != to) --to, q_delete(cast(T*)(to.v)); + else static if (TI.isComplex) + while (from != to) --to, cast(T*)(to).__dtor(); + } + } + + //iteration support + int opApply(int delegate(ref T) dg) + { + int result = 0; + int sz = this.length; + for (int i = 0; i < sz; i++) + { + static if (isQtReference!T) + { + T t = this[i]; // hack to avoid "is not an lvalue" error, since dg accepts ref T + result = dg(t); + } + else + result = dg(this[i]); + + if (result) + break; + } + return result; + } +} + +alias QList!string QStringList; + +QList!T toQList(T)(T[] src) +{ + auto res = QList!T.opCall(); + foreach(elem; src) + res.append(elem); + return res; +} + +QList!T qList(T)() +{ + return QList!T.opCall(); +} + +extern(C) void qtd_create_QList(void *nativeId); +extern(C) void qtd_create_QList_double(void *nativeId); + +extern(C) void qtd_create_QList_QObject(void *nativeId); diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/core/QMetaObject.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/core/QMetaObject.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,390 @@ +module qt.core.QMetaObject; + +import qt.QGlobal; +import qt.core.QObject; +import qt.QtdObject; + +import std.algorithm; +import std.string; +import std.stdio; + +class Meta +{ + string name; +} + +class MetaType : Meta +{ + this() + { + } +} + +class MetaVariable : Meta +{ + MetaType type; +} + +class MetaCallable : Meta { } + +class MetaMethod : Meta { } + +class QMetaArgument : MetaVariable { } + +class QMetaMethod : MetaMethod +{ +// QMetaArgument[] arguments; + string signature; + int indexOfMethod; + + this(string signature_, int indexOfMethod_) + { + signature = signature_; + indexOfMethod = indexOfMethod_; + } + + string args() const + { + int openBracket = indexOf(signature, '('); + if(signature.length - openBracket - 2 > 0) + return signature[openBracket + 1 .. $-1]; + else + return ""; + } + + string name() const + { + int openBracket = indexOf(signature, '('); + return signature[0..openBracket]; + } +} + +class QMetaSignal : QMetaMethod +{ + this(string signature_, int indexOfMethod_) + { + super(signature_, indexOfMethod_); + } +} + +class QMetaSlot : QMetaMethod +{ + this(string signature_, int indexOfMethod_) + { + super(signature_, indexOfMethod_); + } +} + +class MetaObject : MetaType +{ + MetaObject _base; +} + +struct QMetaObjectNative +{ + QMetaObjectNative *superdata; + immutable(char) *stringdata; + const(uint) *data; + void *extradata; +} + +class QMetaException : Exception { this(string msg) { super(msg); } } + +final class QMetaObject +{ + enum Call + { + InvokeMetaMethod, + ReadProperty, + WriteProperty, + ResetProperty, + QueryPropertyDesignable, + QueryPropertyScriptable, + QueryPropertyStored, + QueryPropertyEditable, + QueryPropertyUser, + CreateInstance + } + + private + { + QMetaObjectNative* _nativeId; + QMetaObject _base; // super class + QMetaObject _firstDerived; // head of the linked list of derived classes + QMetaObject _next; // next sibling on this derivation level + QMetaMethod[] _methods; + ClassInfo _classInfo; + + QObject function(void* nativeId) _createWrapper; + } + + private void addDerived(QMetaObject mo) + { + mo._next = _firstDerived; + _firstDerived = mo; + } + + // NOTE: construction is split between this non-templated constructor and 'construct' function below. + this(QMetaObjectNative* nativeId, QMetaObject base) + { + _nativeId = nativeId; + if (base) + { + base.addDerived(this); + _base = base; + } + } + + // TODO: remove when D acquires templated constructors + void construct(T : QObject, Concrete = T)() + { + _classInfo = T.classinfo; + + _createWrapper = function QObject(void* nativeId) { + // COMPILER BUG: cast is should not be needed + auto obj = new Concrete(nativeId, cast(QtdObjectFlags)(QtdObjectFlags.nativeOwnership | QtdObjectFlags.dynamicEntity)); + // TODO: Probably this should be a virtual call from T's constructor + T.__createEntity(nativeId, cast(void*)obj); + return obj; + }; + } + + /++ + +/ + QMetaObject base() + { + return _base; + } + + /++ + +/ + QMetaObjectNative* nativeId() + { + return _nativeId; + } + + /++ + +/ + ClassInfo classInfo() + { + return _classInfo; + } + + const (QMetaMethod[]) methods() + { + return _methods; + } + + void addMethod(QMetaMethod method_) + { + _methods ~= method_; + } + + QMetaMethod lookUpMethod(string slot) + { + foreach (method; _methods) + if (method.signature == slot) + return method; + if (_base) + return _base.lookUpMethod(slot); + else + return null; + } + + QMetaSignal lookUpSignal(string signal) + { + foreach (method; _methods) + if (method.signature == signal && cast(QMetaSignal)method) + return cast(QMetaSignal)method; + if (_base) + return _base.lookUpSignal(signal); + else + return null; + } + + QMetaMethod[] lookUpMethodOverloads(string methodName) + { + typeof(return) result; + foreach (method; _methods) + if (method.name == methodName) + result ~= method; + if (_base) + result ~= _base.lookUpMethodOverloads(methodName); + return result; + } + + QMetaSignal[] lookUpSignalOverloads(string signalName) + { + typeof(return) result; + foreach (method; _methods) + if (method.name == signalName && cast(QMetaSignal)method) + result ~= cast(QMetaSignal)method; + if (_base) + result ~= _base.lookUpSignalOverloads(signalName); + return result; + } + + private QMetaObject lookupDerived(void*[] moIds) + { + assert (moIds.length >= 1); + + for (auto mo = _firstDerived; mo !is null; mo = mo._next) + { + if (mo._nativeId == moIds[0]) + { + if (moIds.length == 1) // exact match found + return mo; + else // look deeper + return mo.lookupDerived(moIds[1..$]); + } + } + + // no initialized wrapper that matches the native object. + // use the base class wrapper + return this; + } + + QObject getObject(void* nativeObjId) + { + QObject result; + + if (nativeObjId) + { + result = cast(QObject)qtd_get_d_qobject(nativeObjId); + if (!result) + { + auto moId = qtd_QObject_metaObject(nativeObjId); + if (_nativeId == moId) + result = _createWrapper(nativeObjId); + else + { + // get native metaobjects for the entire derivation lattice + // up to, but not including, the current metaobject. + size_t moCount = 1; + + for (void* tmp = moId;;) + { + tmp = qtd_QMetaObject_superClass(tmp); + assert(tmp); + if (tmp == _nativeId) + break; + moCount++; + } + + void*[] moIds = (cast(void**)alloca(moCount * (void*).sizeof))[0..moCount]; + + moIds[--moCount] = moId; + while (moCount > 0) + moIds[--moCount] = moId = qtd_QMetaObject_superClass(moId); + + result = lookupDerived(moIds)._createWrapper(nativeObjId); + } + } + } + + return result; + } + + static void activate(QObject sender, QMetaObject m, int local_signal_index, void **argv) + { + qtd_QMetaObject_activate_3(sender.__nativeId, m.nativeId, local_signal_index, argv); + } + + static void activate(QObject sender, QMetaObject m, int from_local_signal_index, int to_local_signal_index, void **argv) + { + qtd_QMetaObject_activate_4(sender.__nativeId, m.nativeId, from_local_signal_index, to_local_signal_index, argv); + } + + static bool connect(const QObject sender, int signal_index, + const QObject receiver, int method_index, + int type = 0, int *types = null) + { + return qtd_QMetaObject_connect(sender.__nativeId, signal_index, receiver.__nativeId, method_index, type, types); + } + + int indexOfMethod_Cpp(string method) + { + return qtd_QMetaObject_indexOfMethod(_nativeId, toStringz(method)); + } + + int methodCount() + { + return qtd_QMetaObject_methodCount(_nativeId); + } + + static void connectImpl(QObject sender, string signalString, QObject receiver, string methodString, int type) + { + QMetaSignal[] signals; + QMetaMethod[] methods; + QMetaSignal signal; + QMetaMethod method; + + if(indexOf(signalString, '(') > 0) + signal = sender.metaObject.lookUpSignal(signalString); + else + signals = sender.metaObject.lookUpSignalOverloads(signalString); // parameters not specified. Looking for a match + + if(indexOf(methodString, '(') > 0) + method = receiver.metaObject.lookUpMethod(methodString); + else + methods = receiver.metaObject.lookUpMethodOverloads(methodString); // parameters not specified. Looking for a match + + if(!signal && !method) + { + Top: + foreach(sig; signals) + foreach(meth; methods) + if(startsWith(sig.args, meth.args)) + { + signal = sig; + method = meth; + break Top; + } + } + else if (!signal) + { + foreach(sig; signals) + if(startsWith(sig.args, method.args)) + { + signal = sig; + break; + } + } + else if (!method) + { + foreach(meth; methods) + if(startsWith(signal.args, meth.args)) + { + method = meth; + break; + } + } + + bool success = false; + + if(!signal && !method) + { + success = false; + } + else + { + int signalIndex = signal.indexOfMethod; + int methodIndex = method.indexOfMethod; + success = QMetaObject.connect(sender, signalIndex, receiver, methodIndex, type); + } + + if(!success) + throw new QMetaException("QMetaObject: Signal " ~ signalString ~ " and slot " ~ methodString ~ " cannot be found"); + } +} + +extern(C) void qtd_QMetaObject_activate_3(void* sender, void* m, int local_signal_index, void **argv); +extern(C) void qtd_QMetaObject_activate_4(void *sender, void* m, int from_local_signal_index, int to_local_signal_index, void **argv); +extern(C) bool qtd_QMetaObject_connect(const void* sender, int signal_index, + const void* receiver, int method_index, + int type, int *types); + +extern(C) int qtd_QMetaObject_indexOfMethod(void *nativeId, const(char) *method); +extern(C) int qtd_QMetaObject_methodCount(void *nativeId); + +extern(C) void* qtd_QMetaObject_superClass(void* nativeId); diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/core/QMetaType.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/core/QMetaType.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,113 @@ +module qt.core.QMetaType; +public import qt.core.Qt; +private import qt.core.QDataStream; + +version (Tango) +{ + import tango.core.Array; + import tango.stdc.stringz; + import tango.core.Traits; +} + +alias extern(C) void *function(void *copy) Ctor; +alias extern(C) void function(void *obj) Dtor; +alias extern(C) void function(void *stream, void * object) StreamOp; + +struct DArrayToC +{ + void[] array; +} + +public template MetaTypeOps(T) +{ + // TODO: + // static assert(typeof(new T), "Type " ~ T.stringof ~ " has no default constructor"); + // static assert(typeof(new T(T.init))), "Type " ~ T.stringof ~ " has no default copy constructor"); + + extern(C) void* ctor(void* copy) + { + static if (is(T == class) || is(T == interface)) + { + return cast(void*)(copy ? new T(cast(T)copy) : new T); + } + else static if (isDynamicArrayType!(T) || isStaticArrayType!(T) ) + { + auto darray = new DArrayToC; + if(copy) + darray.array = (cast(DArrayToC*)copy).array.dup; + return cast(void*)darray; + } + else + { + auto data = new T; + if(copy) + *data = *cast(T*)copy; + return cast(void*)data; + } + } + + + extern(C) void dtor(void* obj) + { + static if (is(T == class) || is(T == interface)) + { + auto tmp = cast(T)obj; + delete tmp; + } + else + { + auto tmp = cast(T*)obj; + delete tmp; + } + } +} + +public int qRegisterMetaType(T)(string name = null) +{ + if (!name.length) + name = typeid(T).toString; + + return qtd_registerType(toStringz(name), &MetaTypeOps!(T).ctor, &MetaTypeOps!(T).dtor); +} + +/* Not work.... +private class DataStreamPriv: QDataStream +{ + this(void * cobj) + { + super(cobj); + } +} +*/ +/* +public void qRegisterMetaTypeStreamOperators(T)(void function(ref QDataStream, T ) saveOp, void function (ref QDataStream, ref T) loadOp, string name = null) +{ + static void function(ref QDataStream, T ) SaveOp; + static void function (ref QDataStream, ref T) LoadOp; + SaveOp = saveOp; + LoadOp = loadOp; + + if (!name.length) + name = typeid(T).toString; + + extern(C) void saveOpC(void *stream, void *object) + { + QDataStream dstream = new DataStreamPriv(stream); + Stdout(object).newline; + static if (is(T == class) || is(T == interface)) + SaveOp(dstream, cast(T)object); + else + SaveOp(dstream, *cast(T*)object); + } + + extern(C) void loadOpC(void *stream, void *object) + { + //return stream; + } + + qtd_registerStreamOperators(toStringz(name), cast(StreamOp)&saveOpC, cast(StreamOp)&loadOpC); +} +*/ +private extern(C) void qtd_registerStreamOperators(char *typeName, StreamOp saveOp, StreamOp loadOp); +private extern(C) int qtd_registerType(in char* namePtr, Ctor ctor, Dtor dtor); +extern(C) int qtd_MetatypeId(in char *id); // TODO: wrap to D. \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/core/QModelIndex.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/core/QModelIndex.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,127 @@ +module qt.core.QModelIndex; + +public import qt.QGlobal; +private import qt.QtdObject; + +// automatic imports------------- +private import qt.core.QVariant; +private import qt.core.QAbstractItemModel; +public import qt.core.Qt; + +version (Tango) +{ + import tango.core.Array; + import tango.stdc.stringz; + import tango.text.convert.Utf; +} + + +public struct QModelIndex +{ + + public static QModelIndex opCall() { + QModelIndex mi; + mi.r = mi.c = -1; + mi.p = mi.m = null; + return mi; + } + public final QModelIndex child(int row, int column) { + return __qtd_QModelIndex_child_int_int(this, row, column); + } + + public final int column() { + return __qtd_QModelIndex_column(this); + } + + public final QVariant data(int role = 0) { + void* __qt_return_value = __qtd_QModelIndex_data_int(this, role); + return new QVariant(__qt_return_value); + } + + public final int flags() { + return __qtd_QModelIndex_flags(this); + } + + public final long internalId() { + return __qtd_QModelIndex_internalId(this); + } + + public final void* internalPointer() { + //return __qtd_QModelIndex_internalPointer(this); + return p; + } + + public final Object object() { + return cast(Object) p; + } + + public final bool isValid() { + return __qtd_QModelIndex_isValid(this); + } + + public final QAbstractItemModel model() { +// void* __qt_return_value = __qtd_QModelIndex_model(this); + void* __qt_return_value = m; + if (__qt_return_value is null) + return null; + void* d_obj = qtd_get_d_qobject(__qt_return_value); + return cast(QAbstractItemModel) d_obj; + } + + private final bool operator_less(QModelIndex other) { + return __qtd_QModelIndex_operator_less_QModelIndex(this, other); + } + + private final bool operator_equal(QModelIndex other) { + return __qtd_QModelIndex_operator_equal_QModelIndex(this, other); + } + + public final QModelIndex parent() { + return __qtd_QModelIndex_parent(this); + } + + public final int row() { + return __qtd_QModelIndex_row(this); + } + + public final QModelIndex sibling(int row, int column) { + return __qtd_QModelIndex_sibling_int_int(this, row, column); + } + +private: + int r; + int c; + void *p; + void *m; +} + +alias QModelIndex QModelIndexAccessor; + + +// C wrappers +private extern(C) void* __qtd_QModelIndex_QModelIndex_QModelIndex(QModelIndex other0); +private extern(C) QModelIndex __qtd_QModelIndex_child_int_int(void* __this_nativeId, + int row0, + int column1); +private extern(C) int __qtd_QModelIndex_column(void* __this_nativeId); +private extern(C) void* __qtd_QModelIndex_data_int(void* __this_nativeId, + int role0); +private extern(C) int __qtd_QModelIndex_flags(void* __this_nativeId); +private extern(C) long __qtd_QModelIndex_internalId(void* __this_nativeId); +private extern(C) void* __qtd_QModelIndex_internalPointer(void* __this_nativeId); +private extern(C) bool __qtd_QModelIndex_isValid(void* __this_nativeId); +private extern(C) void* __qtd_QModelIndex_model(void* __this_nativeId); +private extern(C) bool __qtd_QModelIndex_operator_less_QModelIndex(void* __this_nativeId, + QModelIndex other0); +private extern(C) bool __qtd_QModelIndex_operator_equal_QModelIndex(void* __this_nativeId, + QModelIndex other0); +private extern(C) QModelIndex __qtd_QModelIndex_parent(void* __this_nativeId); +private extern(C) int __qtd_QModelIndex_row(void* __this_nativeId); +private extern(C) QModelIndex __qtd_QModelIndex_sibling_int_int(void* __this_nativeId, + int row0, + int column1); +// Just the private functions for abstract functions implemeneted in superclasses + + + +// Virtual Dispatch functions diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/core/QPoint.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/core/QPoint.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,234 @@ +module qt.core.QPoint; + +public import qt.QGlobal; +public import qt.core.Qt; +public import qt.core.QDataStream; + +public struct QPoint +{ + +// Functions + public static QPoint opCall() { + QPoint pt; + pt.xp = pt.yp = 0; + return pt; + } + + public static QPoint opCall(int xpos, int ypos) { + QPoint pt; + pt.xp = xpos; + pt.yp = ypos; + return pt; + } + + bool isNull() // const + { return xp == 0 && yp == 0; } + + int x() // const + { return xp; } + + int y() // const + { return yp; } + + void x(int xpos) + { xp = xpos; } + + void y(int ypos) + { yp = ypos; } + + void setX(int xpos) // for convenience + { xp = xpos; } + + void setY(int ypos) // for convenience + { yp = ypos; } + + public final int manhattanLength() { + return qtd_QPoint_manhattanLength(this); + } +/* +inline int &rx() +{ return xp; } + +inline int &ry() +{ return yp; } +*/ + + QPoint opAddAssign(in QPoint p) + { xp+=p.xp; yp+=p.yp; return *this; } + + QPoint opSubAssign(in QPoint p) + { xp-=p.xp; yp-=p.yp; return *this; } + + QPoint opMulAssign(qreal c) + { xp = qRound(xp*c); yp = qRound(yp*c); return *this; } + + bool opEquals(in QPoint p) + { return xp == p.xp && yp == p.yp; } + + QPoint opAdd(in QPoint p) + { return QPoint(this.xp+p.xp, this.yp+p.yp); } + + QPoint opSub(in QPoint p) + { return QPoint(this.xp-p.xp, this.yp-p.yp); } + + QPoint opMul(qreal c) + { return QPoint(qRound(this.xp*c), qRound(this.yp*c)); } + + QPoint opDivAssign(qreal c) + { + xp = qRound(xp/c); + yp = qRound(yp/c); + return *this; + } + + QPoint opDiv(qreal c) + { + return QPoint(qRound(this.xp/c), qRound(this.yp/c)); + } + + public final void writeTo(QDataStream arg__1) { + qtd_QPoint_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final void readFrom(QDataStream arg__1) { + qtd_QPoint_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); + } + +private: + // ### Qt 5; remove the ifdef and just have the same order on all platforms. + version(OSX) + { + int yp; + int xp; + } + else + { + int xp; + int yp; + } +} + + +public struct QPointF +{ + public static QPointF opCall() { + QPointF pt; + pt.xp = pt.yp = 0; + return pt; + } + + public static QPointF opCall(qreal xpos, qreal ypos) { + QPointF pt; + pt.xp = xpos; + pt.yp = ypos; + return pt; + } + + public static QPointF opCall(in QPoint p) { + QPointF pt; + pt.xp = p.x(); + pt.yp = p.y(); + return pt; + } + + bool isNull() //const + { + return qIsNull(xp) && qIsNull(yp); + } + + qreal x() //const + { + return xp; + } + + qreal y() //const + { + return yp; + } + + void x(qreal xpos) + { + xp = xpos; + } + + void y(qreal ypos) + { + yp = ypos; + } +/* +inline qreal &QPointF::rx() +{ + return xp; +} + +inline qreal &QPointF::ry() +{ + return yp; +} +*/ + + QPointF opAddAssign(in QPointF p) + { xp+=p.xp; yp+=p.yp; return *this; } + + QPointF opSubAssign(in QPointF p) + { xp-=p.xp; yp-=p.yp; return *this; } + + QPointF opMulAssign(qreal c) + { xp*=c; yp*=c; return *this; } + + bool opEquals(in QPointF p) + { return qFuzzyCompare(xp, p.xp) && qFuzzyCompare(yp, p.yp); } + + QPointF opAdd(in QPointF p) + { return QPointF(this.xp+p.xp, this.yp+p.yp); } + + QPointF opSub(in QPointF p) + { return QPointF(this.xp-p.xp, this.yp-p.yp); } + + QPointF opMul(qreal c) + { return QPointF(this.xp*c, this.yp*c); } + + QPointF opDivAssign(qreal c) + { + xp/=c; + yp/=c; + return *this; + } + + QPointF opDiv(qreal c) + { + return QPointF(xp/c, yp/c); + } + + QPoint toPoint() //const + { + return QPoint(qRound(xp), qRound(yp)); + } + + public final void writeTo(QDataStream arg__1) { + qtd_QPointF_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final void readFrom(QDataStream arg__1) { + qtd_QPointF_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); + } + +private: + qreal xp; + qreal yp; +} + + +// C wrappers +// QPoint +private extern(C) int qtd_QPoint_manhattanLength(void* __this_nativeId); +private extern(C) void qtd_QPoint_writeTo_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void qtd_QPoint_readFrom_QDataStream(void* __this_nativeId, + void* arg__1); + +// QPointF +private extern(C) void qtd_QPointF_writeTo_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void qtd_QPointF_readFrom_QDataStream(void* __this_nativeId, + void* arg__1); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/core/QPointF.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/core/QPointF.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,4 @@ +module qt.core.QPointF; +/* dummy */ + +public import qt.core.QPoint; diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/core/QRect.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/core/QRect.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,382 @@ +module qt.core.QRect; + +public import qt.QGlobal; +public import qt.core.Qt; + +public import qt.core.QDataStream; +public import qt.core.QSize; +public import qt.core.QPoint; + + +public struct QRect +{ + public static QRect opCall() { + QRect rt; + rt.x1 = rt.y1 = 0; + rt.x2 = rt.y2 = -1; + return rt; + } + + public static QRect opCall(int aleft, int atop, int awidth, int aheight) + { + QRect rt; + rt.x1 = aleft; + rt.y1 = atop; + rt.x2 = (aleft + awidth - 1); + rt.y2 = (atop + aheight - 1); + return rt; + } + + public static QRect opCall(in QPoint atopLeft, in QPoint abottomRight) + { + QRect rt; + rt.x1 = atopLeft.x(); + rt.y1 = atopLeft.y(); + rt.x2 = abottomRight.x(); + rt.y2 = abottomRight.y(); + return rt; + } + + public static QRect opCall(in QPoint atopLeft, in QSize asize) + { + QRect rt; + rt.x1 = atopLeft.x(); + rt.y1 = atopLeft.y(); + rt.x2 = (rt.x1+asize.width() - 1); + rt.y2 = (rt.y1+asize.height() - 1); + return rt; + } + + bool isNull() // const + { return x2 == x1 - 1 && y2 == y1 - 1; } + + bool isEmpty() // const + { return x1 > x2 || y1 > y2; } + + bool isValid() // const + { return x1 <= x2 && y1 <= y2; } + + int left() // const + { return x1; } + + int top() // const + { return y1; } + + int right() // const + { return x2; } + + int bottom() // const + { return y2; } + + int x() // const + { return x1; } + + int y() // const + { return y1; } + + void left(int pos) + { x1 = pos; } + + void top(int pos) + { y1 = pos; } + + void right(int pos) + { x2 = pos; } + + void bottom(int pos) + { y2 = pos; } + + void setLeft(int pos) + { x1 = pos; } + + void setTop(int pos) + { y1 = pos; } + + void setRight(int pos) + { x2 = pos; } + + void setBottom(int pos) + { y2 = pos; } + + void setTopLeft(in QPoint p) + { x1 = p.x(); y1 = p.y(); } + + void setBottomRight(in QPoint p) + { x2 = p.x(); y2 = p.y(); } + + void setTopRight(in QPoint p) + { x2 = p.x(); y1 = p.y(); } + + void setBottomLeft(in QPoint p) + { x1 = p.x(); y2 = p.y(); } + + void setX(int ax) + { x1 = ax; } + + void setY(int ay) + { y1 = ay; } + + QPoint topLeft() // const + { return QPoint(x1, y1); } + + QPoint bottomRight() // const + { return QPoint(x2, y2); } + + QPoint topRight() // const + { return QPoint(x2, y1); } + + QPoint bottomLeft() // const + { return QPoint(x1, y2); } + + QPoint center() // const + { return QPoint((x1+x2)/2, (y1+y2)/2); } + + int width() // const + { return x2 - x1 + 1; } + + int height() // const + { return y2 - y1 + 1; } + + QSize size() // const + { return QSize(width(), height()); } + + void translate(int dx, int dy) + { + x1 += dx; + y1 += dy; + x2 += dx; + y2 += dy; + } + + void translate(in QPoint p) + { + x1 += p.x(); + y1 += p.y(); + x2 += p.x(); + y2 += p.y(); + } + + QRect translated(int dx, int dy) // const + { return QRect(QPoint(x1 + dx, y1 + dy), QPoint(x2 + dx, y2 + dy)); } + + QRect translated(in QPoint p) // const + { return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); } + + void moveTo(int ax, int ay) + { + x2 += ax - x1; + y2 += ay - y1; + x1 = ax; + y1 = ay; + } + + void moveTo(in QPoint p) + { + x2 += p.x() - x1; + y2 += p.y() - y1; + x1 = p.x(); + y1 = p.y(); + } + + void moveLeft(int pos) + { x2 += (pos - x1); x1 = pos; } + + void moveTop(int pos) + { y2 += (pos - y1); y1 = pos; } + + void moveRight(int pos) + { + x1 += (pos - x2); + x2 = pos; + } + + void moveBottom(int pos) + { + y1 += (pos - y2); + y2 = pos; + } + + void moveTopLeft(in QPoint p) + { + moveLeft(p.x()); + moveTop(p.y()); + } + + void moveBottomRight(in QPoint p) + { + moveRight(p.x()); + moveBottom(p.y()); + } + + void moveTopRight(in QPoint p) + { + moveRight(p.x()); + moveTop(p.y()); + } + + void moveBottomLeft(in QPoint p) + { + moveLeft(p.x()); + moveBottom(p.y()); + } + + void getRect(int *ax, int *ay, int *aw, int *ah) // const + { + *ax = x1; + *ay = y1; + *aw = x2 - x1 + 1; + *ah = y2 - y1 + 1; + } + + void setRect(int ax, int ay, int aw, int ah) + { + x1 = ax; + y1 = ay; + x2 = (ax + aw - 1); + y2 = (ay + ah - 1); + } + + void getCoords(int *xp1, int *yp1, int *xp2, int *yp2) // const + { + *xp1 = x1; + *yp1 = y1; + *xp2 = x2; + *yp2 = y2; + } + + void setCoords(int xp1, int yp1, int xp2, int yp2) + { + x1 = xp1; + y1 = yp1; + x2 = xp2; + y2 = yp2; + } + + QRect adjusted(int xp1, int yp1, int xp2, int yp2) // const + { return QRect(QPoint(x1 + xp1, y1 + yp1), QPoint(x2 + xp2, y2 + yp2)); } + + void adjust(int dx1, int dy1, int dx2, int dy2) + { + x1 += dx1; + y1 += dy1; + x2 += dx2; + y2 += dy2; + } + + void setWidth(int w) + { x2 = (x1 + w - 1); } + + void setHeight(int h) + { y2 = (y1 + h - 1); } + + void setSize(in QSize s) + { + x2 = (s.width() + x1 - 1); + y2 = (s.height() + y1 - 1); + } + + bool contains(int ax, int ay, bool aproper) // const + { + return contains(QPoint(ax, ay), aproper); + } + + bool contains(int ax, int ay) // const + { + return contains(QPoint(ax, ay), false); + } + + QRect opOrAssign(in QRect r) + { + *this = *this | r; + return *this; + } + + QRect opAndAssign(in QRect r) + { + *this = *this & r; + return *this; + } + + QRect intersected(in QRect other) // const + { + return *this & other; + } + + QRect united(in QRect r) // const + { + return *this | r; + } + + bool opEquals(in QRect r) + { + return x1==r.x1 && x2==r.x2 && y1==r.y1 && y2==r.y2; + } + + public final void writeTo(QDataStream arg__1) { + qtd_QRect_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final void readFrom(QDataStream arg__1) { + qtd_QRect_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final QRect opAnd(in QRect r) { + return qtd_QRect_operator_and_QRect(this, &r); + } + + public final QRect opOr(in QRect r) { + return qtd_QRect_operator_or_QRect(this, &r); + } + + public final bool contains(QPoint p, bool proper = false) { + return qtd_QRect_contains_QPoint_bool(this, &p, proper); + } + + public final bool contains(QRect r, bool proper = false) { + return qtd_QRect_contains_QRect_bool(this, &r, proper); + } + + public final bool intersects(QRect r) { + return qtd_QRect_intersects_QRect(this, &r); + } + + public final QRect normalized() { + return qtd_QRect_normalized(this); + } + +private: + version(OSX) + { + int y1; + int x1; + int y2; + int x2; + } + else + { + int x1; + int y1; + int x2; + int y2; + } +} + + +// C wrappers +private extern(C) bool qtd_QRect_contains_QPoint_bool(void* __this_nativeId, + void* p0, + bool proper1); +private extern(C) bool qtd_QRect_contains_QRect_bool(void* __this_nativeId, + void* r0, + bool proper1); +private extern(C) bool qtd_QRect_intersects_QRect(void* __this_nativeId, + void* r0); +private extern(C) QRect qtd_QRect_normalized(void* __this_nativeId); +private extern(C) void qtd_QRect_writeTo_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void qtd_QRect_readFrom_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) QRect qtd_QRect_operator_and_QRect(void* __this_nativeId, + void* r0); +private extern(C) QRect qtd_QRect_operator_or_QRect(void* __this_nativeId, + void* r0); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/core/QRectF.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/core/QRectF.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,338 @@ +module qt.core.QRectF; + +public import qt.QGlobal; +public import qt.core.Qt; +public import qt.core.QPointF; +public import qt.core.QRect; +public import qt.core.QSizeF; +public import qt.core.QDataStream; + + +public struct QRectF +{ + + public static QRectF opCall() + { + QRectF rt; + rt.xp = rt.yp = 0.; + rt.w = rt.h = 0.; + return rt; + } + + public static QRectF opCall(qreal aleft, qreal atop, qreal awidth, qreal aheight) + { + QRectF rt; + rt.xp = aleft; + rt.yp = atop; + rt.w = awidth; + rt.h = aheight; + return rt; + } + + public static QRectF opCall(in QPointF atopLeft, in QSizeF asize) + { + QRectF rt; + rt.xp = atopLeft.x(); + rt.yp = atopLeft.y(); + rt.w = asize.width(); + rt.h = asize.height(); + return rt; + } + + public static QRectF opCall(in QPointF atopLeft, in QPointF abottomRight) + { + QRectF rt; + rt.xp = atopLeft.x(); + rt.yp = atopLeft.y(); + rt.w = abottomRight.x() - rt.xp; + rt.h = abottomRight.y() - rt.yp; + return rt; + } + + public static QRectF opCall(in QRect r) + { + QRectF rt; + rt.xp = r.x(); + rt.yp = r.y(); + rt.w = r.width(); + rt.h = r.height(); + return rt; + } + + bool isNull() // conts + { return qIsNull(w) && qIsNull(h); } + + bool isEmpty() // conts + { return w <= 0. || h <= 0.; } + + bool isValid() // conts + { return w > 0. && h > 0.; } + + qreal x() // conts + { return xp; } + + qreal y() // conts + { return yp; } + + qreal left() // const + { return xp; } + + qreal top() // const + { return yp; } + + qreal right() // const + { return xp + w; } + + qreal bottom() // const + { return yp + h; } + + QPointF topLeft() // const + { return QPointF(xp, yp); } + + QPointF bottomRight() // const + { return QPointF(xp+w, yp+h); } + + QPointF topRight() // const + { return QPointF(xp+w, yp); } + + QPointF bottomLeft() // const + { return QPointF(xp, yp+h); } + + void setLeft(qreal pos) { qreal diff = pos - xp; xp += diff; w -= diff; } + + void setRight(qreal pos) { w = pos - xp; } + + void setTop(qreal pos) { qreal diff = pos - yp; yp += diff; h -= diff; } + + void setBottom(qreal pos) { h = pos - yp; } + + void setTopLeft(in QPointF p) { setLeft(p.x()); setTop(p.y()); } + + void setTopRight(in QPointF p) { setRight(p.x()); setTop(p.y()); } + + void setBottomLeft(in QPointF p) { setLeft(p.x()); setBottom(p.y()); } + + void setBottomRight(in QPointF p) { setRight(p.x()); setBottom(p.y()); } + + QPointF center() // conts + { return QPointF(xp + w/2, yp + h/2); } + + void moveLeft(qreal pos) { xp = pos; } + + void moveTop(qreal pos) { yp = pos; } + + void moveRight(qreal pos) { xp = pos - w; } + + void moveBottom(qreal pos) { yp = pos - h; } + + void moveTopLeft(in QPointF p) { moveLeft(p.x()); moveTop(p.y()); } + + void moveTopRight(in QPointF p) { moveRight(p.x()); moveTop(p.y()); } + + void moveBottomLeft(in QPointF p) { moveLeft(p.x()); moveBottom(p.y()); } + + void moveBottomRight(in QPointF p) { moveRight(p.x()); moveBottom(p.y()); } + + void moveCenter(in QPointF p) { xp = p.x() - w/2; yp = p.y() - h/2; } + + qreal width() // conts + { return w; } + + qreal height() // conts + { return h; } + + QSizeF size() // conts + { return QSizeF(w, h); } + + void translate(qreal dx, qreal dy) + { + xp += dx; + yp += dy; + } + + void translate(in QPointF p) + { + xp += p.x(); + yp += p.y(); + } + + void moveTo(qreal ax, qreal ay) + { + xp = ax; + yp = ay; + } + + void moveTo(in QPointF p) + { + xp = p.x(); + yp = p.y(); + } + + QRectF translated(qreal dx, qreal dy) // conts + { return QRectF(xp + dx, yp + dy, w, h); } + + QRectF translated(in QPointF p) // conts + { return QRectF(xp + p.x(), yp + p.y(), w, h); } + + void getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) // conts + { + *ax = this.xp; + *ay = this.yp; + *aaw = this.w; + *aah = this.h; + } + + void setRect(qreal ax, qreal ay, qreal aaw, qreal aah) + { + this.xp = ax; + this.yp = ay; + this.w = aaw; + this.h = aah; + } + + void getCoords(qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2) // conts + { + *xp1 = xp; + *yp1 = yp; + *xp2 = xp + w; + *yp2 = yp + h; + } + + void setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2) + { + xp = xp1; + yp = yp1; + w = xp2 - xp1; + h = yp2 - yp1; + } + + void adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2) + { xp += xp1; yp += yp1; w += xp2 - xp1; h += yp2 - yp1; } + + QRectF adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) // conts + { return QRectF(xp + xp1, yp + yp1, w + xp2 - xp1, h + yp2 - yp1); } + + void setWidth(qreal aw) // for convenience + { this.w = aw; } + + void setHeight(qreal ah) // for convenience + { this.h = ah; } + + void setSize(in QSizeF s) // for convenience + { + w = s.width(); + h = s.height(); + } + + void width(qreal aw) + { this.w = aw; } + + void height(qreal ah) + { this.h = ah; } + + void size(in QSizeF s) + { + w = s.width(); + h = s.height(); + } + + bool contains(qreal ax, qreal ay) // conts + { + return contains(QPointF(ax, ay)); + } + + QRectF opOrAssign(in QRectF r) + { + *this = *this | r; + return *this; + } + + QRectF opAndAssign(in QRectF r) + { + *this = *this & r; + return *this; + } + + QRectF intersected(in QRectF r) // conts + { + return *this & r; + } + + QRectF united(in QRectF r) // conts + { + return *this | r; + } + + bool opEquals(in QRectF r) + { + return qFuzzyCompare(xp, r.xp) && qFuzzyCompare(yp, r.yp) + && qFuzzyCompare(w, r.w) && qFuzzyCompare(h, r.h); + } + + QRect toRect() // conts + { + return QRect(qRound(xp), qRound(yp), qRound(w), qRound(h)); + } + + public final bool contains(QPointF p) { + return qtd_QRectF_contains_QPointF(this, &p); + } + + public final bool contains(QRectF r) { + return qtd_QRectF_contains_QRectF(this, &r); + } + + public final bool intersects(QRectF r) { + return qtd_QRectF_intersects_QRectF(this, &r); + } + + public final QRectF normalized() { + return qtd_QRectF_normalized(this); + } + + public final QRectF opAnd(in QRectF r) { + return qtd_QRectF_operator_and_QRectF(this, &r); + } + + public final void writeTo(QDataStream arg__1) { + qtd_QRectF_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final void readFrom(QDataStream arg__1) { + qtd_QRectF_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final QRectF opOr(in QRectF r) { + return qtd_QRectF_operator_or_QRectF(this, &r); + } + + public final QRect toAlignedRect() // const + { + return qtd_QRectF_toAlignedRect(this); + } + +private: + qreal xp; + qreal yp; + qreal w; + qreal h; +} + + +// C wrappers +private extern(C) bool qtd_QRectF_contains_QPointF(void* __this_nativeId, + void* p0); +private extern(C) bool qtd_QRectF_contains_QRectF(void* __this_nativeId, + void* r0); +private extern(C) bool qtd_QRectF_intersects_QRectF(void* __this_nativeId, + void* r0); +private extern(C) QRectF qtd_QRectF_normalized(void* __this_nativeId); +private extern(C) QRectF qtd_QRectF_operator_and_QRectF(void* __this_nativeId, + void* r0); +private extern(C) void qtd_QRectF_writeTo_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void qtd_QRectF_readFrom_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) QRectF qtd_QRectF_operator_or_QRectF(void* __this_nativeId, + void* r0); +private extern(C) QRect qtd_QRectF_toAlignedRect(void* __this_nativeId); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/core/QSize.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/core/QSize.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,276 @@ +module qt.core.QSize; + +public import qt.QGlobal; +public import qt.core.Qt; + + +public struct QSize +{ +/* ctors, reserved for D2 + public this() + { wd = ht = -1; } + + public this(int w, int h) + { wd = w; ht = h; } +*/ + + public static QSize opCall() { + QSize sz; + sz.wd = sz.ht = -1; + return sz; + } + + public static QSize opCall(int w, int h) { + QSize sz; + sz.wd = w; + sz.ht = h; + return sz; + } + + final bool isNull() + { return wd==0 && ht==0; } + + final bool isEmpty() + { return wd<1 || ht<1; } + + final bool isValid() + { return wd>=0 && ht>=0; } + + final int width() + { return wd; } + + final int height() + { return ht; } + + final void width(int w) + { wd = w; } + + final void height(int h) + { ht = h; } + + final void setWidth(int w) // for convenience + { wd = w; } + + final void setHeight(int h) // for convenience + { ht = h; } + + void transpose() { + int tmp = wd; + wd = ht; + ht = tmp; + } + + void scale(int w, int h, Qt.AspectRatioMode mode) { + scale(QSize(w, h), mode); + } + + void scale(in QSize s, Qt.AspectRatioMode mode) { + __qtd_QSize_scale_QSize_AspectRatioMode(this, &s, mode); + } + + QSize expandedTo(in QSize otherSize) { + return QSize(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht)); + } + + QSize boundedTo(in QSize otherSize) { + return QSize(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht)); + } +/* + public final void writeTo(QDataStream arg__1) { + __qtd_QSize_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.nativeId); + } + + public final void readFrom(QDataStream arg__1) { + __qtd_QSize_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.nativeId); + } +*/ + QSize opAddAssign(in QSize s) + { wd+=s.wd; ht+=s.ht; return *this; } + + QSize opSubAssign(in QSize s) + { wd-=s.wd; ht-=s.ht; return *this; } + + QSize opMulAssign(qreal c) + { wd = qRound(wd*c); ht = qRound(ht*c); return *this; } + + bool opEquals(in QSize s) + { return wd == s.wd && ht == s.ht; } + + QSize opAdd(in QSize s) + { return QSize(this.wd+s.wd, this.ht+s.ht); } + + QSize opSub(in QSize s) + { return QSize(this.wd-s.wd, this.ht-s.ht); } + + QSize opMul(qreal c) + { return QSize(qRound(this.wd*c), qRound(this.ht*c)); } + + QSize opDivAssign(qreal c) { + assert(!qFuzzyCompare(c + 1, 1.)); + wd = qRound(wd/c); ht = qRound(ht/c); + return *this; + } + + QSize opDiv(qreal c) { + assert(!qFuzzyCompare(c + 1, 1.)); + return QSize(qRound(this.wd/c), qRound(this.ht/c)); + } + +private: + int wd; + int ht; +} + + +public struct QSizeF +{ +/* ctors, reserved for D2 + this() + { wd = ht = -1.; } + + this(ref QSize sz) + { wd = sz.width(); ht = sz.height(); } + + this(qreal w, qreal h) + { wd = w; ht = h; } +*/ + public static QSizeF opCall() { + QSizeF sz; + sz.wd = sz.ht = -1.; + return sz; + } + + public static QSizeF opCall(in QSizeF s) { + QSizeF sz; + sz.wd = s.width(); sz.ht = s.height(); + return sz; + } + + public static QSizeF opCall(qreal w, qreal h) { + QSizeF sz; + sz.wd = w; sz.ht = h; + return sz; + } + + bool isNull() + { return qIsNull(wd) && qIsNull(ht); } + + bool isEmpty() + { return wd <= 0. || ht <= 0.; } + + bool isValid() + { return wd >= 0. && ht >= 0.; } + + qreal width() + { return wd; } + + qreal height() + { return ht; } + + void width(qreal w) + { wd = w; } + + void height(qreal h) + { ht = h; } + + void setWidth(qreal w) + { wd = w; } + + void setHeight(qreal h) + { ht = h; } + + void scale(qreal w, qreal h, Qt.AspectRatioMode mode) + { scale(QSizeF(w, h), mode); } + + public final void scale(QSizeF s, Qt.AspectRatioMode mode) + { __qtd_QSizeF_scale_QSizeF_AspectRatioMode(this, &s, mode); } + + void transpose() { + qreal tmp = wd; + wd = ht; + ht = tmp; + } + + QSizeF expandedTo(in QSizeF otherSize) + { return QSizeF(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht)); } + + QSizeF boundedTo(in QSizeF otherSize) + { return QSizeF(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht)); } + + QSize toSize() + { return QSize(qRound(wd), qRound(ht)); } +/* + public final void writeTo(QDataStream arg__1) { + __qtd_QSizeF_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.nativeId); + } + + public final void readFrom(QDataStream arg__1) { + __qtd_QSizeF_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.nativeId); +*/ + QSizeF opAddAssign(in QSizeF s) + { wd += s.wd; ht += s.ht; return *this; } + + QSizeF opSubAssign(in QSizeF s) + { wd -= s.wd; ht -= s.ht; return *this; } + + QSizeF opMulAssign(qreal c) + { wd *= c; ht *= c; return *this; } + + bool opEquals(in QSizeF s) + { return qFuzzyCompare(wd, s.wd) && qFuzzyCompare(ht, s.ht); } + + QSizeF opAdd(in QSizeF s) + { return QSizeF(this.wd+s.wd, this.ht+s.ht); } + + QSizeF opSub(in QSizeF s) + { return QSizeF(this.wd-s.wd, this.ht-s.ht); } + + QSizeF opMul(qreal c) + { return QSizeF(this.wd*c, this.ht*c); } + + QSizeF opDivAssign(qreal c) + { + assert(!qFuzzyCompare(c + 1, 1.)); + wd = wd/c; ht = ht/c; + return *this; + } + + QSizeF opDiv(qreal c) + { + assert(!qFuzzyCompare(c + 1, 1.)); + return QSizeF(this.wd/c, this.ht/c); + } + +private: + qreal wd; + qreal ht; +} + +extern (C) void qtd_append_array_QSize(QSize[]* arr, QSize arg) +{ + *arr ~= arg; +} + +extern (C) void qtd_append_array_QSizeF(QSizeF[]* arr, QSizeF arg) +{ + *arr ~= arg; +} + +// C wrappers +// QSize +private extern(C) void __qtd_QSize_scale_QSize_AspectRatioMode(void* __this_nativeId, + void* s0, + int mode1); +private extern(C) void __qtd_QSize_writeTo_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void __qtd_QSize_readFrom_QDataStream(void* __this_nativeId, + void* arg__1); + +// QSizeF +private extern(C) void __qtd_QSizeF_writeTo_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void __qtd_QSizeF_readFrom_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void __qtd_QSizeF_scale_QSizeF_AspectRatioMode(void* __this_nativeId, + void* s0, + int mode1); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/core/QSizeF.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/core/QSizeF.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,4 @@ +module qt.core.QSizeF; +/* dummy */ + +public import qt.core.QSize; diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/core/QString.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/core/QString.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,112 @@ +module qt.core.QString; + +import qt.QGlobal; + +version (Tango) +{ + public import tango.text.convert.Utf : toUTF8 = toString; +} +else +{ + public import std.utf : toUTF8; +} + +struct QString +{ + public static QString opCall() + { + QString str; + qtd_QString_placed_ctor(&str); + return str; + } + + ~this() + { + qtd_QString_call_destructor(&this); + } + + void opAssign(string str) + { + qtd_QString_assign_fromUtf8(&this, str); + } + + this(string str) + { + qtd_QString_new_fromUtf8_at(&this, str); + } + + public static void __constructPlacedQString(void* place, string source) { + qtd_QString_new_fromUtf8_at(place, source); + } + + // service stuff + static void* __constructNativeCopy(const void* orig) { + return qtd_QString_QString_QString(cast(void*)orig); + } + + static void* __constructPlacedNativeCopy(const void* orig, void* place) { + return qtd_QString_placed_copy(orig, place); + } + + public static void __deleteNativeObject(void* ptr) { + qtd_QString_destructor(ptr); + } + + public static void __callNativeDestructor(void* ptr) { + qtd_QString_call_destructor(ptr); + } + struct QTypeInfo + { + enum bool isComplex = true; + enum bool isStatic = false; + enum bool isLarge = false; + enum bool isPointer = false; + enum bool isDummy = false; + } + +private: + void *dummy; // sizeof(QString) == sizeof(void*) +} + +struct QStringUtil +{ + public static final string toNativeString(void* qstring) { + wchar* arr = qtd_QString_utf16(qstring); + int size = qtd_QString_size(qstring); + return .toUTF8(arr[0..size]); + } + + public static string fromUtf8(string source) { + return source; + } + + public static QStringUtil opCall(void* ptr, bool proxy) { + QStringUtil str; + str.__nativeId = ptr; + return str; + } + + public void* __nativeId; + + public final string toNativeString() { + return QStringUtil.toNativeString(__nativeId); + } + + public void assign(string text) { + qtd_QString_operatorAssign(__nativeId, text); + } +} +private extern(C) void* qtd_QString_placed_copy(const void* orig, void* place); + +private extern (C) void qtd_QString_destructor(void* __this_nativeId); +private extern (C) void qtd_QString_call_destructor(void *ptr); + +private extern (C) void* qtd_QString_QString_QString(void* orig); + +private extern (C) wchar* qtd_QString_utf16(void* __this_nativeId); +private extern (C) int qtd_QString_size(void* __this_nativeId); +private extern (C) void qtd_QString_operatorAssign(void* __this_nativeId, string text); +private extern (C) void* qtd_QString_new_fromUtf8_at(void* place, string text); + +private extern (C) void qtd_QString_placed_ctor(void* place); +private extern (C) void qtd_QString_assign_fromUtf8(QString *__qt_this, string text); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/core/QTypeInfo.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/core/QTypeInfo.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,139 @@ +module qt.core.QTypeInfo; + +//import qt.QGlobal; +//import qt.qtd.Atomic; + +/* + The catch-all template. +*/ +import std.traits; + +import qt.qtd.MetaMarshall; +import qt.core.QString; + +bool qIsDetached(T)(ref T) { return true; } + +template isBasicType(T) +{ + enum isBasicType = isNumeric!T || is(T == bool) || is(T == enum); +} + +template QTypeInfo(T) +{ + static if(is(T == string)) + { + alias QString.QTypeInfo QTypeInfo; + } + else static if(isBasicType!T) + { + public enum + { + isPointer = false, + isComplex = false, + isStatic = false, + isLarge = (T.sizeof > (void*).sizeof), + isDummy = false + } + } + else static if(is(T.QTypeInfo)) + { + alias T.QTypeInfo QTypeInfo; // alias member QTypeInfo + } + else static if ( isQObjectType!T || isObjectType!T ) + { + public enum // are pointers + { + isPointer = true, + isComplex = false, + isStatic = false, + isLarge = false, + isDummy = false + } + } + else // default parameters + { + public enum + { + isPointer = isPointer!T, + isComplex = !isPointer, + isStatic = !isPointer, + isLarge = (T.sizeof > (void*).sizeof), + isDummy = false + } + } +} + + +/* + Specialize a specific type with: + + Q_DECLARE_TYPEINFO(type, flags); + + where 'type' is the name of the type to specialize and 'flags' is + logically-OR'ed combination of the flags below. +*/ + +/* presents in QGlobal +enum { /* TYPEINFO flags + Q_COMPLEX_TYPE = 0, + Q_PRIMITIVE_TYPE = 0x1, + Q_STATIC_TYPE = 0, + Q_MOVABLE_TYPE = 0x2, + Q_DUMMY_TYPE = 0x4 +} +*/ + +/* +template QTypeInfo(alias FLAGS) +{ + template QTypeInfo(TYPE) + { + public: + enum { + isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0), + isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), + isLarge = (TYPE.sizeof > (void*).sizeof), + isPointer = false, + isDummy = (((FLAGS) & Q_DUMMY_TYPE) != 0) + } + } +} +*/ +/* + Specialize a shared type with: + + Q_DECLARE_SHARED(type); + + where 'type' is the name of the type to specialize. NOTE: shared + types must declare a 'bool isDetached(void) const;' member for this + to work. +*/ +/* +#if defined Q_CC_MSVC && _MSC_VER < 1300 +template +inline void qSwap_helper(T &value1, T &value2, T*) +{ + T t = value1; + value1 = value2; + value2 = t; +} +#define Q_DECLARE_SHARED(TYPE) \ +template <> inline bool qIsDetached(TYPE &t) { return t.isDetached(); } \ +template <> inline void qSwap_helper(TYPE &value1, TYPE &value2, TYPE*) \ +{ \ + const TYPE::DataPtr t = value1.data_ptr(); \ + value1.data_ptr() = value2.data_ptr(); \ + value2.data_ptr() = t; \ +} +#else +#define Q_DECLARE_SHARED(TYPE) \ +template <> inline bool qIsDetached(TYPE &t) { return t.isDetached(); } \ +template inline void qSwap(T &, T &); \ +template <> inline void qSwap(TYPE &value1, TYPE &value2) \ +{ \ + const TYPE::DataPtr t = value1.data_ptr(); \ + value1.data_ptr() = value2.data_ptr(); \ + value2.data_ptr() = t; \ +} +#endif +*/ \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/core/QVariant.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/core/QVariant.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,715 @@ +module qt.core.QVariant; + +public import qt.QGlobal; +private import qt.QtdObject; +private import qt.core.QMetaType; + +// automatic imports------------- +private import qt.core.QSizeF; +private import qt.core.QPoint; +private import qt.core.QRectF; +public import qt.core.Qt; +private import qt.core.QDateTime; +private import qt.core.QDataStream; +private import qt.core.QTime; +private import qt.core.QUrl; +private import qt.core.QRegExp; +private import qt.core.QBitArray; +private import qt.core.QLine; +private import qt.core.QByteArray; +private import qt.core.QSize; +private import qt.core.QDate; +private import qt.core.QPointF; +private import qt.core.QLineF; +private import qt.core.QRect; +private import qt.core.QLocale; + +version (Tango) +{ + import tango.core.Array; + import tango.stdc.stringz; + import tango.text.convert.Utf; + import tango.core.Traits; +} + + +public class QVariant : QtdObject +{ + enum Type { + Invalid = 0, + + Bool = 1, + Int = 2, + UInt = 3, + LongLong = 4, + ULongLong = 5, + Double = 6, + Char = 7, + Map = 8, + List = 9, + String = 10, + StringList = 11, + ByteArray = 12, + BitArray = 13, + Date = 14, + Time = 15, + DateTime = 16, + Url = 17, + Locale = 18, + Rect = 19, + RectF = 20, + Size = 21, + SizeF = 22, + Line = 23, + LineF = 24, + Point = 25, + PointF = 26, + RegExp = 27, + LastCoreType = RegExp, + + // value 62 is internally reserved + + Font = 64, + Pixmap = 65, + Brush = 66, + Color = 67, + Palette = 68, + Icon = 69, + Image = 70, + Polygon = 71, + Region = 72, + Bitmap = 73, + Cursor = 74, + SizePolicy = 75, + KeySequence = 76, + Pen = 77, + TextLength = 78, + TextFormat = 79, + Matrix = 80, + Transform = 81, + LastGuiType = Transform, + + UserType = 127, + + LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type + } + +// Functions + + private template getMetaId() + { + const char[] getMetaId = " + int i = qtd_MetatypeId(toStringz(name)); + if(i <= 0) + i = qRegisterMetaType!(T)(name);"; + } + + static public QVariant fromValue(T)(T obj) + { + QVariant var; + static if (is(T == class) || is(T == interface)) + { + string name = obj.classinfo.name; + mixin(getMetaId!()); + var = new QVariant(i, cast(void*)(obj)); + } + else static if (isDynamicArrayType!(T) || isStaticArrayType!(T) ) + { + string name = typeid(ElementTypeOfArray!(T)).toString ~ "[]"; + mixin(getMetaId!()); + auto darray = new DArrayToC; + darray.array = obj.dup; + var = new QVariant(i, cast(void*)(darray)); + } + else + { + string name = typeid(T).toString; + mixin(getMetaId!()); + auto data = new T; + *data = obj; + var = new QVariant(i, cast(void*)(data)); + } + return var; + } + + static public QVariant opCall(T)(T obj) + { + return fromValue(obj); + } + + public this() { + void* __qt_return_value = qtd_QVariant_QVariant(); + super(__qt_return_value); + } + + + public this(QDataStream s) { + void* __qt_return_value = qtd_QVariant_QVariant_QDataStream(s is null ? null : s.__nativeId); + super(__qt_return_value); + } + + + public this(Qt.GlobalColor color) { + void* __qt_return_value = qtd_QVariant_QVariant_GlobalColor(color); + super(__qt_return_value); + } + + + public this(bool b) { + void* __qt_return_value = qtd_QVariant_QVariant_bool(b); + super(__qt_return_value); + } + + + public this(QBitArray bitarray) { + void* __qt_return_value = qtd_QVariant_QVariant_QBitArray(bitarray is null ? null : bitarray.__nativeId); + super(__qt_return_value); + } + + + public this(QByteArray bytearray) { + void* __qt_return_value = qtd_QVariant_QVariant_QByteArray(bytearray is null ? null : bytearray.__nativeId); + super(__qt_return_value); + } + + + public this(QDate date) { + void* __qt_return_value = qtd_QVariant_QVariant_QDate(date is null ? null : date.__nativeId); + super(__qt_return_value); + } + + + public this(QDateTime datetime) { + void* __qt_return_value = qtd_QVariant_QVariant_QDateTime(datetime is null ? null : datetime.__nativeId); + super(__qt_return_value); + } + + + public this(string str) { + void* __qt_return_value = qtd_QVariant_QVariant_String(str); + super(__qt_return_value); + } + + + public this(QLine line) { + void* __qt_return_value = qtd_QVariant_QVariant_QLine(&line); + super(__qt_return_value); + } + + + public this(QLineF line) { + void* __qt_return_value = qtd_QVariant_QVariant_QLineF(&line); + super(__qt_return_value); + } + + + public this(QLocale locale) { + void* __qt_return_value = qtd_QVariant_QVariant_QLocale(locale is null ? null : locale.__nativeId); + super(__qt_return_value); + } + + + public this(QPoint pt) { + void* __qt_return_value = qtd_QVariant_QVariant_QPoint(&pt); + super(__qt_return_value); + } + + + public this(QPointF pt) { + void* __qt_return_value = qtd_QVariant_QVariant_QPointF(&pt); + super(__qt_return_value); + } + + + public this(QRect rect) { + void* __qt_return_value = qtd_QVariant_QVariant_QRect(&rect); + super(__qt_return_value); + } + + + public this(QRectF rect) { + void* __qt_return_value = qtd_QVariant_QVariant_QRectF(&rect); + super(__qt_return_value); + } + + + public this(QRegExp regExp) { + void* __qt_return_value = qtd_QVariant_QVariant_QRegExp(regExp is null ? null : regExp.__nativeId); + super(__qt_return_value); + } + + + public this(QSize size) { + void* __qt_return_value = qtd_QVariant_QVariant_QSize(&size); + super(__qt_return_value); + } + + + public this(QSizeF size) { + void* __qt_return_value = qtd_QVariant_QVariant_QSizeF(&size); + super(__qt_return_value); + } + + + public this(QTime time) { + void* __qt_return_value = qtd_QVariant_QVariant_QTime(time is null ? null : time.__nativeId); + super(__qt_return_value); + } + + + public this(QUrl url) { + void* __qt_return_value = qtd_QVariant_QVariant_QUrl(url is null ? null : url.__nativeId); + super(__qt_return_value); + } + + + public this(QVariant other) { + void* __qt_return_value = qtd_QVariant_QVariant_QVariant(other is null ? null : other.__nativeId); + super(__qt_return_value); + } + +/* + public this(char* str) { + void* __qt_return_value = qtd_QVariant_QVariant_nativepointerchar(str); + super(__qt_return_value); + } +*/ + + public this(double d) { + void* __qt_return_value = qtd_QVariant_QVariant_double(d); + super(__qt_return_value); + } + + + public this(int i) { + void* __qt_return_value = qtd_QVariant_QVariant_int(i); + super(__qt_return_value); + } + + + public this(int typeOrUserType, void* copy) { + void* __qt_return_value = qtd_QVariant_QVariant_int_nativepointervoid(typeOrUserType, copy); + super(__qt_return_value); + } + + + public this(long ll) { + void* __qt_return_value = qtd_QVariant_QVariant_long(ll); + super(__qt_return_value); + } + + + public this(uint ui) { + void* __qt_return_value = qtd_QVariant_QVariant_uint(ui); + super(__qt_return_value); + } + + + public this(ulong ull) { + void* __qt_return_value = qtd_QVariant_QVariant_ulong(ull); + super(__qt_return_value); + } + + private final bool canConvertImpl(string name) + { + int i = qtd_MetatypeId(toStringz(name)); + assert(i > 0); + return qtd_QVariant_canConvert(__nativeId, i); + } + + public final bool canConvert(Type)() { + static if ( is(Type == QBitArray) ) + return canConvertImpl("QBitArray"); + else static if ( is(Type == bool) ) + return canConvertImpl("bool"); + else static if ( is(Type == QByteArray) ) + return canConvertImpl("QByteArray"); + else static if ( is(Type == QDate) ) + return canConvertImpl("QDate"); + else static if ( is(Type == QDateTime) ) + return canConvertImpl("QDateTime"); + else static if ( is(Type == double) ) + return canConvertImpl("double"); + else static if ( is(Type == int) ) + return canConvertImpl("int"); + else static if ( is(Type == QLine) ) + return canConvertImpl("QLine"); + else static if ( is(Type == QLineF) ) + return canConvertImpl("QLineF"); + else static if ( is(Type == QLocale) ) + return canConvertImpl("QLocale"); + else static if ( is(Type == long) ) + return canConvertImpl("long"); + else static if ( is(Type == QPoint) ) + return canConvertImpl("QPoint"); + else static if ( is(Type == QPointF) ) + return canConvertImpl("QPointF"); + else static if ( is(Type == QRect) ) + return canConvertImpl("QRect"); + else static if ( is(Type == QRectF) ) + return canConvertImpl("QRectF"); + else static if ( is(Type == QRegExp) ) + return canConvertImpl("QRegExp"); + else static if ( is(Type == QSize) ) + return canConvertImpl("QSize"); + else static if ( is(Type == QSizeF) ) + return canConvertImpl("QSizeF"); + else static if ( is(Type == string) ) + return canConvertImpl("QString"); + else static if ( is(Type == QTime) ) + return canConvertImpl("QTime"); + else static if ( is(Type == uint) ) + return canConvertImpl("unsigned int"); // TODO: + else static if ( is(Type == ulong) ) + return canConvertImpl("unsigned long long"); // TODO: + else static if ( is(Type == QUrl) ) + return canConvertImpl("QUrl"); + else + { + static if( is( Type == class ) || is( Type == interface ) ) + { + Object object = cast(Object)qtd_QVariant_data(__nativeId); + if(object) + return cast(Type)(object) !is null; + return false; + } + else static if (isDynamicArrayType!(Type) || isStaticArrayType!(Type) ) + { + auto array = cast(DArrayToC*)qtd_QVariant_data(__nativeId); + return cast(Type)(array.array) !is null; + } + else + { + int i = qtd_MetatypeId(toStringz(typeid(Type).toString)); + return qtd_QVariant_canConvert(__nativeId, i); + } + } + } + + public final Type value(Type)() { + static if ( is(Type == QBitArray) ) + return toBitArra; + else static if ( is(Type == bool) ) + return toBool; + else static if ( is(Type == QByteArray) ) + return toByteArray; + else static if ( is(Type == QDate) ) + return toDate; + else static if ( is(Type == QDateTime) ) + return toDateTime; + else static if ( is(Type == double) ) + return toDouble; + else static if ( is(Type == int) ) + return toInt; + else static if ( is(Type == QLine) ) + return toLine; + else static if ( is(Type == QLineF) ) + return toLineF; + else static if ( is(Type == QLocale) ) + return toLocale; + else static if ( is(Type == long) ) + return toLongLong; + else static if ( is(Type == QPoint) ) + return toPoint; + else static if ( is(Type == QPointF) ) + return toPointF; + else static if ( is(Type == QRect) ) + return toRect; + else static if ( is(Type == QRectF) ) + return toRectF; + else static if ( is(Type == QRegExp) ) + return toRegExp; + else static if ( is(Type == QSize) ) + return toSize; + else static if ( is(Type == QSizeF) ) + return toSizeF; + else static if ( is(Type == string) ) + return toString; + else static if ( is(Type == QTime) ) + return toTime; + else static if ( is(Type == uint) ) + return toUInt; + else static if ( is(Type == ulong) ) + return toULongLong; + else static if ( is(Type == QUrl) ) + return toUrl; + else static if( is( Type == class ) || is( Type == interface ) ) + { + Object object = cast(Object)qtd_QVariant_data(__nativeId); + if(object) + return cast(Type)(object); + return null; + } + else static if (isDynamicArrayType!(Type) || isStaticArrayType!(Type) ) + { + auto array = cast(DArrayToC*)qtd_QVariant_data(__nativeId); + return cast(Type)(array.array); + } + else + { + return *cast(Type*)qtd_QVariant_data(__nativeId); + } + } + + public final void clear() { + qtd_QVariant_clear(__nativeId); + } + + protected final bool cmp(QVariant other) { + return qtd_QVariant_cmp_QVariant(__nativeId, other is null ? null : other.__nativeId); + } + + protected final void create(int type, void* copy) { + qtd_QVariant_create_int_nativepointervoid(__nativeId, type, copy); + } + + public final bool isNull() { + return qtd_QVariant_isNull(__nativeId); + } + + public final bool isValid() { + return qtd_QVariant_isValid(__nativeId); + } + + public final void load(QDataStream ds) { + qtd_QVariant_load_QDataStream(__nativeId, ds is null ? null : ds.__nativeId); + } + + public final void writeTo(QDataStream s) { + qtd_QVariant_writeTo_QDataStream(__nativeId, s is null ? null : s.__nativeId); + } + + public final QVariant operator_assign(QVariant other) { + void* __qt_return_value = qtd_QVariant_operator_assign_QVariant(__nativeId, other is null ? null : other.__nativeId); + return new QVariant(__qt_return_value, QtdObjectFlags.nativeOwnership); + } + + private final bool operator_equal(QVariant v) { + return qtd_QVariant_operator_equal_QVariant(__nativeId, v is null ? null : v.__nativeId); + } + + public final void readFrom(QDataStream s) { + qtd_QVariant_readFrom_QDataStream(__nativeId, s is null ? null : s.__nativeId); + } + + public final void save(QDataStream ds) { + qtd_QVariant_save_QDataStream(__nativeId, ds is null ? null : ds.__nativeId); + } + + public final QBitArray toBitArray() { + void* __qt_return_value = qtd_QVariant_toBitArray(__nativeId); + return new QBitArray(__qt_return_value); + } + + public final bool toBool() { + return qtd_QVariant_toBool(__nativeId); + } + + public final QByteArray toByteArray() { + void* __qt_return_value = qtd_QVariant_toByteArray(__nativeId); + return new QByteArray(__qt_return_value); + } + + public final QDate toDate() { + void* __qt_return_value = qtd_QVariant_toDate(__nativeId); + return new QDate(__qt_return_value); + } + + public final QDateTime toDateTime() { + void* __qt_return_value = qtd_QVariant_toDateTime(__nativeId); + return new QDateTime(__qt_return_value); + } + + public final double toDouble(bool* ok = null) { + return qtd_QVariant_toDouble_nativepointerbool(__nativeId, ok); + } + + public final int toInt(bool* ok = null) { + return qtd_QVariant_toInt_nativepointerbool(__nativeId, ok); + } + + public final QLine toLine() { + return qtd_QVariant_toLine(__nativeId); + } + + public final QLineF toLineF() { + return qtd_QVariant_toLineF(__nativeId); + } + + public final QLocale toLocale() { + void* __qt_return_value = qtd_QVariant_toLocale(__nativeId); + return new QLocale(__qt_return_value); + } + + public final long toLongLong(bool* ok = null) { + return qtd_QVariant_toLongLong_nativepointerbool(__nativeId, ok); + } + + public final QPoint toPoint() { + return qtd_QVariant_toPoint(__nativeId); + } + + public final QPointF toPointF() { + return qtd_QVariant_toPointF(__nativeId); + } + + public final QRect toRect() { + return qtd_QVariant_toRect(__nativeId); + } + + public final QRectF toRectF() { + return qtd_QVariant_toRectF(__nativeId); + } + + public final QRegExp toRegExp() { + void* __qt_return_value = qtd_QVariant_toRegExp(__nativeId); + return new QRegExp(__qt_return_value); + } + + public final QSize toSize() { + return qtd_QVariant_toSize(__nativeId); + } + + public final QSizeF toSizeF() { + return qtd_QVariant_toSizeF(__nativeId); + } + + public final string toString() { + string res; + qtd_QVariant_toString(__nativeId, &res); + return res; + } + + public final QTime toTime() { + void* __qt_return_value = qtd_QVariant_toTime(__nativeId); + return new QTime(__qt_return_value); + } + + public final uint toUInt(bool* ok = null) { + return qtd_QVariant_toUInt_nativepointerbool(__nativeId, ok); + } + + public final ulong toULongLong(bool* ok = null) { + return qtd_QVariant_toULongLong_nativepointerbool(__nativeId, ok); + } + + public final QUrl toUrl() { + void* __qt_return_value = qtd_QVariant_toUrl(__nativeId); + return new QUrl(__qt_return_value); + } + + public final char* typeName() { + return qtd_QVariant_typeName(__nativeId); + } + + public final Type type() { + return cast(Type)qtd_QVariant_type(__nativeId); + } + + public final int userType() { + return qtd_QVariant_userType(__nativeId); + } +// Field accessors + + public this(void* native_id, QtdObjectFlags flags = QtdObjectFlags.none) { + super(native_id, flags); + } + + protected override void __deleteNative() { + qtd_QVariant_destructor(__nativeId); + } + +// Injected code in class +} +extern (C) void qtd_QVariant_destructor(void *ptr); + + +// C wrappers +private extern(C) void* qtd_QVariant_QVariant(); +private extern(C) void* qtd_QVariant_QVariant_QDataStream(void* s0); +private extern(C) void* qtd_QVariant_QVariant_GlobalColor(int color0); +private extern(C) void* qtd_QVariant_QVariant_bool(bool b0); +private extern(C) void* qtd_QVariant_QVariant_QBitArray(void* bitarray0); +private extern(C) void* qtd_QVariant_QVariant_QByteArray(void* bytearray0); +private extern(C) void* qtd_QVariant_QVariant_QDate(void* date0); +private extern(C) void* qtd_QVariant_QVariant_QDateTime(void* datetime0); +private extern(C) void* qtd_QVariant_QVariant_String(string string0); +private extern(C) void* qtd_QVariant_QVariant_QLine(void* line0); +private extern(C) void* qtd_QVariant_QVariant_QLineF(void* line0); +private extern(C) void* qtd_QVariant_QVariant_QLocale(void* locale0); +private extern(C) void* qtd_QVariant_QVariant_QPoint(void* pt0); +private extern(C) void* qtd_QVariant_QVariant_QPointF(void* pt0); +private extern(C) void* qtd_QVariant_QVariant_QRect(void* rect0); +private extern(C) void* qtd_QVariant_QVariant_QRectF(void* rect0); +private extern(C) void* qtd_QVariant_QVariant_QRegExp(void* regExp0); +private extern(C) void* qtd_QVariant_QVariant_QSize(void* size0); +private extern(C) void* qtd_QVariant_QVariant_QSizeF(void* size0); +private extern(C) void* qtd_QVariant_QVariant_QTime(void* time0); +private extern(C) void* qtd_QVariant_QVariant_QUrl(void* url0); +private extern(C) void* qtd_QVariant_QVariant_QVariant(void* other0); +private extern(C) void* qtd_QVariant_QVariant_nativepointerchar(char* str0); +private extern(C) void* qtd_QVariant_QVariant_double(double d0); +private extern(C) void* qtd_QVariant_QVariant_int(int i0); +private extern(C) void* qtd_QVariant_QVariant_int_nativepointervoid(int typeOrUserType0, + void* copy1); +private extern(C) void* qtd_QVariant_QVariant_long(long ll0); +private extern(C) void* qtd_QVariant_QVariant_uint(uint ui0); +private extern(C) void* qtd_QVariant_QVariant_ulong(ulong ull0); +private extern(C) bool qtd_QVariant_canConvert(void* __this_nativeId, int); +private extern(C) void qtd_QVariant_clear(void* __this_nativeId); +private extern(C) bool qtd_QVariant_cmp_QVariant(void* __this_nativeId, + void* other0); +private extern(C) void qtd_QVariant_create_int_nativepointervoid(void* __this_nativeId, + int type0, + void* copy1); +private extern(C) bool qtd_QVariant_isNull(void* __this_nativeId); +private extern(C) bool qtd_QVariant_isValid(void* __this_nativeId); +private extern(C) void qtd_QVariant_load_QDataStream(void* __this_nativeId, + void* ds0); +private extern(C) void qtd_QVariant_writeTo_QDataStream(void* __this_nativeId, + void* s0); +private extern(C) void* qtd_QVariant_operator_assign_QVariant(void* __this_nativeId, + void* other0); +private extern(C) bool qtd_QVariant_operator_equal_QVariant(void* __this_nativeId, + void* v0); +private extern(C) void qtd_QVariant_readFrom_QDataStream(void* __this_nativeId, + void* s0); +private extern(C) void qtd_QVariant_save_QDataStream(void* __this_nativeId, + void* ds0); +private extern(C) void* qtd_QVariant_toBitArray(void* __this_nativeId); +private extern(C) bool qtd_QVariant_toBool(void* __this_nativeId); +private extern(C) void* qtd_QVariant_toByteArray(void* __this_nativeId); +private extern(C) void* qtd_QVariant_toDate(void* __this_nativeId); +private extern(C) void* qtd_QVariant_toDateTime(void* __this_nativeId); +private extern(C) double qtd_QVariant_toDouble_nativepointerbool(void* __this_nativeId, + bool* ok0); +private extern(C) int qtd_QVariant_toInt_nativepointerbool(void* __this_nativeId, + bool* ok0); +private extern(C) QLine qtd_QVariant_toLine(void* __this_nativeId); +private extern(C) QLineF qtd_QVariant_toLineF(void* __this_nativeId); +private extern(C) void* qtd_QVariant_toLocale(void* __this_nativeId); +private extern(C) long qtd_QVariant_toLongLong_nativepointerbool(void* __this_nativeId, + bool* ok0); +private extern(C) QPoint qtd_QVariant_toPoint(void* __this_nativeId); +private extern(C) QPointF qtd_QVariant_toPointF(void* __this_nativeId); +private extern(C) QRect qtd_QVariant_toRect(void* __this_nativeId); +private extern(C) QRectF qtd_QVariant_toRectF(void* __this_nativeId); +private extern(C) void* qtd_QVariant_toRegExp(void* __this_nativeId); +private extern(C) QSize qtd_QVariant_toSize(void* __this_nativeId); +private extern(C) QSizeF qtd_QVariant_toSizeF(void* __this_nativeId); +private extern(C) void qtd_QVariant_toString(void* __this_nativeId, + void* __java_return_value); +private extern(C) void* qtd_QVariant_toTime(void* __this_nativeId); +private extern(C) uint qtd_QVariant_toUInt_nativepointerbool(void* __this_nativeId, + bool* ok0); +private extern(C) ulong qtd_QVariant_toULongLong_nativepointerbool(void* __this_nativeId, + bool* ok0); +private extern(C) void* qtd_QVariant_toUrl(void* __this_nativeId); +private extern(C) char* qtd_QVariant_typeName(void* __this_nativeId); +private extern(C) int qtd_QVariant_type(void* __this_nativeId); +private extern(C) int qtd_QVariant_userType(void* __this_nativeId); +private extern(C) void *qtd_QVariant_data(void* __this_nativeId); + +// Just the private functions for abstract functions implemeneted in superclasses + +// Virtual Dispatch functions diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/opengl/gl.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/opengl/gl.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,7 @@ +module qt.opengl.gl; + +public +{ + import qt.opengl.gltypes; + import qt.opengl.glfuncs; +} diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/opengl/glfuncs.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/opengl/glfuncs.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,375 @@ +module qt.opengl.glfuncs; + +private import qt.opengl.gltypes; + +/* +extern (C) +{ + void glEnable(GLenum); + void glEnableClientState(GLenum); + void glDisableClientState(GLenum); + void glClear(GLbitfield); + void glLoadIdentity(); + void glBegin(GLenum); + void glColor3f(GLfloat,GLfloat,GLfloat); + void glVertex3f(GLfloat,GLfloat,GLfloat); + void glEnd(); + void glViewport(GLint,GLint,GLsizei,GLsizei); + void glMatrixMode(GLenum); + void glGetDoublev(GLenum,GLdouble*); + void glGetFloatv(GLenum,GLfloat*); + void glGetIntegerv(GLenum,GLint*); + void glScalef(GLfloat,GLfloat,GLfloat); + void glDeleteLists(GLuint, GLsizei); + void glShadeModel(GLenum); + void glTranslated(GLdouble, GLdouble, GLdouble); + void glTranslatef(GLfloat, GLfloat, GLfloat); + void glRotated(GLdouble, GLdouble, GLdouble, GLdouble); + void glCallList(GLuint); + void glOrtho (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); + GLuint glGenLists (GLsizei range); +} +alias ptrdiff_t GLintptrARB; +alias ptrdiff_t GLsizeiptrARB; + +*/ + +extern (System) +{ + void glAccum (GLenum op, GLfloat value); + void glAlphaFunc (GLenum func, GLclampf ref_); + GLboolean glAreTexturesResident (GLsizei n, GLuint *textures, GLboolean *residences); + void glArrayElement (GLint i); + void glBegin (GLenum mode); + void glBindTexture (GLenum target, GLuint texture); + void glBitmap (GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, GLubyte *bitmap); + void glBlendFunc (GLenum sfactor, GLenum dfactor); + void glCallList (GLuint list); + void glCallLists (GLsizei n, GLenum type, GLvoid *lists); + void glClear (GLbitfield mask); + void glClearAccum (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); + void glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); + void glClearDepth (GLclampd depth); + void glClearIndex (GLfloat c); + void glClearStencil (GLint s); + void glClipPlane (GLenum plane, GLdouble *equation); + void glColor3b (GLbyte red, GLbyte green, GLbyte blue); + void glColor3bv (GLbyte *v); + void glColor3d (GLdouble red, GLdouble green, GLdouble blue); + void glColor3dv (GLdouble *v); + void glColor3f (GLfloat red, GLfloat green, GLfloat blue); + void glColor3fv (GLfloat *v); + void glColor3i (GLint red, GLint green, GLint blue); + void glColor3iv (GLint *v); + void glColor3s (GLshort red, GLshort green, GLshort blue); + void glColor3sv (GLshort *v); + void glColor3ub (GLubyte red, GLubyte green, GLubyte blue); + void glColor3ubv (GLubyte *v); + void glColor3ui (GLuint red, GLuint green, GLuint blue); + void glColor3uiv (GLuint *v); + void glColor3us (GLushort red, GLushort green, GLushort blue); + void glColor3usv (GLushort *v); + void glColor4b (GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha); + void glColor4bv (GLbyte *v); + void glColor4d (GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha); + void glColor4dv (GLdouble *v); + void glColor4f (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); + void glColor4fv (GLfloat *v); + void glColor4i (GLint red, GLint green, GLint blue, GLint alpha); + void glColor4iv (GLint *v); + void glColor4s (GLshort red, GLshort green, GLshort blue, GLshort alpha); + void glColor4sv (GLshort *v); + void glColor4ub (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); + void glColor4ubv (GLubyte *v); + void glColor4ui (GLuint red, GLuint green, GLuint blue, GLuint alpha); + void glColor4uiv (GLuint *v); + void glColor4us (GLushort red, GLushort green, GLushort blue, GLushort alpha); + void glColor4usv (GLushort *v); + void glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); + void glColorMaterial (GLenum face, GLenum mode); + void glColorPointer (GLint size, GLenum type, GLsizei stride, GLvoid *pointer); + void glCopyPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum type); + void glCopyTexImage1D (GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border); + void glCopyTexImage2D (GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); + void glCopyTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); + void glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); + void glCullFace (GLenum mode); + void glDeleteLists (GLuint list, GLsizei range); + void glDeleteTextures (GLsizei n, GLuint *textures); + void glDepthFunc (GLenum func); + void glDepthMask (GLboolean flag); + void glDepthRange (GLclampd zNear, GLclampd zFar); + void glDisable (GLenum cap); + void glDisableClientState (GLenum array); + void glDrawArrays (GLenum mode, GLint first, GLsizei count); + void glDrawBuffer (GLenum mode); + void glDrawElements (GLenum mode, GLsizei count, GLenum type, GLvoid *indices); + void glDrawPixels (GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); + void glEdgeFlag (GLboolean flag); + void glEdgeFlagPointer (GLsizei stride, GLvoid *pointer); + void glEdgeFlagv (GLboolean *flag); + void glEnable (GLenum cap); + void glEnableClientState (GLenum array); + void glEnd (); + void glEndList (); + void glEvalCoord1d (GLdouble u); + void glEvalCoord1dv (GLdouble *u); + void glEvalCoord1f (GLfloat u); + void glEvalCoord1fv (GLfloat *u); + void glEvalCoord2d (GLdouble u, GLdouble v); + void glEvalCoord2dv (GLdouble *u); + void glEvalCoord2f (GLfloat u, GLfloat v); + void glEvalCoord2fv (GLfloat *u); + void glEvalMesh1 (GLenum mode, GLint i1, GLint i2); + void glEvalMesh2 (GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2); + void glEvalPoint1 (GLint i); + void glEvalPoint2 (GLint i, GLint j); + void glFeedbackBuffer (GLsizei size, GLenum type, GLfloat *buffer); + void glFinish (); + void glFlush (); + void glFogf (GLenum pname, GLfloat param); + void glFogfv (GLenum pname, GLfloat *params); + void glFogi (GLenum pname, GLint param); + void glFogiv (GLenum pname, GLint *params); + void glFrontFace (GLenum mode); + void glFrustum (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); + GLuint glGenLists (GLsizei range); + void glGenTextures (GLsizei n, GLuint *textures); + void glGetBooleanv (GLenum pname, GLboolean *params); + void glGetClipPlane (GLenum plane, GLdouble *equation); + void glGetDoublev (GLenum pname, GLdouble *params); + GLenum glGetError (); + void glGetFloatv (GLenum pname, GLfloat *params); + void glGetIntegerv (GLenum pname, GLint *params); + void glGetLightfv (GLenum light, GLenum pname, GLfloat *params); + void glGetLightiv (GLenum light, GLenum pname, GLint *params); + void glGetMapdv (GLenum target, GLenum query, GLdouble *v); + void glGetMapfv (GLenum target, GLenum query, GLfloat *v); + void glGetMapiv (GLenum target, GLenum query, GLint *v); + void glGetMaterialfv (GLenum face, GLenum pname, GLfloat *params); + void glGetMaterialiv (GLenum face, GLenum pname, GLint *params); + void glGetPixelMapfv (GLenum map, GLfloat *values); + void glGetPixelMapuiv (GLenum map, GLuint *values); + void glGetPixelMapusv (GLenum map, GLushort *values); + void glGetPointerv (GLenum pname, GLvoid* *params); + void glGetPolygonStipple (GLubyte *mask); + GLubyte * glGetString (GLenum name); + void glGetTexEnvfv (GLenum target, GLenum pname, GLfloat *params); + void glGetTexEnviv (GLenum target, GLenum pname, GLint *params); + void glGetTexGendv (GLenum coord, GLenum pname, GLdouble *params); + void glGetTexGenfv (GLenum coord, GLenum pname, GLfloat *params); + void glGetTexGeniv (GLenum coord, GLenum pname, GLint *params); + void glGetTexImage (GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); + void glGetTexLevelParameterfv (GLenum target, GLint level, GLenum pname, GLfloat *params); + void glGetTexLevelParameteriv (GLenum target, GLint level, GLenum pname, GLint *params); + void glGetTexParameterfv (GLenum target, GLenum pname, GLfloat *params); + void glGetTexParameteriv (GLenum target, GLenum pname, GLint *params); + void glHint (GLenum target, GLenum mode); + void glIndexMask (GLuint mask); + void glIndexPointer (GLenum type, GLsizei stride, GLvoid *pointer); + void glIndexd (GLdouble c); + void glIndexdv (GLdouble *c); + void glIndexf (GLfloat c); + void glIndexfv (GLfloat *c); + void glIndexi (GLint c); + void glIndexiv (GLint *c); + void glIndexs (GLshort c); + void glIndexsv (GLshort *c); + void glIndexub (GLubyte c); + void glIndexubv (GLubyte *c); + void glInitNames (); + void glInterleavedArrays (GLenum format, GLsizei stride, GLvoid *pointer); + GLboolean glIsEnabled (GLenum cap); + GLboolean glIsList (GLuint list); + GLboolean glIsTexture (GLuint texture); + void glLightModelf (GLenum pname, GLfloat param); + void glLightModelfv (GLenum pname, GLfloat *params); + void glLightModeli (GLenum pname, GLint param); + void glLightModeliv (GLenum pname, GLint *params); + void glLightf (GLenum light, GLenum pname, GLfloat param); + void glLightfv (GLenum light, GLenum pname, GLfloat *params); + void glLighti (GLenum light, GLenum pname, GLint param); + void glLightiv (GLenum light, GLenum pname, GLint *params); + void glLineStipple (GLint factor, GLushort pattern); + void glLineWidth (GLfloat width); + void glListBase (GLuint base); + void glLoadIdentity (); + void glLoadMatrixd (GLdouble *m); + void glLoadMatrixf (GLfloat *m); + void glLoadName (GLuint name); + void glLogicOp (GLenum opcode); + void glMap1d (GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, GLdouble *points); + void glMap1f (GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, GLfloat *points); + void glMap2d (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble *points); + void glMap2f (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat *points); + void glMapGrid1d (GLint un, GLdouble u1, GLdouble u2); + void glMapGrid1f (GLint un, GLfloat u1, GLfloat u2); + void glMapGrid2d (GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2); + void glMapGrid2f (GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2); + void glMaterialf (GLenum face, GLenum pname, GLfloat param); + void glMaterialfv (GLenum face, GLenum pname, GLfloat *params); + void glMateriali (GLenum face, GLenum pname, GLint param); + void glMaterialiv (GLenum face, GLenum pname, GLint *params); + void glMatrixMode (GLenum mode); + void glMultMatrixd (GLdouble *m); + void glMultMatrixf (GLfloat *m); + void glNewList (GLuint list, GLenum mode); + void glNormal3b (GLbyte nx, GLbyte ny, GLbyte nz); + void glNormal3bv (GLbyte *v); + void glNormal3d (GLdouble nx, GLdouble ny, GLdouble nz); + void glNormal3dv (GLdouble *v); + void glNormal3f (GLfloat nx, GLfloat ny, GLfloat nz); + void glNormal3fv (GLfloat *v); + void glNormal3i (GLint nx, GLint ny, GLint nz); + void glNormal3iv (GLint *v); + void glNormal3s (GLshort nx, GLshort ny, GLshort nz); + void glNormal3sv (GLshort *v); + void glNormalPointer (GLenum type, GLsizei stride, GLvoid *pointer); + void glOrtho (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); + void glPassThrough (GLfloat token); + void glPixelMapfv (GLenum map, GLsizei mapsize, GLfloat *values); + void glPixelMapuiv (GLenum map, GLsizei mapsize, GLuint *values); + void glPixelMapusv (GLenum map, GLsizei mapsize, GLushort *values); + void glPixelStoref (GLenum pname, GLfloat param); + void glPixelStorei (GLenum pname, GLint param); + void glPixelTransferf (GLenum pname, GLfloat param); + void glPixelTransferi (GLenum pname, GLint param); + void glPixelZoom (GLfloat xfactor, GLfloat yfactor); + void glPointSize (GLfloat size); + void glPolygonMode (GLenum face, GLenum mode); + void glPolygonOffset (GLfloat factor, GLfloat units); + void glPolygonStipple (GLubyte *mask); + void glPopAttrib (); + void glPopClientAttrib (); + void glPopMatrix (); + void glPopName (); + void glPrioritizeTextures (GLsizei n, GLuint *textures, GLclampf *priorities); + void glPushAttrib (GLbitfield mask); + void glPushClientAttrib (GLbitfield mask); + void glPushMatrix (); + void glPushName (GLuint name); + void glRasterPos2d (GLdouble x, GLdouble y); + void glRasterPos2dv (GLdouble *v); + void glRasterPos2f (GLfloat x, GLfloat y); + void glRasterPos2fv (GLfloat *v); + void glRasterPos2i (GLint x, GLint y); + void glRasterPos2iv (GLint *v); + void glRasterPos2s (GLshort x, GLshort y); + void glRasterPos2sv (GLshort *v); + void glRasterPos3d (GLdouble x, GLdouble y, GLdouble z); + void glRasterPos3dv (GLdouble *v); + void glRasterPos3f (GLfloat x, GLfloat y, GLfloat z); + void glRasterPos3fv (GLfloat *v); + void glRasterPos3i (GLint x, GLint y, GLint z); + void glRasterPos3iv (GLint *v); + void glRasterPos3s (GLshort x, GLshort y, GLshort z); + void glRasterPos3sv (GLshort *v); + void glRasterPos4d (GLdouble x, GLdouble y, GLdouble z, GLdouble w); + void glRasterPos4dv (GLdouble *v); + void glRasterPos4f (GLfloat x, GLfloat y, GLfloat z, GLfloat w); + void glRasterPos4fv (GLfloat *v); + void glRasterPos4i (GLint x, GLint y, GLint z, GLint w); + void glRasterPos4iv (GLint *v); + void glRasterPos4s (GLshort x, GLshort y, GLshort z, GLshort w); + void glRasterPos4sv (GLshort *v); + void glReadBuffer (GLenum mode); + void glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); + void glRectd (GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2); + void glRectdv (GLdouble *v1, GLdouble *v2); + void glRectf (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2); + void glRectfv (GLfloat *v1, GLfloat *v2); + void glRecti (GLint x1, GLint y1, GLint x2, GLint y2); + void glRectiv (GLint *v1, GLint *v2); + void glRects (GLshort x1, GLshort y1, GLshort x2, GLshort y2); + void glRectsv (GLshort *v1, GLshort *v2); + GLint glRenderMode (GLenum mode); + void glRotated (GLdouble angle, GLdouble x, GLdouble y, GLdouble z); + void glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z); + void glScaled (GLdouble x, GLdouble y, GLdouble z); + void glScalef (GLfloat x, GLfloat y, GLfloat z); + void glScissor (GLint x, GLint y, GLsizei width, GLsizei height); + void glSelectBuffer (GLsizei size, GLuint *buffer); + void glShadeModel (GLenum mode); + void glStencilFunc (GLenum func, GLint ref_, GLuint mask); + void glStencilMask (GLuint mask); + void glStencilOp (GLenum fail, GLenum zfail, GLenum zpass); + void glTexCoord1d (GLdouble s); + void glTexCoord1dv (GLdouble *v); + void glTexCoord1f (GLfloat s); + void glTexCoord1fv (GLfloat *v); + void glTexCoord1i (GLint s); + void glTexCoord1iv (GLint *v); + void glTexCoord1s (GLshort s); + void glTexCoord1sv (GLshort *v); + void glTexCoord2d (GLdouble s, GLdouble t); + void glTexCoord2dv (GLdouble *v); + void glTexCoord2f (GLfloat s, GLfloat t); + void glTexCoord2fv (GLfloat *v); + void glTexCoord2i (GLint s, GLint t); + void glTexCoord2iv (GLint *v); + void glTexCoord2s (GLshort s, GLshort t); + void glTexCoord2sv (GLshort *v); + void glTexCoord3d (GLdouble s, GLdouble t, GLdouble r); + void glTexCoord3dv (GLdouble *v); + void glTexCoord3f (GLfloat s, GLfloat t, GLfloat r); + void glTexCoord3fv (GLfloat *v); + void glTexCoord3i (GLint s, GLint t, GLint r); + void glTexCoord3iv (GLint *v); + void glTexCoord3s (GLshort s, GLshort t, GLshort r); + void glTexCoord3sv (GLshort *v); + void glTexCoord4d (GLdouble s, GLdouble t, GLdouble r, GLdouble q); + void glTexCoord4dv (GLdouble *v); + void glTexCoord4f (GLfloat s, GLfloat t, GLfloat r, GLfloat q); + void glTexCoord4fv (GLfloat *v); + void glTexCoord4i (GLint s, GLint t, GLint r, GLint q); + void glTexCoord4iv (GLint *v); + void glTexCoord4s (GLshort s, GLshort t, GLshort r, GLshort q); + void glTexCoord4sv (GLshort *v); + void glTexCoordPointer (GLint size, GLenum type, GLsizei stride, GLvoid *pointer); + void glTexEnvf (GLenum target, GLenum pname, GLfloat param); + void glTexEnvfv (GLenum target, GLenum pname, GLfloat *params); + void glTexEnvi (GLenum target, GLenum pname, GLint param); + void glTexEnviv (GLenum target, GLenum pname, GLint *params); + void glTexGend (GLenum coord, GLenum pname, GLdouble param); + void glTexGendv (GLenum coord, GLenum pname, GLdouble *params); + void glTexGenf (GLenum coord, GLenum pname, GLfloat param); + void glTexGenfv (GLenum coord, GLenum pname, GLfloat *params); + void glTexGeni (GLenum coord, GLenum pname, GLint param); + void glTexGeniv (GLenum coord, GLenum pname, GLint *params); + void glTexImage1D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, GLvoid *pixels); + void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLvoid *pixels); + void glTexParameterf (GLenum target, GLenum pname, GLfloat param); + void glTexParameterfv (GLenum target, GLenum pname, GLfloat *params); + void glTexParameteri (GLenum target, GLenum pname, GLint param); + void glTexParameteriv (GLenum target, GLenum pname, GLint *params); + void glTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, GLvoid *pixels); + void glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); + void glTranslated (GLdouble x, GLdouble y, GLdouble z); + void glTranslatef (GLfloat x, GLfloat y, GLfloat z); + void glVertex2d (GLdouble x, GLdouble y); + void glVertex2dv (GLdouble *v); + void glVertex2f (GLfloat x, GLfloat y); + void glVertex2fv (GLfloat *v); + void glVertex2i (GLint x, GLint y); + void glVertex2iv (GLint *v); + void glVertex2s (GLshort x, GLshort y); + void glVertex2sv (GLshort *v); + void glVertex3d (GLdouble x, GLdouble y, GLdouble z); + void glVertex3dv (GLdouble *v); + void glVertex3f (GLfloat x, GLfloat y, GLfloat z); + void glVertex3fv (GLfloat *v); + void glVertex3i (GLint x, GLint y, GLint z); + void glVertex3iv (GLint *v); + void glVertex3s (GLshort x, GLshort y, GLshort z); + void glVertex3sv (GLshort *v); + void glVertex4d (GLdouble x, GLdouble y, GLdouble z, GLdouble w); + void glVertex4dv (GLdouble *v); + void glVertex4f (GLfloat x, GLfloat y, GLfloat z, GLfloat w); + void glVertex4fv (GLfloat *v); + void glVertex4i (GLint x, GLint y, GLint z, GLint w); + void glVertex4iv (GLint *v); + void glVertex4s (GLshort x, GLshort y, GLshort z, GLshort w); + void glVertex4sv (GLshort *v); + void glVertexPointer (GLint size, GLenum type, GLsizei stride, GLvoid *pointer); + void glViewport (GLint x, GLint y, GLsizei width, GLsizei height); +} \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/opengl/gltypes.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/opengl/gltypes.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,631 @@ +module qt.opengl.gltypes; + +alias uint GLenum; +alias ubyte GLboolean; +alias uint GLbitfield; +alias void GLvoid; +alias byte GLbyte; +alias short GLshort; +alias int GLint; +alias ubyte GLubyte; +alias ushort GLushort; +alias uint GLuint; +alias int GLsizei; +alias float GLfloat; +alias float GLclampf; +alias double GLdouble; +alias double GLclampd; +alias char GLchar; +alias ptrdiff_t GLintptr; +alias ptrdiff_t GLsizeiptr; + +// Boolean values +enum : GLboolean +{ + GL_FALSE = 0x0, + GL_TRUE = 0x1, +} + +enum : GLenum +{ + // Data types + GL_BYTE = 0x1400, + GL_UNSIGNED_BYTE = 0x1401, + GL_SHORT = 0x1402, + GL_UNSIGNED_SHORT = 0x1403, + GL_INT = 0x1404, + GL_UNSIGNED_INT = 0x1405, + GL_FLOAT = 0x1406, + GL_DOUBLE = 0x140A, + GL_2_BYTES = 0x1407, + GL_3_BYTES = 0x1408, + GL_4_BYTES = 0x1409, + + // Primitives + GL_POINTS = 0x0000, + GL_LINES = 0x0001, + GL_LINE_LOOP = 0x0002, + GL_LINE_STRIP = 0x0003, + GL_TRIANGLES = 0x0004, + GL_TRIANGLE_STRIP = 0x0005, + GL_TRIANGLE_FAN = 0x0006, + GL_QUADS = 0x0007, + GL_QUAD_STRIP = 0x0008, + GL_POLYGON = 0x0009, + + // Vertex Arrays + GL_VERTEX_ARRAY = 0x8074, + GL_NORMAL_ARRAY = 0x8075, + GL_COLOR_ARRAY = 0x8076, + GL_INDEX_ARRAY = 0x8077, + GL_TEXTURE_COORD_ARRAY = 0x8078, + GL_EDGE_FLAG_ARRAY = 0x8079, + GL_VERTEX_ARRAY_SIZE = 0x807A, + GL_VERTEX_ARRAY_TYPE = 0x807B, + GL_VERTEX_ARRAY_STRIDE = 0x807C, + GL_NORMAL_ARRAY_TYPE = 0x807E, + GL_NORMAL_ARRAY_STRIDE = 0x807F, + GL_COLOR_ARRAY_SIZE = 0x8081, + GL_COLOR_ARRAY_TYPE = 0x8082, + GL_COLOR_ARRAY_STRIDE = 0x8083, + GL_INDEX_ARRAY_TYPE = 0x8085, + GL_INDEX_ARRAY_STRIDE = 0x8086, + GL_TEXTURE_COORD_ARRAY_SIZE = 0x8088, + GL_TEXTURE_COORD_ARRAY_TYPE = 0x8089, + GL_TEXTURE_COORD_ARRAY_STRIDE = 0x808A, + GL_EDGE_FLAG_ARRAY_STRIDE = 0x808C, + GL_VERTEX_ARRAY_POINTER = 0x808E, + GL_NORMAL_ARRAY_POINTER = 0x808F, + GL_COLOR_ARRAY_POINTER = 0x8090, + GL_INDEX_ARRAY_POINTER = 0x8091, + GL_TEXTURE_COORD_ARRAY_POINTER = 0x8092, + GL_EDGE_FLAG_ARRAY_POINTER = 0x8093, + GL_V2F = 0x2A20, + GL_V3F = 0x2A21, + GL_C4UB_V2F = 0x2A22, + GL_C4UB_V3F = 0x2A23, + GL_C3F_V3F = 0x2A24, + GL_N3F_V3F = 0x2A25, + GL_C4F_N3F_V3F = 0x2A26, + GL_T2F_V3F = 0x2A27, + GL_T4F_V4F = 0x2A28, + GL_T2F_C4UB_V3F = 0x2A29, + GL_T2F_C3F_V3F = 0x2A2A, + GL_T2F_N3F_V3F = 0x2A2B, + GL_T2F_C4F_N3F_V3F = 0x2A2C, + GL_T4F_C4F_N3F_V4F = 0x2A2D, + + // Matrix Mode + GL_MATRIX_MODE = 0x0BA0, + GL_MODELVIEW = 0x1700, + GL_PROJECTION = 0x1701, + GL_TEXTURE = 0x1702, + + // Points + GL_POINT_SMOOTH = 0x0B10, + GL_POINT_SIZE = 0x0B11, + GL_POINT_SIZE_GRANULARITY = 0x0B13, + GL_POINT_SIZE_RANGE = 0x0B12, + + // Lines + GL_LINE_SMOOTH = 0x0B20, + GL_LINE_STIPPLE = 0x0B24, + GL_LINE_STIPPLE_PATTERN = 0x0B25, + GL_LINE_STIPPLE_REPEAT = 0x0B26, + GL_LINE_WIDTH = 0x0B21, + GL_LINE_WIDTH_GRANULARITY = 0x0B23, + GL_LINE_WIDTH_RANGE = 0x0B22, + + // Polygons + GL_POINT = 0x1B00, + GL_LINE = 0x1B01, + GL_FILL = 0x1B02, + GL_CW = 0x0900, + GL_CCW = 0x0901, + GL_FRONT = 0x0404, + GL_BACK = 0x0405, + GL_POLYGON_MODE = 0x0B40, + GL_POLYGON_SMOOTH = 0x0B41, + GL_POLYGON_STIPPLE = 0x0B42, + GL_EDGE_FLAG = 0x0B43, + GL_CULL_FACE = 0x0B44, + GL_CULL_FACE_MODE = 0x0B45, + GL_FRONT_FACE = 0x0B46, + GL_POLYGON_OFFSET_FACTOR = 0x8038, + GL_POLYGON_OFFSET_UNITS = 0x2A00, + GL_POLYGON_OFFSET_POINT = 0x2A01, + GL_POLYGON_OFFSET_LINE = 0x2A02, + GL_POLYGON_OFFSET_FILL = 0x8037, + + // Display Lists + GL_COMPILE = 0x1300, + GL_COMPILE_AND_EXECUTE = 0x1301, + GL_LIST_BASE = 0x0B32, + GL_LIST_INDEX = 0x0B33, + GL_LIST_MODE = 0x0B30, + + // Depth buffer + GL_NEVER = 0x0200, + GL_LESS = 0x0201, + GL_EQUAL = 0x0202, + GL_LEQUAL = 0x0203, + GL_GREATER = 0x0204, + GL_NOTEQUAL = 0x0205, + GL_GEQUAL = 0x0206, + GL_ALWAYS = 0x0207, + GL_DEPTH_TEST = 0x0B71, + GL_DEPTH_BITS = 0x0D56, + GL_DEPTH_CLEAR_VALUE = 0x0B73, + GL_DEPTH_FUNC = 0x0B74, + GL_DEPTH_RANGE = 0x0B70, + GL_DEPTH_WRITEMASK = 0x0B72, + GL_DEPTH_COMPONENT = 0x1902, + + // Lighting + GL_LIGHTING = 0x0B50, + GL_LIGHT0 = 0x4000, + GL_LIGHT1 = 0x4001, + GL_LIGHT2 = 0x4002, + GL_LIGHT3 = 0x4003, + GL_LIGHT4 = 0x4004, + GL_LIGHT5 = 0x4005, + GL_LIGHT6 = 0x4006, + GL_LIGHT7 = 0x4007, + GL_SPOT_EXPONENT = 0x1205, + GL_SPOT_CUTOFF = 0x1206, + GL_CONSTANT_ATTENUATION = 0x1207, + GL_LINEAR_ATTENUATION = 0x1208, + GL_QUADRATIC_ATTENUATION = 0x1209, + GL_AMBIENT = 0x1200, + GL_DIFFUSE = 0x1201, + GL_SPECULAR = 0x1202, + GL_SHININESS = 0x1601, + GL_EMISSION = 0x1600, + GL_POSITION = 0x1203, + GL_SPOT_DIRECTION = 0x1204, + GL_AMBIENT_AND_DIFFUSE = 0x1602, + GL_COLOR_INDEXES = 0x1603, + GL_LIGHT_MODEL_TWO_SIDE = 0x0B52, + GL_LIGHT_MODEL_LOCAL_VIEWER = 0x0B51, + GL_LIGHT_MODEL_AMBIENT = 0x0B53, + GL_FRONT_AND_BACK = 0x0408, + GL_SHADE_MODEL = 0x0B54, + GL_FLAT = 0x1D00, + GL_SMOOTH = 0x1D01, + GL_COLOR_MATERIAL = 0x0B57, + GL_COLOR_MATERIAL_FACE = 0x0B55, + GL_COLOR_MATERIAL_PARAMETER = 0x0B56, + GL_NORMALIZE = 0x0BA1, + + // User clipping planes + GL_CLIP_PLANE0 = 0x3000, + GL_CLIP_PLANE1 = 0x3001, + GL_CLIP_PLANE2 = 0x3002, + GL_CLIP_PLANE3 = 0x3003, + GL_CLIP_PLANE4 = 0x3004, + GL_CLIP_PLANE5 = 0x3005, + + // Accumulation buffer + GL_ACCUM_RED_BITS = 0x0D58, + GL_ACCUM_GREEN_BITS = 0x0D59, + GL_ACCUM_BLUE_BITS = 0x0D5A, + GL_ACCUM_ALPHA_BITS = 0x0D5B, + GL_ACCUM_CLEAR_VALUE = 0x0B80, + GL_ACCUM = 0x0100, + GL_ADD = 0x0104, + GL_LOAD = 0x0101, + GL_MULT = 0x0103, + GL_RETURN = 0x0102, + + // Alpha testing + GL_ALPHA_TEST = 0x0BC0, + GL_ALPHA_TEST_REF = 0x0BC2, + GL_ALPHA_TEST_FUNC = 0x0BC1, + + // Blending + GL_BLEND = 0x0BE2, + GL_BLEND_SRC = 0x0BE1, + GL_BLEND_DST = 0x0BE0, + GL_ZERO = 0x0, + GL_ONE = 0x1, + GL_SRC_COLOR = 0x0300, + GL_ONE_MINUS_SRC_COLOR = 0x0301, + GL_SRC_ALPHA = 0x0302, + GL_ONE_MINUS_SRC_ALPHA = 0x0303, + GL_DST_ALPHA = 0x0304, + GL_ONE_MINUS_DST_ALPHA = 0x0305, + GL_DST_COLOR = 0x0306, + GL_ONE_MINUS_DST_COLOR = 0x0307, + GL_SRC_ALPHA_SATURATE = 0x0308, + + // Render Mode + GL_FEEDBACK = 0x1C01, + GL_RENDER = 0x1C00, + GL_SELECT = 0x1C02, + + // Feedback + GL_2D = 0x0600, + GL_3D = 0x0601, + GL_3D_COLOR = 0x0602, + GL_3D_COLOR_TEXTURE = 0x0603, + GL_4D_COLOR_TEXTURE = 0x0604, + GL_POINT_TOKEN = 0x0701, + GL_LINE_TOKEN = 0x0702, + GL_LINE_RESET_TOKEN = 0x0707, + GL_POLYGON_TOKEN = 0x0703, + GL_BITMAP_TOKEN = 0x0704, + GL_DRAW_PIXEL_TOKEN = 0x0705, + GL_COPY_PIXEL_TOKEN = 0x0706, + GL_PASS_THROUGH_TOKEN = 0x0700, + GL_FEEDBACK_BUFFER_POINTER = 0x0DF0, + GL_FEEDBACK_BUFFER_SIZE = 0x0DF1, + GL_FEEDBACK_BUFFER_TYPE = 0x0DF2, + + // Selection + GL_SELECTION_BUFFER_POINTER = 0x0DF3, + GL_SELECTION_BUFFER_SIZE = 0x0DF4, + + // Fog + GL_FOG = 0x0B60, + GL_FOG_MODE = 0x0B65, + GL_FOG_DENSITY = 0x0B62, + GL_FOG_COLOR = 0x0B66, + GL_FOG_INDEX = 0x0B61, + GL_FOG_START = 0x0B63, + GL_FOG_END = 0x0B64, + GL_LINEAR = 0x2601, + GL_EXP = 0x0800, + GL_EXP2 = 0x0801, + + // Logic Ops + GL_LOGIC_OP = 0x0BF1, + GL_INDEX_LOGIC_OP = 0x0BF1, + GL_COLOR_LOGIC_OP = 0x0BF2, + GL_LOGIC_OP_MODE = 0x0BF0, + GL_CLEAR = 0x1500, + GL_SET = 0x150F, + GL_COPY = 0x1503, + GL_COPY_INVERTED = 0x150C, + GL_NOOP = 0x1505, + GL_INVERT = 0x150A, + GL_AND = 0x1501, + GL_NAND = 0x150E, + GL_OR = 0x1507, + GL_NOR = 0x1508, + GL_XOR = 0x1506, + GL_EQUIV = 0x1509, + GL_AND_REVERSE = 0x1502, + GL_AND_INVERTED = 0x1504, + GL_OR_REVERSE = 0x150B, + GL_OR_INVERTED = 0x150D, + + // Stencil + GL_STENCIL_TEST = 0x0B90, + GL_STENCIL_WRITEMASK = 0x0B98, + GL_STENCIL_BITS = 0x0D57, + GL_STENCIL_FUNC = 0x0B92, + GL_STENCIL_VALUE_MASK = 0x0B93, + GL_STENCIL_REF = 0x0B97, + GL_STENCIL_FAIL = 0x0B94, + GL_STENCIL_PASS_DEPTH_PASS = 0x0B96, + GL_STENCIL_PASS_DEPTH_FAIL = 0x0B95, + GL_STENCIL_CLEAR_VALUE = 0x0B91, + GL_STENCIL_INDEX = 0x1901, + GL_KEEP = 0x1E00, + GL_REPLACE = 0x1E01, + GL_INCR = 0x1E02, + GL_DECR = 0x1E03, + + // Buffers, Pixel Drawing/Reading + GL_NONE = 0x0, + GL_LEFT = 0x0406, + GL_RIGHT = 0x0407, + GL_FRONT_LEFT = 0x0400, + GL_FRONT_RIGHT = 0x0401, + GL_BACK_LEFT = 0x0402, + GL_BACK_RIGHT = 0x0403, + GL_AUX0 = 0x0409, + GL_AUX1 = 0x040A, + GL_AUX2 = 0x040B, + GL_AUX3 = 0x040C, + GL_COLOR_INDEX = 0x1900, + GL_RED = 0x1903, + GL_GREEN = 0x1904, + GL_BLUE = 0x1905, + GL_ALPHA = 0x1906, + GL_LUMINANCE = 0x1909, + GL_LUMINANCE_ALPHA = 0x190A, + GL_ALPHA_BITS = 0x0D55, + GL_RED_BITS = 0x0D52, + GL_GREEN_BITS = 0x0D53, + GL_BLUE_BITS = 0x0D54, + GL_INDEX_BITS = 0x0D51, + GL_SUBPIXEL_BITS = 0x0D50, + GL_AUX_BUFFERS = 0x0C00, + GL_READ_BUFFER = 0x0C02, + GL_DRAW_BUFFER = 0x0C01, + GL_DOUBLEBUFFER = 0x0C32, + GL_STEREO = 0x0C33, + GL_BITMAP = 0x1A00, + GL_COLOR = 0x1800, + GL_DEPTH = 0x1801, + GL_STENCIL = 0x1802, + GL_DITHER = 0x0BD0, + GL_RGB = 0x1907, + GL_RGBA = 0x1908, + + // Implementation limits + GL_MAX_LIST_NESTING = 0x0B31, + GL_MAX_ATTRIB_STACK_DEPTH = 0x0D35, + GL_MAX_MODELVIEW_STACK_DEPTH = 0x0D36, + GL_MAX_NAME_STACK_DEPTH = 0x0D37, + GL_MAX_PROJECTION_STACK_DEPTH = 0x0D38, + GL_MAX_TEXTURE_STACK_DEPTH = 0x0D39, + GL_MAX_EVAL_ORDER = 0x0D30, + GL_MAX_LIGHTS = 0x0D31, + GL_MAX_CLIP_PLANES = 0x0D32, + GL_MAX_TEXTURE_SIZE = 0x0D33, + GL_MAX_PIXEL_MAP_TABLE = 0x0D34, + GL_MAX_VIEWPORT_DIMS = 0x0D3A, + GL_MAX_CLIENT_ATTRIB_STACK_DEPTH = 0x0D3B, + + // Gets + GL_ATTRIB_STACK_DEPTH = 0x0BB0, + GL_CLIENT_ATTRIB_STACK_DEPTH = 0x0BB1, + GL_COLOR_CLEAR_VALUE = 0x0C22, + GL_COLOR_WRITEMASK = 0x0C23, + GL_CURRENT_INDEX = 0x0B01, + GL_CURRENT_COLOR = 0x0B00, + GL_CURRENT_NORMAL = 0x0B02, + GL_CURRENT_RASTER_COLOR = 0x0B04, + GL_CURRENT_RASTER_DISTANCE = 0x0B09, + GL_CURRENT_RASTER_INDEX = 0x0B05, + GL_CURRENT_RASTER_POSITION = 0x0B07, + GL_CURRENT_RASTER_TEXTURE_COORDS = 0x0B06, + GL_CURRENT_RASTER_POSITION_VALID = 0x0B08, + GL_CURRENT_TEXTURE_COORDS = 0x0B03, + GL_INDEX_CLEAR_VALUE = 0x0C20, + GL_INDEX_MODE = 0x0C30, + GL_INDEX_WRITEMASK = 0x0C21, + GL_MODELVIEW_MATRIX = 0x0BA6, + GL_MODELVIEW_STACK_DEPTH = 0x0BA3, + GL_NAME_STACK_DEPTH = 0x0D70, + GL_PROJECTION_MATRIX = 0x0BA7, + GL_PROJECTION_STACK_DEPTH = 0x0BA4, + GL_RENDER_MODE = 0x0C40, + GL_RGBA_MODE = 0x0C31, + GL_TEXTURE_MATRIX = 0x0BA8, + GL_TEXTURE_STACK_DEPTH = 0x0BA5, + GL_VIEWPORT = 0x0BA2, + + // Evaluators + GL_AUTO_NORMAL = 0x0D80, + GL_MAP1_COLOR_4 = 0x0D90, + GL_MAP1_GRID_DOMAIN = 0x0DD0, + GL_MAP1_GRID_SEGMENTS = 0x0DD1, + GL_MAP1_INDEX = 0x0D91, + GL_MAP1_NORMAL = 0x0D92, + GL_MAP1_TEXTURE_COORD_1 = 0x0D93, + GL_MAP1_TEXTURE_COORD_2 = 0x0D94, + GL_MAP1_TEXTURE_COORD_3 = 0x0D95, + GL_MAP1_TEXTURE_COORD_4 = 0x0D96, + GL_MAP1_VERTEX_3 = 0x0D97, + GL_MAP1_VERTEX_4 = 0x0D98, + GL_MAP2_COLOR_4 = 0x0DB0, + GL_MAP2_GRID_DOMAIN = 0x0DD2, + GL_MAP2_GRID_SEGMENTS = 0x0DD3, + GL_MAP2_INDEX = 0x0DB1, + GL_MAP2_NORMAL = 0x0DB2, + GL_MAP2_TEXTURE_COORD_1 = 0x0DB3, + GL_MAP2_TEXTURE_COORD_2 = 0x0DB4, + GL_MAP2_TEXTURE_COORD_3 = 0x0DB5, + GL_MAP2_TEXTURE_COORD_4 = 0x0DB6, + GL_MAP2_VERTEX_3 = 0x0DB7, + GL_MAP2_VERTEX_4 = 0x0DB8, + GL_COEFF = 0x0A00, + GL_DOMAIN = 0x0A02, + GL_ORDER = 0x0A01, + + // Hints + GL_FOG_HINT = 0x0C54, + GL_LINE_SMOOTH_HINT = 0x0C52, + GL_PERSPECTIVE_CORRECTION_HINT = 0x0C50, + GL_POINT_SMOOTH_HINT = 0x0C51, + GL_POLYGON_SMOOTH_HINT = 0x0C53, + GL_DONT_CARE = 0x1100, + GL_FASTEST = 0x1101, + GL_NICEST = 0x1102, + + // Scissor box + GL_SCISSOR_TEST = 0x0C11, + GL_SCISSOR_BOX = 0x0C10, + + // Pixel Mode / Transfer + GL_MAP_COLOR = 0x0D10, + GL_MAP_STENCIL = 0x0D11, + GL_INDEX_SHIFT = 0x0D12, + GL_INDEX_OFFSET = 0x0D13, + GL_RED_SCALE = 0x0D14, + GL_RED_BIAS = 0x0D15, + GL_GREEN_SCALE = 0x0D18, + GL_GREEN_BIAS = 0x0D19, + GL_BLUE_SCALE = 0x0D1A, + GL_BLUE_BIAS = 0x0D1B, + GL_ALPHA_SCALE = 0x0D1C, + GL_ALPHA_BIAS = 0x0D1D, + GL_DEPTH_SCALE = 0x0D1E, + GL_DEPTH_BIAS = 0x0D1F, + GL_PIXEL_MAP_S_TO_S_SIZE = 0x0CB1, + GL_PIXEL_MAP_I_TO_I_SIZE = 0x0CB0, + GL_PIXEL_MAP_I_TO_R_SIZE = 0x0CB2, + GL_PIXEL_MAP_I_TO_G_SIZE = 0x0CB3, + GL_PIXEL_MAP_I_TO_B_SIZE = 0x0CB4, + GL_PIXEL_MAP_I_TO_A_SIZE = 0x0CB5, + GL_PIXEL_MAP_R_TO_R_SIZE = 0x0CB6, + GL_PIXEL_MAP_G_TO_G_SIZE = 0x0CB7, + GL_PIXEL_MAP_B_TO_B_SIZE = 0x0CB8, + GL_PIXEL_MAP_A_TO_A_SIZE = 0x0CB9, + GL_PIXEL_MAP_S_TO_S = 0x0C71, + GL_PIXEL_MAP_I_TO_I = 0x0C70, + GL_PIXEL_MAP_I_TO_R = 0x0C72, + GL_PIXEL_MAP_I_TO_G = 0x0C73, + GL_PIXEL_MAP_I_TO_B = 0x0C74, + GL_PIXEL_MAP_I_TO_A = 0x0C75, + GL_PIXEL_MAP_R_TO_R = 0x0C76, + GL_PIXEL_MAP_G_TO_G = 0x0C77, + GL_PIXEL_MAP_B_TO_B = 0x0C78, + GL_PIXEL_MAP_A_TO_A = 0x0C79, + GL_PACK_ALIGNMENT = 0x0D05, + GL_PACK_LSB_FIRST = 0x0D01, + GL_PACK_ROW_LENGTH = 0x0D02, + GL_PACK_SKIP_PIXELS = 0x0D04, + GL_PACK_SKIP_ROWS = 0x0D03, + GL_PACK_SWAP_BYTES = 0x0D00, + GL_UNPACK_ALIGNMENT = 0x0CF5, + GL_UNPACK_LSB_FIRST = 0x0CF1, + GL_UNPACK_ROW_LENGTH = 0x0CF2, + GL_UNPACK_SKIP_PIXELS = 0x0CF4, + GL_UNPACK_SKIP_ROWS = 0x0CF3, + GL_UNPACK_SWAP_BYTES = 0x0CF0, + GL_ZOOM_X = 0x0D16, + GL_ZOOM_Y = 0x0D17, + + // Texture mapping + GL_TEXTURE_ENV = 0x2300, + GL_TEXTURE_ENV_MODE = 0x2200, + GL_TEXTURE_1D = 0x0DE0, + GL_TEXTURE_2D = 0x0DE1, + GL_TEXTURE_WRAP_S = 0x2802, + GL_TEXTURE_WRAP_T = 0x2803, + GL_TEXTURE_MAG_FILTER = 0x2800, + GL_TEXTURE_MIN_FILTER = 0x2801, + GL_TEXTURE_ENV_COLOR = 0x2201, + GL_TEXTURE_GEN_S = 0x0C60, + GL_TEXTURE_GEN_T = 0x0C61, + GL_TEXTURE_GEN_MODE = 0x2500, + GL_TEXTURE_BORDER_COLOR = 0x1004, + GL_TEXTURE_WIDTH = 0x1000, + GL_TEXTURE_HEIGHT = 0x1001, + GL_TEXTURE_BORDER = 0x1005, + GL_TEXTURE_COMPONENTS = 0x1003, + GL_TEXTURE_RED_SIZE = 0x805C, + GL_TEXTURE_GREEN_SIZE = 0x805D, + GL_TEXTURE_BLUE_SIZE = 0x805E, + GL_TEXTURE_ALPHA_SIZE = 0x805F, + GL_TEXTURE_LUMINANCE_SIZE = 0x8060, + GL_TEXTURE_INTENSITY_SIZE = 0x8061, + GL_NEAREST_MIPMAP_NEAREST = 0x2700, + GL_NEAREST_MIPMAP_LINEAR = 0x2702, + GL_LINEAR_MIPMAP_NEAREST = 0x2701, + GL_LINEAR_MIPMAP_LINEAR = 0x2703, + GL_OBJECT_LINEAR = 0x2401, + GL_OBJECT_PLANE = 0x2501, + GL_EYE_LINEAR = 0x2400, + GL_EYE_PLANE = 0x2502, + GL_SPHERE_MAP = 0x2402, + GL_DECAL = 0x2101, + GL_MODULATE = 0x2100, + GL_NEAREST = 0x2600, + GL_REPEAT = 0x2901, + GL_CLAMP = 0x2900, + GL_S = 0x2000, + GL_T = 0x2001, + GL_R = 0x2002, + GL_Q = 0x2003, + GL_TEXTURE_GEN_R = 0x0C62, + GL_TEXTURE_GEN_Q = 0x0C63, + + // Utility + GL_VENDOR = 0x1F00, + GL_RENDERER = 0x1F01, + GL_VERSION = 0x1F02, + GL_EXTENSIONS = 0x1F03, + + // Errors + GL_NO_ERROR = 0x0, + GL_INVALID_VALUE = 0x0501, + GL_INVALID_ENUM = 0x0500, + GL_INVALID_OPERATION = 0x0502, + GL_STACK_OVERFLOW = 0x0503, + GL_STACK_UNDERFLOW = 0x0504, + GL_OUT_OF_MEMORY = 0x0505, +} + +// glPush/PopAttrib bits +enum : GLuint +{ + GL_CURRENT_BIT = 0x00000001, + GL_POINT_BIT = 0x00000002, + GL_LINE_BIT = 0x00000004, + GL_POLYGON_BIT = 0x00000008, + GL_POLYGON_STIPPLE_BIT = 0x00000010, + GL_PIXEL_MODE_BIT = 0x00000020, + GL_LIGHTING_BIT = 0x00000040, + GL_FOG_BIT = 0x00000080, + GL_DEPTH_BUFFER_BIT = 0x00000100, + GL_ACCUM_BUFFER_BIT = 0x00000200, + GL_STENCIL_BUFFER_BIT = 0x00000400, + GL_VIEWPORT_BIT = 0x00000800, + GL_TRANSFORM_BIT = 0x00001000, + GL_ENABLE_BIT = 0x00002000, + GL_COLOR_BUFFER_BIT = 0x00004000, + GL_HINT_BIT = 0x00008000, + GL_EVAL_BIT = 0x00010000, + GL_LIST_BIT = 0x00020000, + GL_TEXTURE_BIT = 0x00040000, + GL_SCISSOR_BIT = 0x00080000, + GL_ALL_ATTRIB_BITS = 0x000FFFFF, +} + +// gl 1.1 +enum : GLenum +{ +GL_PROXY_TEXTURE_1D = 0x8063, +GL_PROXY_TEXTURE_2D = 0x8064, +GL_TEXTURE_PRIORITY = 0x8066, +GL_TEXTURE_RESIDENT = 0x8067, +GL_TEXTURE_BINDING_1D = 0x8068, +GL_TEXTURE_BINDING_2D = 0x8069, +GL_TEXTURE_INTERNAL_FORMAT = 0x1003, +GL_ALPHA4 = 0x803B, +GL_ALPHA8 = 0x803C, +GL_ALPHA12 = 0x803D, +GL_ALPHA16 = 0x803E, +GL_LUMINANCE4 = 0x803F, +GL_LUMINANCE8 = 0x8040, +GL_LUMINANCE12 = 0x8041, +GL_LUMINANCE16 = 0x8042, +GL_LUMINANCE4_ALPHA4 = 0x8043, +GL_LUMINANCE6_ALPHA2 = 0x8044, +GL_LUMINANCE8_ALPHA8 = 0x8045, +GL_LUMINANCE12_ALPHA4 = 0x8046, +GL_LUMINANCE12_ALPHA12 = 0x8047, +GL_LUMINANCE16_ALPHA16 = 0x8048, +GL_INTENSITY = 0x8049, +GL_INTENSITY4 = 0x804A, +GL_INTENSITY8 = 0x804B, +GL_INTENSITY12 = 0x804C, +GL_INTENSITY16 = 0x804D, +GL_R3_G3_B2 = 0x2A10, +GL_RGB4 = 0x804F, +GL_RGB5 = 0x8050, +GL_RGB8 = 0x8051, +GL_RGB10 = 0x8052, +GL_RGB12 = 0x8053, +GL_RGB16 = 0x8054, +GL_RGBA2 = 0x8055, +GL_RGBA4 = 0x8056, +GL_RGB5_A1 = 0x8057, +GL_RGBA8 = 0x8058, +GL_RGB10_A2 = 0x8059, +GL_RGBA12 = 0x805A, +GL_RGBA16 = 0x805B, +} + +enum : GLuint +{ + GL_CLIENT_PIXEL_STORE_BIT = 0x00000001, + GL_CLIENT_VERTEX_ARRAY_BIT = 0x00000002, + GL_ALL_CLIENT_ATTRIB_BITS = 0xFFFFFFFF, + GL_CLIENT_ALL_ATTRIB_BITS = 0xFFFFFFFF, +} diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qt/opengl/glu.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/opengl/glu.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,196 @@ +module qt.opengl.glu; + +private import qt.opengl.gltypes; + +//============================================================================== +// CONSTANTS +//============================================================================== +enum : GLenum +{ + // StringName + GLU_VERSION = 100800, + GLU_EXTENSIONS = 100801, + // ErrorCode + GLU_INVALID_ENUM = 100900, + GLU_INVALID_VALUE = 100901, + GLU_OUT_OF_MEMORY = 100902, + GLU_INVALID_OPERATION = 100904, + // NurbsDisplay + GLU_OUTLINE_POLYGON = 100240, + GLU_OUTLINE_PATCH = 100241, + // NurbsCallback + GLU_NURBS_ERROR = 100103, + GLU_ERROR = 100103, + GLU_NURBS_BEGIN = 100164, + GLU_NURBS_BEGIN_EXT = 100164, + GLU_NURBS_VERTEX = 100165, + GLU_NURBS_VERTEX_EXT = 100165, + GLU_NURBS_NORMAL = 100166, + GLU_NURBS_NORMAL_EXT = 100166, + GLU_NURBS_COLOR = 100167, + GLU_NURBS_COLOR_EXT = 100167, + GLU_NURBS_TEXTURE_COORD = 100168, + GLU_NURBS_TEX_COORD_EXT = 100168, + GLU_NURBS_END = 100169, + GLU_NURBS_END_EXT = 100169, + GLU_NURBS_BEGIN_DATA = 100170, + GLU_NURBS_BEGIN_DATA_EXT = 100170, + GLU_NURBS_VERTEX_DATA = 100171, + GLU_NURBS_VERTEX_DATA_EXT = 100171, + GLU_NURBS_NORMAL_DATA = 100172, + GLU_NURBS_NORMAL_DATA_EXT = 100172, + GLU_NURBS_COLOR_DATA = 100173, + GLU_NURBS_COLOR_DATA_EXT = 100173, + GLU_NURBS_TEXTURE_COORD_DATA = 100174, + GLU_NURBS_TEX_COORD_DATA_EXT = 100174, + GLU_NURBS_END_DATA = 100175, + GLU_NURBS_END_DATA_EXT = 100175, + // NurbsError + GLU_NURBS_ERROR1 = 100251, + GLU_NURBS_ERROR2 = 100252, + GLU_NURBS_ERROR3 = 100253, + GLU_NURBS_ERROR4 = 100254, + GLU_NURBS_ERROR5 = 100255, + GLU_NURBS_ERROR6 = 100256, + GLU_NURBS_ERROR7 = 100257, + GLU_NURBS_ERROR8 = 100258, + GLU_NURBS_ERROR9 = 100259, + GLU_NURBS_ERROR10 = 100260, + GLU_NURBS_ERROR11 = 100261, + GLU_NURBS_ERROR12 = 100262, + GLU_NURBS_ERROR13 = 100263, + GLU_NURBS_ERROR14 = 100264, + GLU_NURBS_ERROR15 = 100265, + GLU_NURBS_ERROR16 = 100266, + GLU_NURBS_ERROR17 = 100267, + GLU_NURBS_ERROR18 = 100268, + GLU_NURBS_ERROR19 = 100269, + GLU_NURBS_ERROR20 = 100270, + GLU_NURBS_ERROR21 = 100271, + GLU_NURBS_ERROR22 = 100272, + GLU_NURBS_ERROR23 = 100273, + GLU_NURBS_ERROR24 = 100274, + GLU_NURBS_ERROR25 = 100275, + GLU_NURBS_ERROR26 = 100276, + GLU_NURBS_ERROR27 = 100277, + GLU_NURBS_ERROR28 = 100278, + GLU_NURBS_ERROR29 = 100279, + GLU_NURBS_ERROR30 = 100280, + GLU_NURBS_ERROR31 = 100281, + GLU_NURBS_ERROR32 = 100282, + GLU_NURBS_ERROR33 = 100283, + GLU_NURBS_ERROR34 = 100284, + GLU_NURBS_ERROR35 = 100285, + GLU_NURBS_ERROR36 = 100286, + GLU_NURBS_ERROR37 = 100287, + // NurbsProperty + GLU_AUTO_LOAD_MATRIX = 100200, + GLU_CULLING = 100201, + GLU_SAMPLING_TOLERANCE = 100203, + GLU_DISPLAY_MODE = 100204, + GLU_PARAMETRIC_TOLERANCE = 100202, + GLU_SAMPLING_METHOD = 100205, + GLU_U_STEP = 100206, + GLU_V_STEP = 100207, + GLU_NURBS_MODE = 100160, + GLU_NURBS_MODE_EXT = 100160, + GLU_NURBS_TESSELLATOR = 100161, + GLU_NURBS_TESSELLATOR_EXT = 100161, + GLU_NURBS_RENDERER = 100162, + GLU_NURBS_RENDERER_EXT = 100162, + // NurbsSampling + GLU_OBJECT_PARAMETRIC_ERROR = 100208, + GLU_OBJECT_PARAMETRIC_ERROR_EXT = 100208, + GLU_OBJECT_PATH_LENGTH = 100209, + GLU_OBJECT_PATH_LENGTH_EXT = 100209, + GLU_PATH_LENGTH = 100215, + GLU_PARAMETRIC_ERROR = 100216, + GLU_DOMAIN_DISTANCE = 100217, + // NurbsTrim + GLU_MAP1_TRIM_2 = 100210, + GLU_MAP2_TRIM_3 = 100211, + // QuadricDrawStyle + GLU_POINT = 100010, + GLU_LINE = 100011, + GLU_FILL = 100012, + GLU_SILHOUETTE = 100013, + // QuadricNormal + GLU_SMOOTH = 100000, + GLU_FLAT = 100001, + GLU_NONE = 100002, + // QuadricOrientation + GLU_OUTSIDE = 100020, + GLU_INSIDE = 100021, + // TessCallback + GLU_TESS_BEGIN = 100100, + GLU_BEGIN = 100100, + GLU_TESS_VERTEX = 100101, + GLU_VERTEX = 100101, + GLU_TESS_END = 100102, + GLU_END = 100102, + GLU_TESS_ERROR = 100103, + GLU_TESS_EDGE_FLAG = 100104, + GLU_EDGE_FLAG = 100104, + GLU_TESS_COMBINE = 100105, + GLU_TESS_BEGIN_DATA = 100106, + GLU_TESS_VERTEX_DATA = 100107, + GLU_TESS_END_DATA = 100108, + GLU_TESS_ERROR_DATA = 100109, + GLU_TESS_EDGE_FLAG_DATA = 100110, + GLU_TESS_COMBINE_DATA = 100111, + // TessContour + GLU_CW = 100120, + GLU_CCW = 100121, + GLU_INTERIOR = 100122, + GLU_EXTERIOR = 100123, + GLU_UNKNOWN = 100124, + // TessProperty + GLU_TESS_WINDING_RULE = 100140, + GLU_TESS_BOUNDARY_ONLY = 100141, + GLU_TESS_TOLERANCE = 100142, + // TessError + GLU_TESS_ERROR1 = 100151, + GLU_TESS_ERROR2 = 100152, + GLU_TESS_ERROR3 = 100153, + GLU_TESS_ERROR4 = 100154, + GLU_TESS_ERROR5 = 100155, + GLU_TESS_ERROR6 = 100156, + GLU_TESS_ERROR7 = 100157, + GLU_TESS_ERROR8 = 100158, + GLU_TESS_MISSING_BEGIN_POLYGON = 100151, + GLU_TESS_MISSING_BEGIN_COUNTER = 100152, + GLU_TESS_MISSING_END_POLYGON = 100153, + GLU_TESS_MISSING_END_COUNTER = 100154, + GLU_TESS_COORD_TOO_LARGE = 100155, + GLU_TESS_NEED_COMBINE_CALLBACK = 100156, + // TessWinding + GLU_TESS_WINDING_ODD = 100130, + GLU_TESS_WINDING_NONZERO = 100131, + GLU_TESS_WINDING_POSITIVE = 100132, + GLU_TESS_WINDING_NEGATIVE = 100133, + GLU_TESS_WINDING_ABS_GEQ_TWO = 100134, +} + +const GLdouble GLU_TESS_MAX_COORD = 1.0e150; + +//============================================================================== +// TYPES +//============================================================================== +struct GLUnurbs {} +struct GLUquadric {} +struct GLUtesselator {} + +typedef GLUnurbs GLUnurbsObj; +typedef GLUquadric GLUquadricObj; +typedef GLUtesselator GLUtesselatorObj; +typedef GLUtesselator GLUtriangulatorObj; + +extern(System) +{ + void gluOrtho2D(GLdouble,GLdouble,GLdouble,GLdouble); + void gluPerspective(GLdouble,GLdouble,GLdouble,GLdouble); + void gluLookAt(GLdouble,GLdouble,GLdouble,GLdouble,GLdouble,GLdouble,GLdouble,GLdouble,GLdouble); + GLint gluProject(GLdouble,GLdouble,GLdouble,GLdouble*,GLdouble*,GLint*,GLdouble*,GLdouble*,GLdouble*); + GLint gluUnProject(GLdouble,GLdouble,GLdouble,GLdouble*,GLdouble*,GLint*,GLdouble*,GLdouble*,GLdouble*); +} + diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qtd/Array.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qtd/Array.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,37 @@ +/** + * + * Copyright: Copyright QtD Team, 2008-2009 + * Authors: Max Samukha + * License: Boost License 1.0 +* +* Copyright QtD Team, 2008-2009 +* Distributed under the Boost Software License, Version 1.0. +* (See accompanying file boost-license-1.0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +* +*/ + +module qt.qtd.ArrayOpsPrimitive; + +import qt.QGlobal; + +// int +private extern(C) void qtd_allocate_int_array(int[]* arr, size_t len) +{ + *arr = new int[len]; +} + +private extern(C) void qtd_assign_int_array_element(int[]* arr, size_t pos, int elem) +{ + (*arr)[pos] = elem; +} + +private extern(C) void qtd_get_int_from_array(int* arr, size_t pos, int* elem) +{ + *elem = arr[pos]; +} + +// uint +private extern(C) void qtd_allocate_uint_array(int[]* arr, size_t len) +{ + *arr = new int[len]; +} + +private extern(C) void qtd_assign_uint_array_element(int[]* arr, size_t pos, uint elem) +{ + (*arr)[pos] = elem; +} + +private extern(C) void qtd_get_uint_from_array(uint* arr, size_t pos, uint* elem) +{ + *elem = arr[pos]; +} + +// double +private extern(C) void qtd_allocate_double_array(double[]* arr, size_t len) +{ + *arr = new double[len]; +} + +private extern(C) void qtd_assign_double_array_element(double[]* arr, size_t pos, double elem) +{ + (*arr)[pos] = elem; +} + +private extern(C) void qtd_get_double_from_array(double* arr, size_t pos, double* elem) +{ + *elem = arr[pos]; +} + +// string +private extern(C) void qtd_allocate_string_array(string[]* arr, size_t len) +{ + *arr = new string[len]; +} + +private extern(C) void qtd_assign_string_array_element(string[]* arr, size_t pos, string* elem) +{ +} + +private extern(C) void* qtd_string_from_array(string[]* arr, size_t pos) +{ + return &((*arr)[pos]); +} +/* +private extern(C) void qtd_get_string_from_array(string* arr, size_t pos, char** elem, size_t* elem_size) +{ + *elem = arr[pos].ptr; + *elem_size = arr[pos].length; +} +*/ + +private extern(C) void qtd_get_string_from_array(string* arr, size_t pos, string* elem) +{ + *elem = arr[pos]; +} + +version(cpp_shared) +{ + extern (C) void qtd_core_ArrayOps_initCallBacks(void* callbacks); + + static this() { + void*[13] callbacks; + + callbacks[0] = &qtd_allocate_int_array; + callbacks[1] = &qtd_assign_int_array_element; + callbacks[2] = &qtd_get_int_from_array; + + callbacks[3] = &qtd_allocate_uint_array; + callbacks[4] = &qtd_assign_uint_array_element; + callbacks[5] = &qtd_get_uint_from_array; + + callbacks[6] = &qtd_allocate_double_array; + callbacks[7] = &qtd_assign_double_array_element; + callbacks[8] = &qtd_get_double_from_array; + + callbacks[9] = &qtd_allocate_string_array; + callbacks[10] = &qtd_assign_string_array_element; + callbacks[11] = &qtd_string_from_array; + callbacks[12] = &qtd_get_string_from_array; + + qtd_core_ArrayOps_initCallBacks(callbacks.ptr); + } +} \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qtd/Atomic.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qtd/Atomic.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,1818 @@ +/** + * The atomic module is intended to provide some basic support for lock-free + * concurrent programming. Some common operations are defined, each of which + * may be performed using the specified memory barrier or a less granular + * barrier if the hardware does not support the version requested. This + * model is based on a design by Alexander Terekhov as outlined in + * + * this thread. Another useful reference for memory ordering on modern + * architectures is this + * article by Paul McKenney. + * + * Copyright: Copyright (C) 2005-2006 Sean Kelly. All rights reserved. + * License: BSD style: $(LICENSE) + * Authors: Sean Kelly + */ +module qt.qtd.Atomic; +//deprecated: +//////////////////////////////////////////////////////////////////////////////// +// Synchronization Options +//////////////////////////////////////////////////////////////////////////////// + + +/** + * Memory synchronization flag. If the supplied option is not available on the + * current platform then a stronger method will be used instead. + */ +enum msync +{ + raw, /// not sequenced + hlb, /// hoist-load barrier + hsb, /// hoist-store barrier + slb, /// sink-load barrier + ssb, /// sink-store barrier + acq, /// hoist-load + hoist-store barrier + rel, /// sink-load + sink-store barrier + seq, /// fully sequenced (acq + rel) +} + + +//////////////////////////////////////////////////////////////////////////////// +// Internal Type Checking +//////////////////////////////////////////////////////////////////////////////// + + +private +{ + version( D_Ddoc ) {} else + { + import std.traits; + + + template isValidAtomicType( T ) + { + const bool isValidAtomicType = T.sizeof == byte.sizeof || + T.sizeof == short.sizeof || + T.sizeof == int.sizeof || + T.sizeof == long.sizeof; + } + + + template isValidNumericType( T ) + { + const bool isValidNumericType = isIntegral!( T ) || + isPointer!( T ); + } + + + template isHoistOp( msync ms ) + { + const bool isHoistOp = ms == msync.hlb || + ms == msync.hsb || + ms == msync.acq || + ms == msync.seq; + } + + + template isSinkOp( msync ms ) + { + const bool isSinkOp = ms == msync.slb || + ms == msync.ssb || + ms == msync.rel || + ms == msync.seq; + } + } +} + + +//////////////////////////////////////////////////////////////////////////////// +// DDoc Documentation for Atomic Functions +//////////////////////////////////////////////////////////////////////////////// + + +version( D_Ddoc ) +{ + //////////////////////////////////////////////////////////////////////////// + // Atomic Load + //////////////////////////////////////////////////////////////////////////// + + + /** + * Supported msync values: + * msync.raw + * msync.hlb + * msync.acq + * msync.seq + */ + template atomicLoad( msync ms, T ) + { + /** + * Refreshes the contents of 'val' from main memory. This operation is + * both lock-free and atomic. + * + * Params: + * val = The value to load. This value must be properly aligned. + * + * Returns: + * The loaded value. + */ + T atomicLoad( ref T val ) + { + return val; + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Store + //////////////////////////////////////////////////////////////////////////// + + + /** + * Supported msync values: + * msync.raw + * msync.ssb + * msync.acq + * msync.rel + * msync.seq + */ + template atomicStore( msync ms, T ) + { + /** + * Stores 'newval' to the memory referenced by 'val'. This operation + * is both lock-free and atomic. + * + * Params: + * val = The destination variable. + * newval = The value to store. + */ + void atomicStore( ref T val, T newval ) + { + + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic StoreIf + //////////////////////////////////////////////////////////////////////////// + + + /** + * Supported msync values: + * msync.raw + * msync.ssb + * msync.acq + * msync.rel + * msync.seq + */ + template atomicStoreIf( msync ms, T ) + { + /** + * Stores 'newval' to the memory referenced by 'val' if val is equal to + * 'equalTo'. This operation is both lock-free and atomic. + * + * Params: + * val = The destination variable. + * newval = The value to store. + * equalTo = The comparison value. + * + * Returns: + * true if the store occurred, false if not. + */ + bool atomicStoreIf( ref T val, T newval, T equalTo ) + { + return false; + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Increment + //////////////////////////////////////////////////////////////////////////// + + + /** + * Supported msync values: + * msync.raw + * msync.ssb + * msync.acq + * msync.rel + * msync.seq + */ + template atomicIncrement( msync ms, T ) + { + /** + * This operation is only legal for built-in value and pointer types, + * and is equivalent to an atomic "val = val + 1" operation. This + * function exists to facilitate use of the optimized increment + * instructions provided by some architecures. If no such instruction + * exists on the target platform then the behavior will perform the + * operation using more traditional means. This operation is both + * lock-free and atomic. + * + * Params: + * val = The value to increment. + * + * Returns: + * The result of an atomicLoad of val immediately following the + * increment operation. This value is not required to be equal to the + * newly stored value. Thus, competing writes are allowed to occur + * between the increment and successive load operation. + */ + T atomicIncrement( ref T val ) + { + return val; + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Decrement + //////////////////////////////////////////////////////////////////////////// + + + /** + * Supported msync values: + * msync.raw + * msync.ssb + * msync.acq + * msync.rel + * msync.seq + */ + template atomicDecrement( msync ms, T ) + { + /** + * This operation is only legal for built-in value and pointer types, + * and is equivalent to an atomic "val = val - 1" operation. This + * function exists to facilitate use of the optimized decrement + * instructions provided by some architecures. If no such instruction + * exists on the target platform then the behavior will perform the + * operation using more traditional means. This operation is both + * lock-free and atomic. + * + * Params: + * val = The value to decrement. + * + * Returns: + * The result of an atomicLoad of val immediately following the + * increment operation. This value is not required to be equal to the + * newly stored value. Thus, competing writes are allowed to occur + * between the increment and successive load operation. + */ + T atomicDecrement( ref T val ) + { + return val; + } + } +} + + +//////////////////////////////////////////////////////////////////////////////// +// LDC Atomics Implementation +//////////////////////////////////////////////////////////////////////////////// + + +else version( LDC ) +{ + import ldc.intrinsics; + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Load + //////////////////////////////////////////////////////////////////////////// + + + template atomicLoad( msync ms = msync.seq, T ) + { + T atomicLoad(ref T val) + { + llvm_memory_barrier( + ms == msync.hlb || ms == msync.acq || ms == msync.seq, + ms == msync.hsb || ms == msync.acq || ms == msync.seq, + ms == msync.slb || ms == msync.rel || ms == msync.seq, + ms == msync.ssb || ms == msync.rel || ms == msync.seq, + false); + static if (isPointerType!(T)) + { + return cast(T)llvm_atomic_load_add!(size_t)(cast(size_t*)&val, 0); + } + else static if (is(T == bool)) + { + return llvm_atomic_load_add!(ubyte)(cast(ubyte*)&val, cast(ubyte)0) ? 1 : 0; + } + else + { + return llvm_atomic_load_add!(T)(&val, cast(T)0); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Store + //////////////////////////////////////////////////////////////////////////// + + + template atomicStore( msync ms = msync.seq, T ) + { + void atomicStore( ref T val, T newval ) + { + llvm_memory_barrier( + ms == msync.hlb || ms == msync.acq || ms == msync.seq, + ms == msync.hsb || ms == msync.acq || ms == msync.seq, + ms == msync.slb || ms == msync.rel || ms == msync.seq, + ms == msync.ssb || ms == msync.rel || ms == msync.seq, + false); + static if (isPointerType!(T)) + { + llvm_atomic_swap!(size_t)(cast(size_t*)&val, cast(size_t)newval); + } + else static if (is(T == bool)) + { + llvm_atomic_swap!(ubyte)(cast(ubyte*)&val, newval?1:0); + } + else + { + llvm_atomic_swap!(T)(&val, newval); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Store If + //////////////////////////////////////////////////////////////////////////// + + + template atomicStoreIf( msync ms = msync.seq, T ) + { + bool atomicStoreIf( ref T val, T newval, T equalTo ) + { + llvm_memory_barrier( + ms == msync.hlb || ms == msync.acq || ms == msync.seq, + ms == msync.hsb || ms == msync.acq || ms == msync.seq, + ms == msync.slb || ms == msync.rel || ms == msync.seq, + ms == msync.ssb || ms == msync.rel || ms == msync.seq, + false); + T oldval = void; + static if (isPointerType!(T)) + { + oldval = cast(T)llvm_atomic_cmp_swap!(size_t)(cast(size_t*)&val, cast(size_t)equalTo, cast(size_t)newval); + } + else static if (is(T == bool)) + { + oldval = llvm_atomic_cmp_swap!(ubyte)(cast(ubyte*)&val, equalTo?1:0, newval?1:0)?0:1; + } + else + { + oldval = llvm_atomic_cmp_swap!(T)(&val, equalTo, newval); + } + return oldval == equalTo; + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Increment + //////////////////////////////////////////////////////////////////////////// + + + template atomicIncrement( msync ms = msync.seq, T ) + { + // + // NOTE: This operation is only valid for integer or pointer types + // + static assert( isValidNumericType!(T) ); + + + T atomicIncrement( ref T val ) + { + static if (isPointerType!(T)) + { + llvm_atomic_load_add!(size_t)(cast(size_t*)&val, 1); + } + else + { + llvm_atomic_load_add!(T)(&val, cast(T)1); + } + return val; + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Decrement + //////////////////////////////////////////////////////////////////////////// + + + template atomicDecrement( msync ms = msync.seq, T ) + { + // + // NOTE: This operation is only valid for integer or pointer types + // + static assert( isValidNumericType!(T) ); + + + T atomicDecrement( ref T val ) + { + static if (isPointerType!(T)) + { + llvm_atomic_load_sub!(size_t)(cast(size_t*)&val, 1); + } + else + { + llvm_atomic_load_sub!(T)(&val, cast(T)1); + } + return val; + } + } +} + +//////////////////////////////////////////////////////////////////////////////// +// x86 Atomic Function Implementation +//////////////////////////////////////////////////////////////////////////////// + + +else version( D_InlineAsm_X86 ) +{ + version( X86 ) + { + version( BuildInfo ) + { + pragma( msg, "tango.core.Atomic: using IA-32 inline asm" ); + } + + version(darwin){ + extern(C) bool OSAtomicCompareAndSwap64(long oldValue, long newValue, long *theValue); + extern(C) bool OSAtomicCompareAndSwap64Barrier(long oldValue, long newValue, long *theValue); + } + version = Has64BitCAS; + version = Has32BitOps; + } + version( X86_64 ) + { + version( BuildInfo ) + { + pragma( msg, "tango.core.Atomic: using AMD64 inline asm" ); + } + + version = Has64BitOps; + } + + private + { + //////////////////////////////////////////////////////////////////////// + // x86 Value Requirements + //////////////////////////////////////////////////////////////////////// + + + // NOTE: Strictly speaking, the x86 supports atomic operations on + // unaligned values. However, this is far slower than the + // common case, so such behavior should be prohibited. + template atomicValueIsProperlyAligned( T ) + { + bool atomicValueIsProperlyAligned( size_t addr ) + { + return addr % T.sizeof == 0; + } + } + + + //////////////////////////////////////////////////////////////////////// + // x86 Synchronization Requirements + //////////////////////////////////////////////////////////////////////// + + + // NOTE: While x86 loads have acquire semantics for stores, it appears + // that independent loads may be reordered by some processors + // (notably the AMD64). This implies that the hoist-load barrier + // op requires an ordering instruction, which also extends this + // requirement to acquire ops (though hoist-store should not need + // one if support is added for this later). However, since no + // modern architectures will reorder dependent loads to occur + // before the load they depend on (except the Alpha), raw loads + // are actually a possible means of ordering specific sequences + // of loads in some instances. The original atomic<> + // implementation provides a 'ddhlb' ordering specifier for + // data-dependent loads to handle this situation, but as there + // are no plans to support the Alpha there is no reason to add + // that option here. + // + // For reference, the old behavior (acquire semantics for loads) + // required a memory barrier if: ms == msync.seq || isSinkOp!(ms) + template needsLoadBarrier( msync ms ) + { + const bool needsLoadBarrier = ms != msync.raw; + } + + + // NOTE: x86 stores implicitly have release semantics so a membar is only + // necessary on acquires. + template needsStoreBarrier( msync ms ) + { + const bool needsStoreBarrier = ms == msync.seq || isHoistOp!(ms); + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Load + //////////////////////////////////////////////////////////////////////////// + + + template atomicLoad( msync ms = msync.seq, T ) + { + T atomicLoad( ref T val ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof == byte.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 1 Byte Load + //////////////////////////////////////////////////////////////// + + + static if( needsLoadBarrier!(ms) ) + { + asm + { + mov DL, 42; + mov AL, 42; + mov ECX, val; + lock; + cmpxchg [ECX], DL; + } + } + else + { + synchronized + { + return val; + } + } + } + else static if( T.sizeof == short.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 2 Byte Load + //////////////////////////////////////////////////////////////// + + static if( needsLoadBarrier!(ms) ) + { + asm + { + mov DX, 42; + mov AX, 42; + mov ECX, val; + lock; + cmpxchg [ECX], DX; + } + } + else + { + synchronized + { + return val; + } + } + } + else static if( T.sizeof == int.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 4 Byte Load + //////////////////////////////////////////////////////////////// + + + static if( needsLoadBarrier!(ms) ) + { + asm + { + mov EDX, 42; + mov EAX, 42; + mov ECX, val; + lock; + cmpxchg [ECX], EDX; + } + } + else + { + synchronized + { + return val; + } + } + } + else static if( T.sizeof == long.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 8 Byte Load + //////////////////////////////////////////////////////////////// + + + version( Has64BitOps ) + { + //////////////////////////////////////////////////////////// + // 8 Byte Load on 64-Bit Processor + //////////////////////////////////////////////////////////// + + + static if( needsLoadBarrier!(ms) ) + { + asm + { + mov RAX, val; + lock; + mov RAX, [RAX]; + } + } + else + { + synchronized + { + return val; + } + } + } + else + { + //////////////////////////////////////////////////////////// + // 8 Byte Load on 32-Bit Processor + //////////////////////////////////////////////////////////// + + + pragma( msg, "This operation is only available on 64-bit platforms." ); + static assert( false ); + } + } + else + { + //////////////////////////////////////////////////////////////// + // Not a 1, 2, 4, or 8 Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Store + //////////////////////////////////////////////////////////////////////////// + + + template atomicStore( msync ms = msync.seq, T ) + { + void atomicStore( ref T val, T newval ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof == byte.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 1 Byte Store + //////////////////////////////////////////////////////////////// + + + static if( needsStoreBarrier!(ms) ) + { + asm + { + mov EAX, val; + mov DL, newval; + lock; + xchg [EAX], DL; + } + } + else + { + asm + { + mov EAX, val; + mov DL, newval; + mov [EAX], DL; + } + } + } + else static if( T.sizeof == short.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 2 Byte Store + //////////////////////////////////////////////////////////////// + + + static if( needsStoreBarrier!(ms) ) + { + asm + { + mov EAX, val; + mov DX, newval; + lock; + xchg [EAX], DX; + } + } + else + { + asm + { + mov EAX, val; + mov DX, newval; + mov [EAX], DX; + } + } + } + else static if( T.sizeof == int.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 4 Byte Store + //////////////////////////////////////////////////////////////// + + + static if( needsStoreBarrier!(ms) ) + { + asm + { + mov EAX, val; + mov EDX, newval; + lock; + xchg [EAX], EDX; + } + } + else + { + asm + { + mov EAX, val; + mov EDX, newval; + mov [EAX], EDX; + } + } + } + else static if( T.sizeof == long.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 8 Byte Store + //////////////////////////////////////////////////////////////// + + + version( Has64BitOps ) + { + //////////////////////////////////////////////////////////// + // 8 Byte Store on 64-Bit Processor + //////////////////////////////////////////////////////////// + + + static if( needsStoreBarrier!(ms) ) + { + asm + { + mov RAX, val; + mov RDX, newval; + lock; + xchg [RAX], RDX; + } + } + else + { + asm + { + mov RAX, val; + mov RDX, newval; + mov [RAX], RDX; + } + } + } + else + { + //////////////////////////////////////////////////////////// + // 8 Byte Store on 32-Bit Processor + //////////////////////////////////////////////////////////// + + + pragma( msg, "This operation is only available on 64-bit platforms." ); + static assert( false ); + } + } + else + { + //////////////////////////////////////////////////////////////// + // Not a 1, 2, 4, or 8 Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Store If + //////////////////////////////////////////////////////////////////////////// + + + template atomicStoreIf( msync ms = msync.seq, T ) + { + bool atomicStoreIf( ref T val, T newval, T equalTo ) + in + { + // NOTE: 32 bit x86 systems support 8 byte CAS, which only requires + // 4 byte alignment, so use size_t as the align type here. + static if( T.sizeof > size_t.sizeof ) + assert( atomicValueIsProperlyAligned!(size_t)( cast(size_t) &val ) ); + else + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof == byte.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 1 Byte StoreIf + //////////////////////////////////////////////////////////////// + + + asm + { + mov DL, newval; + mov AL, equalTo; + mov ECX, val; + lock; // lock always needed to make this op atomic + cmpxchg [ECX], DL; + setz AL; + } + } + else static if( T.sizeof == short.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 2 Byte StoreIf + //////////////////////////////////////////////////////////////// + + + asm + { + mov DX, newval; + mov AX, equalTo; + mov ECX, val; + lock; // lock always needed to make this op atomic + cmpxchg [ECX], DX; + setz AL; + } + } + else static if( T.sizeof == int.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 4 Byte StoreIf + //////////////////////////////////////////////////////////////// + + + asm + { + mov EDX, newval; + mov EAX, equalTo; + mov ECX, val; + lock; // lock always needed to make this op atomic + cmpxchg [ECX], EDX; + setz AL; + } + } + else static if( T.sizeof == long.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 8 Byte StoreIf + //////////////////////////////////////////////////////////////// + + + version( Has64BitOps ) + { + //////////////////////////////////////////////////////////// + // 8 Byte StoreIf on 64-Bit Processor + //////////////////////////////////////////////////////////// + + + asm + { + mov RDX, newval; + mov RAX, equalTo; + mov RCX, val; + lock; // lock always needed to make this op atomic + cmpxchg [RCX], RDX; + setz AL; + } + } + else version( Has64BitCAS ) + { + //////////////////////////////////////////////////////////// + // 8 Byte StoreIf on 32-Bit Processor + //////////////////////////////////////////////////////////// + version(darwin){ + static if(ms==msync.raw){ + return OSAtomicCompareAndSwap64(cast(long)equalTo, cast(long)newval, cast(long*)&val); + } else { + return OSAtomicCompareAndSwap64Barrier(cast(long)equalTo, cast(long)newval, cast(long*)&val); + } + } else { + asm + { + push EDI; + push EBX; + lea EDI, newval; + mov EBX, [EDI]; + mov ECX, 4[EDI]; + lea EDI, equalTo; + mov EAX, [EDI]; + mov EDX, 4[EDI]; + mov EDI, val; + lock; // lock always needed to make this op atomic + cmpxch8b [EDI]; + setz AL; + pop EBX; + pop EDI; + } + } + } + } + else + { + //////////////////////////////////////////////////////////////// + // Not a 1, 2, 4, or 8 Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Increment + //////////////////////////////////////////////////////////////////////////// + + + template atomicIncrement( msync ms = msync.seq, T ) + { + // + // NOTE: This operation is only valid for integer or pointer types + // + static assert( isValidNumericType!(T) ); + + + T atomicIncrement( ref T val ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof == byte.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 1 Byte Increment + //////////////////////////////////////////////////////////////// + + + asm + { + mov EAX, val; + lock; // lock always needed to make this op atomic + inc [EAX]; + mov AL, [EAX]; + } + } + else static if( T.sizeof == short.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 2 Byte Increment + //////////////////////////////////////////////////////////////// + + + asm + { + mov EAX, val; + lock; // lock always needed to make this op atomic + inc short ptr [EAX]; + mov AX, [EAX]; + } + } + else static if( T.sizeof == int.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 4 Byte Increment + //////////////////////////////////////////////////////////////// + + + asm + { + mov EAX, val; + lock; // lock always needed to make this op atomic + inc int ptr [EAX]; + mov EAX, [EAX]; + } + } + else static if( T.sizeof == long.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 8 Byte Increment + //////////////////////////////////////////////////////////////// + + + version( Has64BitOps ) + { + //////////////////////////////////////////////////////////// + // 8 Byte Increment on 64-Bit Processor + //////////////////////////////////////////////////////////// + + + asm + { + mov RAX, val; + lock; // lock always needed to make this op atomic + inc qword ptr [RAX]; + mov RAX, [RAX]; + } + } + else + { + //////////////////////////////////////////////////////////// + // 8 Byte Increment on 32-Bit Processor + //////////////////////////////////////////////////////////// + + + pragma( msg, "This operation is only available on 64-bit platforms." ); + static assert( false ); + } + } + else + { + //////////////////////////////////////////////////////////////// + // Not a 1, 2, 4, or 8 Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Decrement + //////////////////////////////////////////////////////////////////////////// + + + template atomicDecrement( msync ms = msync.seq, T ) + { + // + // NOTE: This operation is only valid for integer or pointer types + // + static assert( isValidNumericType!(T) ); + + + T atomicDecrement( ref T val ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof == byte.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 1 Byte Decrement + //////////////////////////////////////////////////////////////// + + + asm + { + mov EAX, val; + lock; // lock always needed to make this op atomic + dec [EAX]; + mov AL, [EAX]; + } + } + else static if( T.sizeof == short.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 2 Byte Decrement + //////////////////////////////////////////////////////////////// + + + asm + { + mov EAX, val; + lock; // lock always needed to make this op atomic + dec short ptr [EAX]; + mov AX, [EAX]; + } + } + else static if( T.sizeof == int.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 4 Byte Decrement + //////////////////////////////////////////////////////////////// + + + asm + { + mov EAX, val; + lock; // lock always needed to make this op atomic + dec int ptr [EAX]; + mov EAX, [EAX]; + } + } + else static if( T.sizeof == long.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 8 Byte Decrement + //////////////////////////////////////////////////////////////// + + + version( Has64BitOps ) + { + //////////////////////////////////////////////////////////// + // 8 Byte Decrement on 64-Bit Processor + //////////////////////////////////////////////////////////// + + + asm + { + mov RAX, val; + lock; // lock always needed to make this op atomic + dec qword ptr [RAX]; + mov RAX, [RAX]; + } + } + else + { + //////////////////////////////////////////////////////////// + // 8 Byte Decrement on 32-Bit Processor + //////////////////////////////////////////////////////////// + + + pragma( msg, "This operation is only available on 64-bit platforms." ); + static assert( false ); + } + } + else + { + //////////////////////////////////////////////////////////////// + // Not a 1, 2, 4, or 8 Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } +} +else +{ + version( BuildInfo ) + { + pragma( msg, "tango.core.Atomic: using synchronized ops" ); + } + + private + { + //////////////////////////////////////////////////////////////////////// + // Default Value Requirements + //////////////////////////////////////////////////////////////////////// + + + template atomicValueIsProperlyAligned( T ) + { + bool atomicValueIsProperlyAligned( size_t addr ) + { + return addr % T.sizeof == 0; + } + } + + + //////////////////////////////////////////////////////////////////////// + // Default Synchronization Requirements + //////////////////////////////////////////////////////////////////////// + + + template needsLoadBarrier( msync ms ) + { + const bool needsLoadBarrier = ms != msync.raw; + } + + + template needsStoreBarrier( msync ms ) + { + const bool needsStoreBarrier = ms != msync.raw; + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Load + //////////////////////////////////////////////////////////////////////////// + + + template atomicLoad( msync ms = msync.seq, T ) + { + T atomicLoad( ref T val ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof <= (void*).sizeof ) + { + //////////////////////////////////////////////////////////////// + // <= (void*).sizeof Byte Load + //////////////////////////////////////////////////////////////// + + + static if( needsLoadBarrier!(ms) ) + { + synchronized + { + return val; + } + } + else + { + synchronized + { + return val; + } + } + } + else + { + //////////////////////////////////////////////////////////////// + // > (void*).sizeof Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Store + //////////////////////////////////////////////////////////////////////////// + + + template atomicStore( msync ms = msync.seq, T ) + { + void atomicStore( ref T val, T newval ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof <= (void*).sizeof ) + { + //////////////////////////////////////////////////////////////// + // <= (void*).sizeof Byte Store + //////////////////////////////////////////////////////////////// + + + static if( needsStoreBarrier!(ms) ) + { + synchronized + { + val = newval; + } + } + else + { + synchronized + { + val = newval; + } + } + } + else + { + //////////////////////////////////////////////////////////////// + // > (void*).sizeof Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Store If + //////////////////////////////////////////////////////////////////////////// + + + template atomicStoreIf( msync ms = msync.seq, T ) + { + bool atomicStoreIf( ref T val, T newval, T equalTo ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof <= (void*).sizeof ) + { + //////////////////////////////////////////////////////////////// + // <= (void*).sizeof Byte StoreIf + //////////////////////////////////////////////////////////////// + + + synchronized + { + if( val == equalTo ) + { + val = newval; + return true; + } + return false; + } + } + else + { + //////////////////////////////////////////////////////////////// + // > (void*).sizeof Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } + + + ///////////////////////////////////////////////////////////////////////////// + // Atomic Increment + //////////////////////////////////////////////////////////////////////////// + + + template atomicIncrement( msync ms = msync.seq, T ) + { + // + // NOTE: This operation is only valid for integer or pointer types + // + static assert( isValidNumericType!(T) ); + + + T atomicIncrement( ref T val ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof <= (void*).sizeof ) + { + //////////////////////////////////////////////////////////////// + // <= (void*).sizeof Byte Increment + //////////////////////////////////////////////////////////////// + + + synchronized + { + return ++val; + } + } + else + { + //////////////////////////////////////////////////////////////// + // > (void*).sizeof Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Decrement + //////////////////////////////////////////////////////////////////////////// + + + template atomicDecrement( msync ms = msync.seq, T ) + { + // + // NOTE: This operation is only valid for integer or pointer types + // + static assert( isValidNumericType!(T) ); + + + T atomicDecrement( ref T val ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof <= (void*).sizeof ) + { + //////////////////////////////////////////////////////////////// + // <= (void*).sizeof Byte Decrement + //////////////////////////////////////////////////////////////// + + + synchronized + { + return --val; + } + } + else + { + //////////////////////////////////////////////////////////////// + // > (void*).sizeof Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } +} + + +//////////////////////////////////////////////////////////////////////////////// +// Atomic +//////////////////////////////////////////////////////////////////////////////// + + +/** + * This struct represents a value which will be subject to competing access. + * All accesses to this value will be synchronized with main memory, and + * various memory barriers may be employed for instruction ordering. Any + * primitive type of size equal to or smaller than the memory bus size is + * allowed, so 32-bit machines may use values with size <= int.sizeof and + * 64-bit machines may use values with size <= long.sizeof. The one exception + * to this rule is that architectures that support DCAS will allow double-wide + * storeIf operations. The 32-bit x86 architecture, for example, supports + * 64-bit storeIf operations. + */ +struct Atomic( T ) +{ + //////////////////////////////////////////////////////////////////////////// + // Atomic Load + //////////////////////////////////////////////////////////////////////////// + + + template load( msync ms = msync.seq ) + { + static assert( ms == msync.raw || ms == msync.hlb || + ms == msync.acq || ms == msync.seq, + "ms must be one of: msync.raw, msync.hlb, msync.acq, msync.seq" ); + + /** + * Refreshes the contents of this value from main memory. This + * operation is both lock-free and atomic. + * + * Returns: + * The loaded value. + */ + T load() + { + return atomicLoad!(ms,T)( m_val ); + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Store + //////////////////////////////////////////////////////////////////////////// + + + template store( msync ms = msync.seq ) + { + static assert( ms == msync.raw || ms == msync.ssb || + ms == msync.acq || ms == msync.rel || + ms == msync.seq, + "ms must be one of: msync.raw, msync.ssb, msync.acq, msync.rel, msync.seq" ); + + /** + * Stores 'newval' to the memory referenced by this value. This + * operation is both lock-free and atomic. + * + * Params: + * newval = The value to store. + */ + void store( T newval ) + { + atomicStore!(ms,T)( m_val, newval ); + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic StoreIf + //////////////////////////////////////////////////////////////////////////// + + + template storeIf( msync ms = msync.seq ) + { + static assert( ms == msync.raw || ms == msync.ssb || + ms == msync.acq || ms == msync.rel || + ms == msync.seq, + "ms must be one of: msync.raw, msync.ssb, msync.acq, msync.rel, msync.seq" ); + + /** + * Stores 'newval' to the memory referenced by this value if val is + * equal to 'equalTo'. This operation is both lock-free and atomic. + * + * Params: + * newval = The value to store. + * equalTo = The comparison value. + * + * Returns: + * true if the store occurred, false if not. + */ + bool storeIf( T newval, T equalTo ) + { + return atomicStoreIf!(ms,T)( m_val, newval, equalTo ); + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Numeric Functions + //////////////////////////////////////////////////////////////////////////// + + + /** + * The following additional functions are available for integer types. + */ + static if( isValidNumericType!(T) ) + { + //////////////////////////////////////////////////////////////////////// + // Atomic Increment + //////////////////////////////////////////////////////////////////////// + + + template increment( msync ms = msync.seq ) + { + static assert( ms == msync.raw || ms == msync.ssb || + ms == msync.acq || ms == msync.rel || + ms == msync.seq, + "ms must be one of: msync.raw, msync.ssb, msync.acq, msync.rel, msync.seq" ); + + /** + * This operation is only legal for built-in value and pointer + * types, and is equivalent to an atomic "val = val + 1" operation. + * This function exists to facilitate use of the optimized + * increment instructions provided by some architecures. If no + * such instruction exists on the target platform then the + * behavior will perform the operation using more traditional + * means. This operation is both lock-free and atomic. + * + * Returns: + * The result of an atomicLoad of val immediately following the + * increment operation. This value is not required to be equal to + * the newly stored value. Thus, competing writes are allowed to + * occur between the increment and successive load operation. + */ + T increment() + { + return atomicIncrement!(ms,T)( m_val ); + } + } + + + //////////////////////////////////////////////////////////////////////// + // Atomic Decrement + //////////////////////////////////////////////////////////////////////// + + + template decrement( msync ms = msync.seq ) + { + static assert( ms == msync.raw || ms == msync.ssb || + ms == msync.acq || ms == msync.rel || + ms == msync.seq, + "ms must be one of: msync.raw, msync.ssb, msync.acq, msync.rel, msync.seq" ); + + /** + * This operation is only legal for built-in value and pointer + * types, and is equivalent to an atomic "val = val - 1" operation. + * This function exists to facilitate use of the optimized + * decrement instructions provided by some architecures. If no + * such instruction exists on the target platform then the behavior + * will perform the operation using more traditional means. This + * operation is both lock-free and atomic. + * + * Returns: + * The result of an atomicLoad of val immediately following the + * increment operation. This value is not required to be equal to + * the newly stored value. Thus, competing writes are allowed to + * occur between the increment and successive load operation. + */ + T decrement() + { + return atomicDecrement!(ms,T)( m_val ); + } + } + } + +private: + T m_val; +} + + +//////////////////////////////////////////////////////////////////////////////// +// Support Code for Unit Tests +//////////////////////////////////////////////////////////////////////////////// + + +private +{ + version( D_Ddoc ) {} else + { + template testLoad( msync ms, T ) + { + void testLoad( T val = T.init + 1 ) + { + T base; + Atomic!(T) atom; + + assert( atom.load!(ms)() == base ); + base = val; + atom.m_val = val; + assert( atom.load!(ms)() == base ); + } + } + + + template testStore( msync ms, T ) + { + void testStore( T val = T.init + 1 ) + { + T base; + Atomic!(T) atom; + + assert( atom.m_val == base ); + base = val; + atom.store!(ms)( base ); + assert( atom.m_val == base ); + } + } + + + template testStoreIf( msync ms, T ) + { + void testStoreIf( T val = T.init + 1 ) + { + T base; + Atomic!(T) atom; + + assert( atom.m_val == base ); + base = val; + atom.storeIf!(ms)( base, val ); + assert( atom.m_val != base ); + atom.storeIf!(ms)( base, T.init ); + assert( atom.m_val == base ); + } + } + + + template testIncrement( msync ms, T ) + { + void testIncrement( T val = T.init + 1 ) + { + T base = val; + T incr = val; + Atomic!(T) atom; + + atom.m_val = val; + assert( atom.m_val == base && incr == base ); + base = cast(T)( base + 1 ); + incr = atom.increment!(ms)(); + assert( atom.m_val == base && incr == base ); + } + } + + + template testDecrement( msync ms, T ) + { + void testDecrement( T val = T.init + 1 ) + { + T base = val; + T decr = val; + Atomic!(T) atom; + + atom.m_val = val; + assert( atom.m_val == base && decr == base ); + base = cast(T)( base - 1 ); + decr = atom.decrement!(ms)(); + assert( atom.m_val == base && decr == base ); + } + } + + + template testType( T ) + { + void testType( T val = T.init +1 ) + { + testLoad!(msync.raw, T)( val ); + testLoad!(msync.hlb, T)( val ); + testLoad!(msync.acq, T)( val ); + testLoad!(msync.seq, T)( val ); + + testStore!(msync.raw, T)( val ); + testStore!(msync.ssb, T)( val ); + testStore!(msync.acq, T)( val ); + testStore!(msync.rel, T)( val ); + testStore!(msync.seq, T)( val ); + + testStoreIf!(msync.raw, T)( val ); + testStoreIf!(msync.ssb, T)( val ); + testStoreIf!(msync.acq, T)( val ); + testStoreIf!(msync.rel, T)( val ); + testStoreIf!(msync.seq, T)( val ); + + static if( isValidNumericType!(T) ) + { + testIncrement!(msync.raw, T)( val ); + testIncrement!(msync.ssb, T)( val ); + testIncrement!(msync.acq, T)( val ); + testIncrement!(msync.rel, T)( val ); + testIncrement!(msync.seq, T)( val ); + + testDecrement!(msync.raw, T)( val ); + testDecrement!(msync.ssb, T)( val ); + testDecrement!(msync.acq, T)( val ); + testDecrement!(msync.rel, T)( val ); + testDecrement!(msync.seq, T)( val ); + } + } + } + } +} + + +//////////////////////////////////////////////////////////////////////////////// +// Unit Tests +//////////////////////////////////////////////////////////////////////////////// + + +debug( UnitTest ) +{ + unittest + { + testType!(bool)(); + + testType!(byte)(); + testType!(ubyte)(); + + testType!(short)(); + testType!(ushort)(); + + testType!(int)(); + testType!(uint)(); + + int x; + testType!(void*)( &x ); + + version( Has64BitOps ) + { + testType!(long)(); + testType!(ulong)(); + } + else version( Has64BitCAS ) + { + testStoreIf!(msync.raw, long)(); + testStoreIf!(msync.ssb, long)(); + testStoreIf!(msync.acq, long)(); + testStoreIf!(msync.rel, long)(); + testStoreIf!(msync.seq, long)(); + + testStoreIf!(msync.raw, ulong)(); + testStoreIf!(msync.ssb, ulong)(); + testStoreIf!(msync.acq, ulong)(); + testStoreIf!(msync.rel, ulong)(); + testStoreIf!(msync.seq, ulong)(); + } + } +} diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qtd/CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qtd/CMakeLists.txt Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,3 @@ +set(QT_QTD_SRCS_D +Str.d +) diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qtd/MOC.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qtd/MOC.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,561 @@ +module qt.qtd.MOC; + +import qt.qtd.ctfe.Format; + +import std.typetuple; + +import qt.QGlobal; +import qt.Signal; +import qt.qtd.MetaMarshall; +import qt.qtd.Meta; + +public import qt.core.QString; + +public import std.traits; +/** + Utils. + */ + +bool is_digit_char(const char s) +{ + return (s >= '0' && s <= '9'); +} + +bool is_octal_char(const char s) +{ + return (s >= '0' && s <= '7'); +} + +bool is_hex_char(const char s) +{ + return ((s >= 'a' && s <= 'f') + || (s >= 'A' && s <= 'F') + || (s >= '0' && s <= '9') + ); +} + +int lastIndexOf(T)(T[] haystack, T[] needle, int from = -1) +{ + auto l = haystack.length; + auto ol = needle.length; + int delta = l - ol; + if (from < 0) + from = delta; + if (from < 0 || from > l) + return -1; + if (from > delta) + from = delta; + + while(from >= 0) + { + if (haystack[from..from+ol] == needle) + return from; + from--; + } + return -1; +} + + +T[] newArray(T)(size_t len, T[] from = []) +{ + if (len == from.length) + return from; + + if (!from.length) + from = [T.init]; + + if (from.length < len) + return newArray!T(len, from ~ from); + + return from[0..len]; +} + +string replicate(int n, char value) +{ + char[] ret = "".dup; + if (n > 0) + { +// ret = newArray!char(n); + for(int i = 0; i < n; i++) + ret ~= value; + } + return cast(string)ret; +} + +/** + CTFE MOC port. + */ + +enum MethodFlags { + AccessPrivate = 0x00, + AccessProtected = 0x01, + AccessPublic = 0x02, + MethodMethod = 0x00, + MethodSignal = 0x04, + MethodSlot = 0x08, + MethodConstructor = 0x0c, + MethodCompatibility = 0x10, + MethodCloned = 0x20, + MethodScriptable = 0x40 +} + +enum Access { Private, Protected, Public } + +struct FunctionDef +{ +/* FunctionDef(): returnTypeIsVolatile(false), access(Private), isConst(false), isVirtual(false), + inlineCode(false), wasCloned(false), isCompat(false), isInvokable(false), + isScriptable(false), isSlot(false), isSignal(false), + isConstructor(false), isDestructor(false), isAbstract(false) {} + */ +// Type type; +// string normalizedType; +// string tag; +// string name; + string sig; + string arguments; + Access access; +/* bool returnTypeIsVolatile; + + QList arguments; + + enum Access { Private, Protected, Public }; + bool isConst; + bool isVirtual; + bool inlineCode; + bool wasCloned; + + QByteArray inPrivateClass; + bool isCompat; + bool isInvokable; + bool isScriptable; + bool isSlot; + bool isSignal; + bool isConstructor; + bool isDestructor; + bool isAbstract; + */ +} + +FunctionDef newSlot(string sig, string args) +{ + return FunctionDef(sig, args, Access.Public); +} + +FunctionDef newSignal(string sig, string args) +{ + return FunctionDef(sig, args, Access.Protected); +} + +struct Generator +{ + string output; + string[] strings; +// QByteArray purestSuperClass; +// QList metaTypes; +} + +int lengthOfEscapeSequence(string s, uint i) +{ + if (s[i] != '\\' || i >= s.length - 1) + return 1; + const int startPos = i; + ++i; + auto ch = s[i]; + if (ch == 'x') { + ++i; + while (i < s.length && is_hex_char(s[i])) + ++i; + } else if (is_octal_char(ch)) { + while (i < startPos + 4 + && i < s.length + && is_octal_char(s[i])) { + ++i; + } + } else { // single character escape sequence + i = qMin(i + 1, s.length); + } + return i - startPos; +} + +int strreg(ref Generator gen, string s) +{ + int idx = 0; + foreach (str; gen.strings) { + if (str == s) + return idx; + idx += str.length + 1; + foreach (i, c; str) { + if (c == '\\') { + int cnt = lengthOfEscapeSequence(str, i) - 1; + idx -= cnt; + i += cnt; + } + } + } + gen.strings ~= s; + return idx; +} + +void generateFunctions(ref Generator gen, FunctionDef[] list, string functype, byte type) +{ + if (!list.length) + return; + gen.output ~= format_ctfe("\n // ${}s: signature, parameters, type, tag, flags\n", functype); + + foreach (i, f; list) { + byte flags = type; + + if (f.access == Access.Private) + flags |= MethodFlags.AccessPrivate; + else if (f.access == Access.Public) + flags |= MethodFlags.AccessPublic; + else if (f.access == Access.Protected) + flags |= MethodFlags.AccessProtected; + + gen.output ~= format_ctfe(" ${}, ${}, ${}, ${}, 0x${:x},\n", strreg(gen, f.sig), + strreg(gen, f.arguments), strreg(gen, ""/*f.normalizedType*/), strreg(gen, ""/*f.tag*/), flags); + } +} + +string generateCode(string className, FunctionDef[] signalList, FunctionDef[] slotList) +{ + auto gen = Generator("", []); + +/* bool isQt = (cdef->classname == "Qt"); + bool isQObject = (cdef->classname == "QObject"); + bool isConstructible = !cdef->constructorList.isEmpty(); + +// +// build the data array +// + int i = 0; + + + // filter out undeclared enumerators and sets + { + QList enumList; + for (i = 0; i < cdef->enumList.count(); ++i) { + EnumDef def = cdef->enumList.at(i); + if (cdef->enumDeclarations.contains(def.name)) { + enumList += def; + } + QByteArray alias = cdef->flagAliases.value(def.name); + if (cdef->enumDeclarations.contains(alias)) { + def.name = alias; + enumList += def; + } + } + cdef->enumList = enumList; + } + + + QByteArray qualifiedClassNameIdentifier = cdef->qualified; + qualifiedClassNameIdentifier.replace(':', '_'); +*/ + bool isConstructible = false; + + FunctionDef[] propertyList, enumList, constructorList; + int index = 12; + gen.output ~= format_ctfe("static const uint[] qt_meta_data_${} = [\n", className); + gen.output ~= format_ctfe("\n // content:\n"); + gen.output ~= format_ctfe(" ${}, // revision\n", 2); + gen.output ~= format_ctfe(" ${}, // classname\n", strreg(gen, className)); + gen.output ~= format_ctfe(" ${}, ${}, // classinfo\n", 0, 0); +// index += cdef->classInfoList.count() * 2; + + int methodCount = signalList.length + slotList.length;// + cdef->methodList.count(); + gen.output ~= format_ctfe(" ${}, ${}, // methods\n", methodCount, methodCount ? index : 0); + index += methodCount * 5; + gen.output ~= format_ctfe(" ${}, ${}, // properties\n", propertyList.length, propertyList.length ? index : 0); + index += propertyList.length * 3; +// if(cdef->notifyableProperties) +// index += cdef->propertyList.count(); + gen.output ~= format_ctfe(" ${}, ${}, // enums/sets\n", enumList.length, enumList.length ? index : 0); + +// int enumsIndex = index; +// for (i = 0; i < cdef->enumList.count(); ++i) +// index += 4 + (cdef->enumList.at(i).values.count() * 2); + gen.output ~= format_ctfe(" ${}, ${}, // constructors\n", isConstructible ? constructorList.length : 0, + isConstructible ? index : 0); + +// +// Build classinfo array +// +// generateClassInfos(); + +// +// Build signals array first, otherwise the signal indices would be wrong +// + generateFunctions(gen, signalList, "signal", MethodFlags.MethodSignal); + +// +// Build slots array +// + generateFunctions(gen, slotList, "slot", MethodFlags.MethodSlot); + +// +// Build method array +// +// generateFunctions(cdef->methodList, "method", MethodMethod); + + +// +// Build property array +// +// generateProperties(); + +// +// Build enums array +// +// generateEnums(enumsIndex); + +// +// Build constructors array +// +// if (isConstructible) +// generateFunctions(cdef->constructorList, "constructor", MethodConstructor); + +// +// Terminate data array +// + gen.output ~= format_ctfe("\n 0 // eod\n];\n\n"); + +// +// Build stringdata array +// + gen.output ~= format_ctfe("static const string qt_meta_stringdata_${} = \n", className); + gen.output ~= format_ctfe(" \""); + int col = 0; + int len = 0; + foreach (i, s; gen.strings) { + len = s.length; + if (col && col + len >= 72) { + gen.output ~= format_ctfe("\"\n \""); + col = 0; + } else if (len && s[0] >= '0' && s[0] <= '9') { + gen.output ~= format_ctfe("\"\""); + len += 2; + } + int idx = 0; + while (idx < s.length) { + if (idx > 0) { + col = 0; + gen.output ~= format_ctfe("\"\n \""); + } + int spanLen = qMin(cast(uint)70, s.length - idx); + // don't cut escape sequences at the end of a line + int backSlashPos = s.lastIndexOf("\\", idx + spanLen - 1); + if (backSlashPos >= idx) { + int escapeLen = lengthOfEscapeSequence(s, backSlashPos); + spanLen = qBound(spanLen, backSlashPos + escapeLen - idx, cast(int)(s.length - idx)); + } + gen.output ~= s[idx..idx+spanLen]; + idx += spanLen; + col += spanLen; + } + + gen.output ~= "\\0"; + col += len + 2; + } + gen.output ~= "\";\n\n"; + + return gen.output; +} + +string metaCallArgs(Args...)() +{ + string res; + foreach(i, _; Args) { + if (i > 0) + res ~= ","; + res ~= metaCallArgument!(Args[i])("_a[" ~ __toString(i+1) ~ "]"); + } + return res; +} + +string qtDeclArgs(Args...)() +{ + string ret; + foreach(i, _; Args) + { + if(i > 0) + ret ~= ","; + ret ~= qtDeclArg!(Args[i]); + } + return ret; +} + +string generate_qt_metacall(alias Signals, alias Slots)() +{ + string res = " +protected int qt_metacall(QMetaObject.Call _c, int _id, void **_a) + { + _id = super.qt_metacall(_c, _id, _a); + if (_id < 0) + return _id;\n"; + + alias TypeTuple!(Signals.at, Slots.at) Methods; + enum methodCount = Methods.length; + if(methodCount) + { + res ~= " + if (_c == QMetaObject.Call.InvokeMetaMethod) { + switch (_id) {"; + foreach(i, _; Repeat!(void, methodCount)) { + res ~= " + case " ~ __toString(i) ~ ": " ~ MetaEntryName!(Methods[i].at) ~ "(" ~ metaCallArgs!(MetaEntryArgs!(Methods[i].at))() ~ "); break;"; + } + res ~= "\n default: ;\n }\n"; + res ~= " _id -= " ~ __toString(methodCount) ~ ";"; + res ~= "\n }"; + } + + res ~= "\n return _id; + }"; + return res; +} + +string dDeclArgs(Args...)() +{ + string ret; + foreach(i, _; Args) + { + if (i > 0) + ret ~= ", "; + ret ~= fullDName!(Args[i]); + } + return ret; +} +string genMetaMethodsConstr(alias Funcs)(string className) +{ + string res; + enum funcsCount = Funcs.at.length; + foreach(i, bogus; Repeat!(void, funcsCount)) + { + res ~= " index++;\n" ~ + " _staticMetaObject.addMethod(new " ~ className ~ "(signature!(" ~ dDeclArgs!(MetaEntryArgs!(Funcs.at[i].at))()~ ")(\"" ~ MetaEntryName!(Funcs.at[i].at) ~ "\"), index));\n\n"; + } + return res; +} +string generateMetaObjectConstruction(alias Signals, alias Slots)() +{ + string res; + res ~= "\n + private static void _populateMetaInfo() { + alias BaseClassesTuple!(typeof(this))[0] BaseClass; + int index = BaseClass.staticMetaObject().methodCount() - 1;\n\n"; + + res ~= genMetaMethodsConstr!(Signals)("QMetaSignal"); + res ~= genMetaMethodsConstr!(Slots)("QMetaSlot"); + + res ~= " + }\n"; + return res; +} + +string generateQMetaObject(string className) +{ + string res; + res ~= " + public QMetaObject metaObject() { return staticMetaObject(); } + private static __gshared QMetaObject _staticMetaObject; + private static __gshared QMetaObjectNative _nativeStaticMetaObject; + public static QMetaObject staticMetaObject() + { + if(!_staticMetaObject) + createStaticMetaObject(); + return _staticMetaObject; + } + protected static void createStaticMetaObject() { + assert(!_staticMetaObject); + alias BaseClassesTuple!(typeof(this))[0] BaseClass; + if (!BaseClass._staticMetaObject) + BaseClass.createStaticMetaObject; + auto base = BaseClass._staticMetaObject; + _nativeStaticMetaObject = QMetaObjectNative(base.nativeId, qt_meta_stringdata_" ~ className ~ ".ptr, + qt_meta_data_" ~ className ~ ".ptr, null ); + + _staticMetaObject = new QMetaObject(&_nativeStaticMetaObject, base); +// _staticMetaObject.construct!(typeof(this)); + _populateMetaInfo(); + }\n\n"; + return res; +} + +size_t commaCount(int argCount) +{ + size_t ret = 0; + if(argCount > 1) + ret = argCount - 1; + return ret; +} + +FunctionDef[] genFuncDefs(alias Funcs, alias newFunc)() +{ + typeof(return) res; + enum funcsCount = Funcs.at.length; + foreach(i, bogus; Repeat!(void, funcsCount)) + { + string args = replicate(commaCount((MetaEntryArgs!(Funcs.at[i].at)).length), ','); + string funcSig = MetaEntryName!(Funcs.at[i].at) ~ "(" ~ qtDeclArgs!(MetaEntryArgs!(Funcs.at[i].at))() ~ ")"; + res ~= newFunc(funcSig, args); + } + return res; +} + +template Q_OBJECT_BIND() +{ +} + +// ------------------------------------------------------------------------------------------ + +string generateSignalEmitters(alias Funcs)() +{ + string res; + enum funcsCount = Funcs.at.length; + foreach(i, bogus; Repeat!(void, funcsCount)) + { + res ~= SignalEmitter!(MetaEntryArgs!(Funcs.at[i].at))(SignalType.NewSignal, MetaEntryName!(Funcs.at[i].at), cast(string[])[], i); + } + return res; +} + +string generateSlotAliases(alias Funcs)() +{ + string res; + enum funcsCount = Funcs.at.length; + foreach(i, bogus; Repeat!(void, funcsCount)) + { + string name = MetaEntryName!(Funcs.at[i].at); + res ~= format_ctfe(" alias slot_${} ${};\n", name, name); + } + return res; +} + + +string generateMetaInfo(T, alias Signals, alias Slots)() +{ + string res = ""; + auto signalList = genFuncDefs!(Signals, newSignal)(); + auto slotList = genFuncDefs!(Slots, newSlot)(); + res ~= generateSignalEmitters!(Signals)(); + res ~= generateSlotAliases!(Slots)(); + res ~= generateCode(T.stringof, signalList, slotList); + res ~= generate_qt_metacall!(Signals, Slots); + res ~= generateMetaObjectConstruction!(Signals, Slots); + res ~= generateQMetaObject(T.stringof); + return res; +} + +template Q_OBJECT() +{ + alias findSignals!(typeof(this)) SignalFuncs; + alias toMetaEntries!(SignalFuncs) SignalMetaEntries; + alias findSlots!(typeof(this)) SlotFuncs; + alias toMetaEntries!(SlotFuncs) SlotMetaEntries; + + mixin(generateMetaInfo!(typeof(this), SignalMetaEntries, SlotMetaEntries)()); + // debug output +// pragma(msg, generateMetaInfo!(typeof(this), SignalMetaEntries, SlotMetaEntries)()); +} diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qtd/Meta.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qtd/Meta.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,113 @@ +module qt.qtd.Meta; + +import std.traits; +import std.typetuple; +import std.string; + +// Various compile time utilities + +public bool ctfeStartsWith(T)(T[] source, T[] pattern) +{ + return source.length >= pattern.length && source[0 .. pattern.length] == pattern[]; +} + +// compile-time toString, maybe to!string is already working in CT +string __toString(long v) +{ + if (v == 0) + return "0"; + + string ret; + + bool neg; + if (v < 0) + { + neg = true; + v = -v; + } + + while (v != 0) + { + ret = cast(char)(v % 10 + '0') ~ ret; + v = cast(long)(v / 10); + } + + if (neg) + ret = "-" ~ ret; + + return ret; +} + +// returns the type of a template parameter if there is one +template templateParam(U : V!(U), alias V) +{ + alias U templateParam; +} + +// to workaround buggy foreach, returns a tuple of Ts of size I +template Repeat(T, int I) +{ + static if (!I) alias TypeTuple!() Repeat; + else alias TypeTuple!(T, Repeat!(T, I - 1)) Repeat; +} + +//returns number of required function arguments, optional arguments excluded +int requiredArgCount(alias fn)() { + alias ParameterTypeTuple!(typeof(&fn)) P; + P p; + static if (P.length == 0) + return 0; + + foreach(i, _; P) + { + static if (!__traits(compiles, fn(p[0..$-i-1]))) + { + return p.length - i; + } + } + return 0; +} + +template isDg(Dg) +{ + enum isDg = is(Dg == delegate); +} + +template isFn(Fn) +{ + enum isFn = is(typeof(*Fn.init) == function); +} + +template isFnOrDg(Dg) +{ + enum isFnOrDg = isFn!(Dg) || isDg!(Dg); +} + +uint isModule(string str) +{ + return startsWith(str, "module "); +} + +template qualifiedCppName(T) +{ + static if(!isModule(__traits(parent, T).stringof)) + enum qualifiedCppName = qualifiedCppName!(__traits(parent, T)) ~ "::" ~ T.stringof; + else + enum qualifiedCppName = T.stringof; +} + +template qualifiedDName(T) +{ + static if (!isModule(__traits(parent, T).stringof)) + enum qualifiedDName = qualifiedDName!(__traits(parent, T)) ~ "." ~ T.stringof; + else + enum qualifiedDName = T.stringof; +} + +template fullDName(T) +{ + static if (is(T == enum)) + enum fullDName = qualifiedDName!T; + else + enum fullDName = T.stringof; +} diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qtd/MetaMarshall.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qtd/MetaMarshall.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,129 @@ +module qt.qtd.MetaMarshall; + +import std.traits; + +import qt.qtd.Meta; + +template isQObjectType(T) // is a QObject type that belongs to the library +{ + enum isQObjectType = is(T.__isQObjectType); +} + +template isObjectType(T) // is a Qt Object type that belongs to the library +{ + enum isObjectType = is(T.__isObjectType); +} + +template isValueType(T) // is a Qt Value type that belongs to the library +{ + enum isValueType = is(T.__isValueType); +} + +template isQtType(T) +{ + mixin ("enum isQtType = is(T.__isQtType_" ~ T.stringof ~ ");"); +} +/* +template isQtType(T) +{ + enum isQtType = isQObjectType!(T) || isObjectType!(T) || isValueType!(T) || is(T.__isQtType); +} +*/ +template isNativeType(T) // type that doesn't require conversion i.e. is the same in C++ and D +{ + enum isNativeType = isNumeric!T || is(T == bool) || is(T == struct); +} + +template isStringType(T) // string type +{ + enum isStringType = is(T == string); +} + +template isQList(T) +{ + enum isQList = ctfeStartsWith(Unqual!(T).stringof, "QList!"); +} + +// returns full name of enum: +// for Qt enum it is in the form of QPaintDevice::PaintDeviceMetric +// for pure D enums it is Foo.Bar +template enumFullName(T) +{ + static if(!isModule(__traits(parent, T).stringof)) + { + static if(isQtType!(__traits(parent, T))) + enum enumFullName = qualifiedCppName!T; + else + enum enumFullName = qualifiedDName!T; + } + else + enum enumFullName = qualifiedDName!T; + +} + +// converts an argumnent from C++ to D in qt_metacall +string metaCallArgument(T)(string ptr) +{ + static if (isQObjectType!T || isObjectType!T) + return T.stringof ~ ".__getObject(*cast(void**)(" ~ ptr ~ "))"; + else static if (isValueType!T) + return "new " ~ T.stringof ~ "(" ~ T.stringof ~ ".__constructNativeCopy(" ~ ptr ~ "))"; + else static if (isNativeType!T) + return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")"; + else static if (isStringType!T) + return "QStringUtil.toNativeString(" ~ ptr ~ ")"; + else static if (is(T == enum)) + return "*(cast(" ~ qualifiedDName!T ~ "*)" ~ ptr ~ ")"; + else + return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")"; + //res = T.stringof; +} + +// converts a D argument type to C++ for registering in Qt meta system +string qtDeclArg(T)() +{ + static if (isQObjectType!T || isObjectType!T) + return T.stringof ~ "*"; + else static if (isValueType!T) + return T.stringof; + else static if (isStringType!T) + return "QString"; + else static if (isQList!T) + { + alias templateParam!T ElementType; + static if (is(ElementType == string)) + return "QStringList"; + else + return "QList<" ~ qtDeclArg!(templateParam!T)() ~ ">"; + } + else static if (is(T == enum)) + return enumFullName!T; + else static if (isNativeType!T) + return Unqual!T.stringof; + else + return T.stringof; +} + +// converts an argument from D to C++ in a signal emitter +string convertSignalArgument(T)(string arg) +{ + static if (isQObjectType!T || isObjectType!T) + return arg ~ " ? " "&" ~ arg ~ ".__nativeId : cast(void**) &" ~ arg; // since it is a pointer type check arg for null + else static if (isValueType!T) + return arg ~ ".__nativeId"; + else static if (isStringType!T) + return "&_qt" ~ arg; + else static if (isNativeType!T) + return "&" ~ arg; + else + return "&" ~ arg; +} + +string prepareSignalArguments(Args...)() +{ + string res; + foreach(i, _; Args) + static if (isStringType!(Args[i])) + res ~= "auto _qt_t" ~ __toString(i) ~ " = QString(_t" ~ __toString(i) ~ ");\n"; + return res; +} diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qtd/Str.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qtd/Str.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,43 @@ +/** + * + * Copyright: Copyright QtD Team, 2008-2009 + * License: 0 ) + { + bool inExp = false; + + // Look for a $ + foreach( i,c ; tmpl ) + { + if (c == '$') + { + inExp = true; + r ~= tmpl[0..i]; + tmpl = tmpl[i+1..$]; + break; + } + } + + // If we didn't find a $, it's because we hit the end of the template. + if( !inExp ) + { + r ~= tmpl; + break; + } + + // So we're in an expansion/substitution. + + debug(gb_Format_verbose) r ~= "{in exp}"; + + if( tmpl.length == 0 ) + { + r ~= "{unterminated substitution}"; + break; + } + + // c is the next character, whilst tmpl is everything left in the + // template string. + char c = tmpl[0]; + tmpl = tmpl[1..$]; + + // $$ - escaped $. + if( c == '$' ) + { + debug(gb_Format_verbose) r ~= "{escaped $}"; + r ~= '$'; + continue; + } + + // $n - shortcut for ${n}. + if( '0' <= c && c <= '9' ) + { + debug(gb_Format_verbose) r ~= "{shorthand index}"; + r ~= stringify(c-'0', 0, "", args); + continue; + } + + // $* - shortcut for ${} + if( c == '*' ) + { + debug(gb_Format_verbose) r ~= "{shorthand next}"; + r ~= stringify(argPos++, 0, "", args); + continue; + } + + // This means we got a $ followed by something unexpected. + if( c != '{' ) + { + r ~= "{malformed substitution}"; + break; + } + + if( tmpl.length == 0 ) + { + r ~= "{unterminated substitution}"; + break; + } + + debug(gb_Format_verbose) + { + r ~= "{parse complex at '"; + r ~= c; + r ~= "':\"" ~ tmpl ~ "\"}"; + } + + // NOTE: We haven't updated c and tmpl yet. + + { + // arg will contain the index of the argument the user wanted + // substituted. + size_t arg = size_t.max; + // fmt will contain any additional formatting options. + string fmt = ""; + + // If we didn't get a : or }, that means we expect an index. + if( !( tmpl[0] == ':' || tmpl[0] == '}' ) ) + { + // So parse it. + auto used = Integer.parse_ctfe!(size_t)(tmpl, true); + + if( used == 0 ) + { + debug(gb_Format_verbose) r ~= "{used zero of \""~tmpl~"\"}"; + r ~= "{invalid argument index}"; + break; + } + + arg = Integer.parse_ctfe!(size_t)(tmpl); + tmpl = tmpl[used..$]; + + if( tmpl.length == 0 ) + { + r ~= "{unterminated substitution}"; + break; + } + } + else + { + // Otherwise, the index was elided, which means we want to use + // the index of the "next" argument. + arg = argPos; + ++ argPos; + } + + c = tmpl[0]; + tmpl = tmpl[1..$]; + + debug(gb_Format_verbose) + r ~= "{index " ~ Integer.format_ctfe(arg) ~ "}"; + + // If c is :, then we've got formatting options to parse + + if( c == ':' ) + { + debug(gb_Format_verbose) r ~= "{fmt string}"; + + // Look for the closing }. + size_t len = 0; + foreach( i,d ; tmpl ) + { + if( d == '}' ) + { + len = i; + break; + } + } + if( len == 0 ) + { + r ~= "{malformed format}"; + break; + } + fmt = tmpl[0..len]; + tmpl = tmpl[len..$]; + + if( tmpl.length == 0 ) + { + r ~= "{unterminated substitution}"; + break; + } + + c = tmpl[0]; + tmpl = tmpl[1..$]; + } + + // At this point, we should have the closing }. If not, someone's + // screwed up. + if( c != '}' ) + { + debug(gb_Format_verbose) + { + r ~= "{expected closing; got '"; + r ~= c; + r ~= "':\"" ~ tmpl ~ "\"}"; + } + r ~= "{malformed substitution}"; + break; + } + + // Stringify that bugger. + r ~= stringify(arg, 0, fmt, args); + + // When we fall off the end here, we'll continue with the + // remainder of tmpl, unless it's empty in which case we're + // finished. + } + } + + return r; +} + +version( Unittest ) +{ + static assert(format_ctfe("A: $$", "foo"[]) == "A: $"); + static assert(format_ctfe("B: a $$ c", "b"[]) == "B: a $ c"); + + static assert(format_ctfe("C: ${}", "foo"[]) == "C: foo"); + static assert(format_ctfe("D: a ${} c", "b"[]) == "D: a b c"); + + static assert(format_ctfe("E: $0", "foo"[]) == "E: foo"); + static assert(format_ctfe("F: a $0 c", "b"[]) == "F: a b c"); + + static assert(format_ctfe("G: $*", "foo"[]) == "G: foo"); + static assert(format_ctfe("H: a $* c", "b"[]) == "H: a b c"); + + static assert(format_ctfe("I: ${0}", "foo"[]) == "I: foo"); + static assert(format_ctfe("J: a ${0} c", "b"[]) == "J: a b c"); + + static assert(format_ctfe("K: ${} ${} ${}", 1, -2, "c"[]) == "K: 1 -2 c"); + static assert(format_ctfe("L: $* $* $*", 1, -2, "c"[]) == "L: 1 -2 c"); + static assert(format_ctfe("M: $0 $1 $2", 1, -2, "c"[]) == "M: 1 -2 c"); + static assert(format_ctfe("N: ${0} ${1} ${2}", 1, -2, "c"[]) == "N: 1 -2 c"); + + static assert(format_ctfe("O: ${2} ${0} ${1}", 1, -2, "c"[]) == "O: c 1 -2"); + + static assert(format_ctfe("P: ${:x} ${0:x} ${0:o} ${0:b}", 42) == "P: 2a 2a 52 101010"); + + static assert(format_ctfe("Q: ${0} ${0:q} ${0:x}", "abc"[]) == "Q: abc \"abc\" 616263"); + static assert(format_ctfe("R: ${0} ${0:q}", ["a","b","c"][]) == "R: [a, b, c] [\"a\", \"b\", \"c\"]"); + + const TORTURE_TMPL = ` + struct $*Enum + { + const Name = ${0:q}; + const string[${:l}] Members = ${1:q}; + + ${2} value() + { + return ${3:xx}; + } + } + `[]; + + const TORTURE_EXPECTED = ` + struct FooEnum + { + const Name = "Foo"; + const string[3] Members = ["bar", "quxx", "zyzzy"]; + + int value() + { + return 0x42; + } + } + `[]; + + const TORTURE_ACTUAL = format_ctfe(TORTURE_TMPL, + "Foo"[], ["bar"[],"quxx","zyzzy"][], + "int"[], 0x42); + + static assert( TORTURE_EXPECTED == TORTURE_ACTUAL ); +} + +private +{ + size_t findIndexByName(Args...)(string name, Args args) + { + foreach( i ; Tuple.Sequence!(0, Args.length, 2) ) + { + static if( !is( Args[i] : string ) ) + { + static assert(false, "expected string for argument " + ~ Integer.format_ctfe(i) ~ " in " ~ Args.stringof + ~ " not " ~ Args[i].stringof); + } + if( name == args[i][] ) + return i+1; + } + return size_t.max; + } + + version( Unittest ) + { + static assert( findIndexByName("a", "a", 0, "b", 1) == 1 ); + static assert( findIndexByName("b", "a", 0, "b", 1) == 3 ); + static assert( findIndexByName("c", "a", 0, "b", 1) == size_t.max ); + } +} + +/// ditto + +string formatNamed_ctfe(Args...)(string tmpl, Args args) +{ + string r = ""; + int argPos = 0; + + while( tmpl.length > 0 ) + { + bool inExp = false; + + // Look for a $ + foreach( i,c ; tmpl ) + { + if (c == '$') + { + inExp = true; + r ~= tmpl[0..i]; + tmpl = tmpl[i+1..$]; + break; + } + } + + // If we didn't find a $, it's because we hit the end of the template. + if( !inExp ) + { + r ~= tmpl; + break; + } + + // So we're in an expansion/substitution. + + debug(gb_Format_verbose) r ~= "{in exp}"; + + if( tmpl.length == 0 ) + { + r ~= "{unterminated substitution}"; + break; + } + + // c is the next character, whilst tmpl is everything left in the + // template string. + char c = tmpl[0]; + tmpl = tmpl[1..$]; + + // $$ - escaped $. + if( c == '$' ) + { + debug(gb_Format_verbose) r ~= "{escaped $}"; + r ~= '$'; + continue; + } + + // $a... - shortcut for $a... + if( String.isIdentStartChar_ctfe(c) ) + { + debug(gb_Format_verbose) r ~= "{shorthand name}"; + size_t i = 0; + while( i < tmpl.length ) + { + if( !String.isIdentChar_ctfe(tmpl[i]) ) + break; + ++ i; + } + string name = c ~ tmpl[0..i]; + tmpl = tmpl[i..$]; + r ~= stringify(findIndexByName(name, args), 0, "", args); + continue; + } + + // This means we got a $ followed by something unexpected. + if( c != '{' ) + { + r ~= "{malformed substitution}"; + break; + } + + if( tmpl.length == 0 ) + { + r ~= "{unterminated substitution}"; + break; + } + + debug(gb_Format_verbose) + { + r ~= "{parse complex at '"; + r ~= c; + r ~= "':\"" ~ tmpl ~ "\"}"; + } + + // NOTE: We haven't updated c and tmpl yet. + + { + // arg will contain the index of the argument the user wanted + // substituted. + size_t arg = size_t.max; + // fmt will contain any additional formatting options. + string fmt = ""; + + // If we didn't get a : or }, that means we expect a name. + if( !( tmpl[0] == ':' || tmpl[0] == '}' ) ) + { + // So parse it. + size_t i = 0; + while( i < tmpl.length ) + { + if( !String.isIdentChar_ctfe(tmpl[i]) ) + break; + ++ i; + } + string name = tmpl[0..i]; + tmpl = tmpl[i..$]; + + arg = findIndexByName(name, args); + + if( tmpl.length == 0 ) + { + r ~= "{unterminated substitution}"; + break; + } + } + else + { + // Otherwise, the name was elided. Kaboom! + r ~= "{substitution missing name}"; + break; + } + + c = tmpl[0]; + tmpl = tmpl[1..$]; + + debug(gb_Format_verbose) + r ~= "{index " ~ Integer.format_ctfe(arg) ~ "}"; + + // If c is :, then we've got formatting options to parse + + if( c == ':' ) + { + debug(gb_Format_verbose) r ~= "{fmt string}"; + + // Look for the closing }. + size_t len = 0; + foreach( i,d ; tmpl ) + { + if( d == '}' ) + { + len = i; + break; + } + } + if( len == 0 ) + { + r ~= "{malformed format}"; + break; + } + fmt = tmpl[0..len]; + tmpl = tmpl[len..$]; + + debug(gb_Format_verbose) r ~= "{fmt:"~fmt~"}"; + + if( tmpl.length == 0 ) + { + r ~= "{unterminated substitution}"; + break; + } + + c = tmpl[0]; + tmpl = tmpl[1..$]; + } + + // At this point, we should have the closing }. If not, someone's + // screwed up. + if( c != '}' ) + { + debug(gb_Format_verbose) + { + r ~= "{expected closing; got '"; + r ~= c; + r ~= "':\"" ~ tmpl ~ "\"}"; + } + r ~= "{malformed substitution}"; + break; + } + + // Stringify that bugger. + r ~= stringify(arg, 0, fmt, args); + + // When we fall off the end here, we'll continue with the + // remainder of tmpl, unless it's empty in which case we're + // finished. + } + } + + return r; +} + +version( Unittest ) +{ + static assert( formatNamed_ctfe("A: $$", "a"[], 0, "b"[], 1) == "A: $" ); + static assert( formatNamed_ctfe("B: $a", "a"[], 0, "b"[], 1) == "B: 0" ); + static assert( formatNamed_ctfe("C: $b", "a"[], 0, "b"[], 1) == "C: 1" ); + + static assert( formatNamed_ctfe("D: ${a}", "a"[], 0, "b"[], 1) == "D: 0" ); + static assert( formatNamed_ctfe("E: ${b}", "a"[], 0, "b"[], 1) == "E: 1" ); + + static assert( formatNamed_ctfe("F: $foo$bar", "foo"[], 0, "bar"[], 1) == "F: 01" ); + static assert( formatNamed_ctfe("G: ${foo}${bar}", "foo"[], 0, "bar"[], 1) == "G: 01" ); + + static assert( formatNamed_ctfe("H: ${foo:x}${bar:xx}", "foo"[], 0, "bar"[], 1) == "H: 00x1" ); + + const TORTURE_NAMED_TMPL = ` + struct ${name}Enum + { + const Name = ${name:q}; + const string[${members:l}] Members = ${members:q}; + + ${retType} value() + { + return ${value:xx}; + } + } + `[]; + + const TORTURE_NAMED_EXPECTED = ` + struct FooEnum + { + const Name = "Foo"; + const string[3] Members = ["bar", "quxx", "zyzzy"]; + + int value() + { + return 0x42; + } + } + `[]; + + const TORTURE_NAMED_ACTUAL = formatNamed_ctfe(TORTURE_NAMED_TMPL, + "name"[], "Foo"[], + "members"[], ["bar"[],"quxx","zyzzy"][], + "retType"[], "int"[], + "value"[], 0x42); + + static assert( TORTURE_NAMED_EXPECTED == TORTURE_NAMED_ACTUAL ); +} + diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qtd/ctfe/Integer.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qtd/ctfe/Integer.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,169 @@ +/** + * CTFE Integer routines. + * + * Authors: Daniel Keep + * Copyright: See LICENSE. + */ +module qt.qtd.ctfe.Integer; + +/** + * Formats an integer as a string. You can optionally specify a different + * base; any value between 2 and 16 inclusive is supported. + * + * Params: + * v = value to format. + * base = base to use; defaults to 10. + * Returns: + * integer formatted as a string. + */ + +string format_ctfe(intT)(intT v, int base = 10) +{ + static if( !is( intT == ulong ) ) + { + return (v < 0) + ? "-" ~ format_ctfe(cast(ulong) -v, base) + : format_ctfe(cast(ulong) v, base); + } + else + { + assert( 2 <= base && base <= 16, + "base must be between 2 and 16; got " ~ format_ctfe(base, 10) ); + + string r = ""; + do + { + r = INT_CHARS[cast(size_t)(v % base)] ~ r; + v /= base; + } + while( v > 0 ); + return r; + } +} + +/** + * Parses an integer value from a string. You can optionally specify a + * different base; any value between 2 and 16 inclusive is supported. + * + * Note that this does not fail if it cannot consume the entire string; + * use returnUsed to determine the number of characters consumed. + * + * Params: + * str = string to parse. + * returnUsed = defaults to false; if set to true, returns the number of + * characters consumed from the string instead of the + * parsed value. + * base = base to use; defaults to 10. + * Returns: + * either the parsed integer or the number of characters consumed, + * depending on the value of returnUsed. + */ + +intT parse_ctfe(intT)(string str, bool returnUsed = false, int base = 10) +{ + auto origStr = str; + + assert( 2 <= base && base <= 16, + "base must be between 2 and 16; got " ~ format_ctfe(base, 10) ); + + bool neg = false; + if( str.length > 0 && str[0] == '-' ) + { + neg = true; + str = str[1..$]; + } + + if( intT.min == 0 && neg ) + assert(false, "underwhile while parsing \"" ~ origStr + ~ "\" as a " ~ intT.stringof ~ ": cannot represent negative " + ~ "values"); + + intT r = 0; + size_t used = 0; + + foreach( c ; str ) + { + int cv = -1; + + if( '0' <= c && c <= '9' ) + cv = c - '0'; + + else if( 'A' <= c && c <= 'Z' ) + cv = 10 + c - 'A'; + + else if( 'a' <= c && c <= 'z' ) + cv = 10 + c - 'a'; + + if( cv >= base || cv < 0 ) + break; + + auto oldR = r; + r = r*base + cast(intT) cv; + ++ used; + + if( r < oldR ) + assert(false, "overflow while parsing \"" ~ origStr + ~ "\" as a " ~ intT.stringof); + } + + if( neg ) + { + r = -r; + ++used; + } + + if( returnUsed ) + { + assert( used < intT.max, "overflow attempting to return " + ~ "number of characters consumed in a " ~ intT.stringof ); + + return used; + } + else + return r; +} + +/** + * Like parse_ctfe, except it will raise an error if the provided string + * cannot be parsed in its entirety. + * + * Params: + * str = the string to parse. + * base = base to use; defaults to 10. + * Returns: + * the parsed integer. + */ + +intT parseAll_ctfe(intT)(string str, int base = 10) +{ + auto used = parse_ctfe!(intT)(str, true, base); + assert( used == str.length, "could not parse entire string \"" ~ str + ~ "\"" ); + return parse_ctfe!(int)(str, false, base); +} + +private +{ + const INT_CHARS = "0123456789abcdef"; +} + +version( Unittest ) +{ + static assert( format_ctfe(0) == "0", "got: " ~ format_ctfe(0) ); + static assert( format_ctfe(1) == "1" ); + static assert( format_ctfe(-1) == "-1" ); + static assert( format_ctfe(42) == "42" ); + static assert( format_ctfe(0xf00, 16) == "f00" ); + static assert( format_ctfe(0123, 8) == "123" ); + + static assert( parse_ctfe!(long)("0") == 0 ); + static assert( parse_ctfe!(long)("1") == 1 ); + static assert( parse_ctfe!(long)("-1") == -1 ); + static assert( parse_ctfe!(long)("42") == 42 ); + static assert( parse_ctfe!(long)("f00", false, 16) == 0xf00 ); + static assert( parse_ctfe!(long)("123", false, 8) == 0123 ); + static assert( parse_ctfe!(long)("123ax", true) == 3 ); + static assert( parse_ctfe!(long)("123ax", true, 16) == 4 ); + + static assert( parseAll_ctfe!(long)("123") == 123 ); +} diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qtd/ctfe/String.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qtd/ctfe/String.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,317 @@ +/** + * CTFE String routines. + * + * Authors: Daniel Keep + * Copyright: See LICENSE. + */ +module qt.qtd.ctfe.String; + +import Integer = qt.qtd.ctfe.Integer; + +private +{ + const HEX_CHARS = "0123456789abcdef"; +} + +/** + * Escapes a string into an equivalent string literal. + * + * Params: + * str = string to escape. + * aggressive = if set, the function will escape all non-printing + * characters, non-space whitespace and newlines. Defaults + * to true. + * Returns: + * Escaped string literal. + */ +string escape_ctfe(string str, bool aggressive=true) +{ + string head = ""; + + foreach( i,c ; str ) + { + if( c == '"' || c == '\\' || c == '\0' ) + { + head = "\""~str[0..i]; + str = str[i..$]; + break; + } + + if( aggressive ) + { + if( c < 0x20 || c == 0x7f ) + { + head = "\""~str[0..i]; + str = str[i..$]; + break; + } + } + } + + if( head.length == 0 ) + return "\"" ~ str ~ "\""; + + string tail = ""; + + foreach( c ; str ) + { + if( c == '"' ) + tail ~= `\"`; + + else if( c == '\\' ) + tail ~= "\\\\"; + + else if( c == '\0' ) + tail ~= `\0`; + + else if( aggressive ) + { + switch( c ) + { + case '\?': + tail ~= `\?`; + break; + + case '\a': + tail ~= `\a`; + break; + + case '\b': + tail ~= `\b`; + break; + + case '\f': + tail ~= `\f`; + break; + + case '\n': + tail ~= `\n`; + break; + + case '\r': + tail ~= `\r`; + break; + + case '\t': + tail ~= `\t`; + break; + + case '\v': + tail ~= `\v`; + break; + + default: + if( c < 0x20 || c == 0x75 ) + { + tail ~= `\x`; + tail ~= HEX_CHARS[c/0xf]; + tail ~= HEX_CHARS[c&0xf]; + } + else + tail ~= c; + } + } + else + tail ~= c; + } + + return head ~ tail ~ "\""; +} + +version( Unittest ) +{ + static assert( escape_ctfe("abc") == "\"abc\"" ); + static assert( escape_ctfe("a\"c") == "\"a\\\"c\"" ); +} + +/** + * Turns an array of bytes into a hexadecimal string. + * + * Params: + * arr = array to hexify. + * grouping = if non-zero, specifies after how many bytes to insert a + * space. + * Returns: + * String of hex bytes. + */ + +string hexify_ctfe(ubyte[] arr, int grouping = 0) +{ + string r = ""; + int bytes = grouping; + foreach( b ; arr ) + { + if( bytes == 0 && grouping > 0 ) + { + r ~= ' '; + bytes = grouping; + } + + auto bh = b/16; + auto bl = b&15; + + assert( bh < 16 ); + assert( bl < 16 ); + + r ~= HEX_CHARS[bh]; + r ~= HEX_CHARS[bl]; + + if( grouping > 0 ) + -- bytes; + } + return r; +} + +/// ditto + +string hexify_ctfe(string arr, int grouping = 0) +{ + string r = ""; + int bytes = grouping; + foreach( b ; arr ) + { + if( bytes == 0 && grouping > 0 ) + { + r ~= ' '; + bytes = grouping; + } + + auto bh = b/16; + auto bl = b&15; + + assert( bh < 16 ); + assert( bl < 16 ); + + r ~= HEX_CHARS[bh]; + r ~= HEX_CHARS[bl]; + + if( grouping > 0 ) + -- bytes; + } + return r; +} + +version( Unittest ) +{ + static const ubyte[] DATA_1 = [0x00,0x01,0x02,0x03]; + static const ubyte[] DATA_2 = [0x0f,0x10,0xef,0xf0]; + + static assert( hexify_ctfe(DATA_1) == "00010203" ); + static assert( hexify_ctfe(DATA_2) == "0f10eff0" ); + + static assert( hexify_ctfe(DATA_1, 1) == "00 01 02 03" ); + static assert( hexify_ctfe(DATA_2, 1) == "0f 10 ef f0" ); + + static assert( hexify_ctfe(DATA_1, 2) == "0001 0203" ); + static assert( hexify_ctfe(DATA_2, 2) == "0f10 eff0" ); + + static assert( hexify_ctfe(DATA_1, 4) == "00010203" ); + static assert( hexify_ctfe(DATA_2, 4) == "0f10eff0" ); +} + +/** + * Pads a string. padl adds padding to the left, padr adds it to the right. + * Params: + * str = string to pad. + * len = length to pad to. + * padding = character to use for padding. Defaults to space. + * Returns: + * padded string. + */ + +string padl_ctfe(string str, int len, char padding = ' ') +{ + while( str.length < len ) + str = padding ~ str; + return str; +} + +/// ditto + +string padr_ctfe(string str, int len, char padding = ' ') +{ + while( str.length < len ) + str ~= padding; + return str; +} + +version( Unittest ) +{ + static assert( padl_ctfe("abc", 2) == "abc" ); + static assert( padl_ctfe("abc", 3) == "abc" ); + static assert( padl_ctfe("abc", 4) == " abc" ); + static assert( padl_ctfe("abc", 4, 'x') == "xabc" ); + + static assert( padr_ctfe("abc", 2) == "abc" ); + static assert( padr_ctfe("abc", 3) == "abc" ); + static assert( padr_ctfe("abc", 4) == "abc " ); + static assert( padr_ctfe("abc", 4, 'x') == "abcx" ); +} + +/** + * Returns the tail of a string after a given splitting character. The Rev + * variant returns the tail after the last instance of the splitting + * character. + */ + +string tail_ctfe(string str, char split) +{ + foreach( i,c ; str ) + { + if( c == split ) + return str[i+1..$]; + } + return str; +} + +/// ditto + +string tailRev_ctfe(string str, char split) +{ + foreach_reverse( i,c ; str ) + { + if( c == split ) + return str[i+1..$]; + } + return str; +} + +/** + * Determines whether a character is valid in an identifier in a + * non-initial position. + * + * Does not support the full range of valid D identifier characters. + */ + +bool isIdentChar_ctfe(char c) +{ + return ('a' <= c && c <= 'z') + || ('A' <= c && c <= 'Z') + || ('0' <= c && c <= '9') + || (c == '_'); +} + +/** + * Determines whether a character is valid in an identifier in an + * initial position. + * + * Does not support the full range of valid D identifier characters. + */ + +bool isIdentStartChar_ctfe(char c) +{ + return ('a' <= c && c <= 'z') + || ('A' <= c && c <= 'Z') + || (c == '_'); +} + +/** + * Returns a line spec suitable for mixing in. This can be used with string + * mixins to ensure compile errors appear on the "correct" line in the source. + */ + +string linespec_ctfe(string file, long line) +{ + return "#line "~Integer.format_ctfe(line)~" \"" ~ file ~ "\"\n"; +} + diff -r 552647ec0f82 -r 96a75b1e5b26 d1/qtd/util/Tuple.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qtd/util/Tuple.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,64 @@ +/** + * Tuple-related stuff. + * + * Authors: Daniel Keep + * Copyright: See LICENSE. + */ +module qt.qtd.util.Tuple; + +import std.typetuple; + +/** + * Sequence can be used to generate a tuple of integer values. It can be + * used in one of three forms: + * + * ----- + * Sequence!(6) // ==> (0, 1, 2, 3, 4, 5) + * Sequence!(1,6) // ==> (1, 2, 3, 4, 5) + * Sequence!(1,6,2) // ==> (1, 3, 5) + * ----- + */ + +template Sequence(int max) +{ + static if( max <= 0 ) + alias TypeTuple!() Sequence; + else + alias TypeTuple!(Sequence!(max-1), max-1) Sequence; +} + +/// ditto + +template Sequence(int min, int max) +{ + static if( max <= min ) + alias TypeTuple!() Sequence; + else + alias TypeTuple!(Sequence!(min, max-1), max-1) Sequence; +} + +/// ditto + +template Sequence(int min, int max, int stride) +{ + static if( min >= max ) + alias TypeTuple!() Sequence; + else + alias TypeTuple!(min, Sequence!(min+stride, max, stride)) Sequence; +} + +version( Unittest ) +{ + static assert( Sequence!(3)[0] == 0 ); + static assert( Sequence!(3)[1] == 1 ); + static assert( Sequence!(3)[2] == 2 ); + static assert( Sequence!(3).length == 3 ); + + static assert( Sequence!(1, 3)[0] == 1 ); + static assert( Sequence!(1, 3)[1] == 2 ); + static assert( Sequence!(1, 3).length == 2 ); + + static assert( Sequence!(1, 5, 2)[0] == 1 ); + static assert( Sequence!(1, 5, 2)[1] == 3 ); + static assert( Sequence!(1, 5, 2).length == 2 ); +} diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/CMakeLists.txt Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,23 @@ +project (qt_d D) + +set(QT_SRCS_D +QtdObject.d +QGlobal.d + +core/QChildEvent.d +core/QCoreApplication.d +core/QEvent.d +core/QEventLoop.d +core/QObject.d +core/QTimerEvent.d +core/QTranslator.d +core/Qt.d + +qtd/Str.d +) + +#add_subdirectory(core) +#add_subdirectory(qtd) + +#add_library(qt_d STATIC ${QT_CORE_SRCS_D} ${QT_QTD_SRCS_D} ${QT_SRCS_D}) +add_library(qt_d STATIC ${QT_SRCS_D}) diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/QDefines.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/QDefines.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,4 @@ +module qt.QDefines; + +const char[] QT_VERSION_STR = "4.5.2"; +const int QT_VERSION = 263426; diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/QDefines.d.inc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/QDefines.d.inc Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,4 @@ +module qt.QDefines; + +const char[] QT_VERSION_STR = "@QTD_VERSION_STR@"; +const int QT_VERSION = @QTD_VERSION@; \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/QGlobal.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/QGlobal.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,746 @@ +module qt.QGlobal; + +public import qtd.Str; +public import qt.QDefines; + +version (Tango) +{ + import tango.io.Stdout; + void writeln(string s) + { + Stdout(s).newline; + } + package import tango.stdc.stdlib, + tango.core.Memory; +} +else +{ + import std.stdio; + package import std.c.stdlib, + core.memory; +} + +T static_cast(T, U)(U obj) +{ + return cast(T)cast(void*)obj; +} + +template QT_BEGIN_NAMESPACE() { +} + +template QT_END_NAMESPACE() { +} + +template QT_BEGIN_HEADER() { +} + +template QT_END_HEADER() { +} + +mixin QT_BEGIN_HEADER; +mixin QT_BEGIN_NAMESPACE; + +//TODO: this sucks +extern(C) void qtd_dummy() {} +// Defined in QObject.d +extern(C) void qtd_delete_d_qobject(void* dPtr); + +version(cpp_shared) +{ + extern (C) void qtd_core_initCallBacks(void* toUtf8, void* dummy); + static this() { + qtd_core_initCallBacks(&qtd_toUtf8, &qtd_dummy); + } + + extern (C) void qtd_QObjectEntity_initCallBacks(void* del_d_obj); + static this() { + qtd_QObjectEntity_initCallBacks(&qtd_delete_d_qobject); + } +} + +string tr(string arg) { + return arg; +} + +/* + can be used like #if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0)) +*/ +bool QT_VERSION_CHECK( ushort major, ushort minor, ushort patch ) +{ + return cast(bool)((major<<16)|(minor<<8)|(patch)); +} +//TODO(katrina) get this from the C++ side +const char[] QT_PACKAGEDATE_STR = "2008-09-27"; +//TODO(katrina) get this from the C++ side +const char[] QT_PACKAGE_TAG = "gc9953de622c6a0f655322e0d9f5bd6dc2803b470"; + +/* + Size-dependent types (architechture-dependent byte order) + + Make sure to update QMetaType when changing these typedefs +*/ + +alias char qint8; /* 8 bit signed */ +alias char quint8; /* 8 bit unsigned */ +alias short qint16; /* 16 bit signed */ +alias ushort quint16; /* 16 bit unsigned */ +alias int qint32; /* 32 bit signed */ +alias uint quint32; /* 32 bit unsigned */ +alias long qint64; /* 64 bit signed */ +alias ulong quint64; /* 64 bit unsigned */ + +version (X86) +{ + alias quint32 quintptr; + alias qint32 qptrdiff; +} +else version (X86_64) +{ + alias quint64 quintptr; + alias qint64 qptrdiff; +} + +const byte QT_POINTER_SIZE = 8; + +alias int QNoImplicitBoolCast; + +alias double qreal; + + +/* + Utility macros and inline functions + TODO(katrina) see if we need to do anything to make these + able to be evaluated at compile time +*/ + +T qAbs(T)(T t) { return t >= 0 ? t : -t; } + +int qRound(qreal d) +{ return d >= 0.0 ? cast(int)(d + 0.5) : cast(int)(d - cast(int)(d-1) + 0.5) + cast(int)(d-1); } + +qint64 qRound64(qreal d) +{ return d >= 0.0 ? cast(qint64)(d + 0.5) : cast(qint64)(d - cast(qint64)(d-1) + 0.5) + cast(qint64)(d-1); } + +T qMin(T)(T a,T b) { if (a < b) return a; return b; } +T qMax(T)(T a, T b) { if (a < b) return b; return a; } +T qBound(T)(T min, T val,T max) { return qMax(min, qMin(max, val)); } + +/* + Data stream functions are provided by many classes (defined in qdatastream.h) +*/ + +//class QDataStream; + +/* + System information +*/ + +class QSysInfo { +public: + enum Sizes { + WordSize = ((void *).sizeof<<3) + }; + + enum Endian { + BigEndian, + LittleEndian, + ByteOrder = BigEndian + }; + /* needed to bootstrap qmake */ + static const int ByteOrder; + + enum WinVersion { + WV_32s = 0x0001, + WV_95 = 0x0002, + WV_98 = 0x0003, + WV_Me = 0x0004, + WV_DOS_based= 0x000f, + + WV_NT = 0x0010, + WV_2000 = 0x0020, + WV_XP = 0x0030, + WV_2003 = 0x0040, + WV_VISTA = 0x0080, + WV_NT_based = 0x00f0, + + WV_CE = 0x0100, + WV_CENET = 0x0200, + WV_CE_5 = 0x0300, + WV_CE_6 = 0x0400, + WV_CE_based = 0x0f00 + }; + static const WinVersion WindowsVersion; + static WinVersion windowsVersion(); + + enum MacVersion { + MV_Unknown = 0x0000, + + /* version */ + MV_9 = 0x0001, + MV_10_0 = 0x0002, + MV_10_1 = 0x0003, + MV_10_2 = 0x0004, + MV_10_3 = 0x0005, + MV_10_4 = 0x0006, + MV_10_5 = 0x0007, + + /* codenames */ + MV_CHEETAH = MV_10_0, + MV_PUMA = MV_10_1, + MV_JAGUAR = MV_10_2, + MV_PANTHER = MV_10_3, + MV_TIGER = MV_10_4, + MV_LEOPARD = MV_10_5 + }; + static const MacVersion MacintoshVersion; +}; + + +extern(C) stringz qtd_qVersion(); +/// +string qVersion() +{ + return fromStringz(qtd_qVersion); +} + +extern(C) bool qtd_qSharedBuild(); +/// +bool qSharedBuild() +{ + return qtd_qSharedBuild; +} + +/// +int qMacVersion() { return QSysInfo.MacintoshVersion; } + +/// +void qUnused(T)(T x) { cast(void) x; } +/// +void Q_UNUSED(T)(T x) { qUnused(x); } + +/* + Debugging and error handling +*/ + +//class QString; +//char[] qPrintable(QString string) { string.toLocal8Bit().constData(); } +//TODO(katrina) These should probably actually call into the c++ functions +void qFatal(string str) +{ + throw new Exception(str); +} + +void qDebug( char[] str ) /* print debug message */ +{ writeln(str); } + +extern (C) void Qt_qWarning( char * ); + +void qWarning(char[] str) /* print warning message */ +{ writeln(str); } + +//QString qt_error_string(int errorCode = -1); +void qCritical(char[] str) /* print critical message */ +{ writeln(str); } + +/* + Forward declarations only. + + In order to use the qDebug() stream, you must #include +*/ +//class QDebug; +//class QNoDebug; +//QDebug qDebug(); +//QDebug qWarning(); +//QDebug qCritical(); + +void qt_noop() {} +//TODO(katrina) Implement these +void qt_assert(char[] assertion, char[] file, int line); + +void qt_assert_x(char[] where, char[] what, char[] file, int line); + +void qt_check_pointer(char[], int); + +enum QtMsgType { QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg, QtSystemMsg = QtCriticalMsg }; + +void qt_message_output(QtMsgType, char[] buf); +//class QtMsgHandler; +//QtMsgHandler qInstallMsgHandler(QtMsgHandler); + +// forward declaration, since qatomic.h needs qglobal.h +class QBasicAtomicPointer(T); + +// POD for Q_GLOBAL_STATIC +class QGlobalStatic(T) +{ +public: + QBasicAtomicPointer!(T) pointer; + bool destroyed; +}; + +// Created as a function-local static to delete a QGlobalStatic +class QGlobalStaticDeleter(T) +{ +public: + QGlobalStatic!(T) globalStatic; + this(QGlobalStatic!(T) _globalStatic) { + globalStatic(_globalStatic); + } + + ~this() + { + delete globalStatic.pointer; + globalStatic.pointer = 0; + globalStatic.destroyed = true; + } +}; + +class QBool +{ + bool b; + +public: + this(bool B) { b = B; } +// void *() const +// { return b ? static_cast(this) : static_cast(0); } +} + +bool qFuzzyCompare(double p1, double p2) +{ + return (qAbs(p1 - p2) <= 0.000000000001 * qMin(qAbs(p1), qAbs(p2))); +} + +bool qFuzzyCompare(float p1, float p2) +{ + return (qAbs(p1 - p2) <= 0.00001f * qMin(qAbs(p1), qAbs(p2))); +} + +/* + This function tests a double for a null value. It doesn't + check whether the actual value is 0 or close to 0, but whether + it is binary 0. +*/ +bool qIsNull(double d) +{ + union U { + double d; + quint64 u; + }; + U val; + val.d = d; + return val.u == cast(quint64)(0); +} + +/* + This function tests a float for a null value. It doesn't + check whether the actual value is 0 or close to 0, but whether + it is binary 0. +*/ +bool qIsNull(float f) +{ + union U { + float f; + quint32 u; + }; + U val; + val.f = f; + return val.u == 0u; +} + +/* + Compilers which follow outdated template instantiation rules + require a class to have a comparison operator to exist when + a QList of this type is instantiated. It's not actually + used in the list, though. Hence the dummy implementation. + Just in case other code relies on it we better trigger a warning + mandating a real implementation. +*/ + + +/* + QTypeInfo - type trait functionality + qIsDetached - data sharing functionality +*/ + +/* + The catch-all template. +*/ +/* +bool qIsDetached(T)(T) { return true; } + +class QTypeInfossss(T) +{ +public: + enum { + isPointer = false, + isComplex = true, + isStatic = true, + isLarge = ((T).sizeof>(void*).sizeof), + isDummy = false + }; +}; + +class QTypeInfo(T) +{ +public: + enum { + isPointer = true, + isComplex = false, + isStatic = false, + isLarge = false, + isDummy = false + }; +}; +*/ + +/* + Specialize a specific type with: + + Q_DECLARE_TYPEINFO(type, flags); + + where 'type' is the name of the type to specialize and 'flags' is + logically-OR'ed combination of the flags below. +*/ +enum { /* TYPEINFO flags */ + Q_COMPLEX_TYPE = 0, + Q_PRIMITIVE_TYPE = 0x1, + Q_STATIC_TYPE = 0, + Q_MOVABLE_TYPE = 0x2, + Q_DUMMY_TYPE = 0x4 +}; + +/* + Specialize a shared type with: + + Q_DECLARE_SHARED(type); + + where 'type' is the name of the type to specialize. NOTE: shared + types must declare a 'bool isDetached(void) const;' member for this + to work. +*/ +void qSwap_helper(T)(ref T value1, ref T value2, T*) +{ + T t = value1; + value1 = value2; + value2 = t; +} +bool qIsDetached(T)(ref T t) { return t.isDetached(); } +void qSwap_helper(T)(ref T value1, ref T value2, T*) +{ + const T.DataPtr t = value1.data_ptr(); + value1.data_ptr() = value2.data_ptr(); + value2.data_ptr() = t; +} + +void qSwap(T)(ref T value1, ref T value2) +{ + T t = value1; + value1 = value2; + value2 = t; +} + +/* + QTypeInfo primitive specializations + TODO(katrina) Find out what we need to do here +*/ +/* +Q_DECLARE_TYPEINFO(bool, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(char, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(signed char, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(uchar, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(short, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(ushort, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(int, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(uint, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(long, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(ulong, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(qint64, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(quint64, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(float, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(double, Q_PRIMITIVE_TYPE); +#ifndef Q_OS_DARWIN +Q_DECLARE_TYPEINFO(long double, Q_PRIMITIVE_TYPE); +#endif +*/ +/* + These functions make it possible to use standard C++ functions with + a similar name from Qt header files (especially template classes). + TODO(katrina) Implement these +*/ +void * qMalloc(size_t size); +void qFree(void * ptr); +void * qRealloc(void * ptr, size_t size); +void * qMemCopy(void * dest, void * src, size_t n); +void * qMemSet(void * dest, int c, size_t n); + +struct QFlags(Enum) +{ +private: + alias void **Zero; + int i; + +public: + alias Enum enum_type; + + public static QFlags!(Enum) opCall(Enum)(QFlags f) { + QFlags!(Enum) res; + res.i = f.i; + return res; + } + + public static QFlags opCall(Enum)(Enum f) { + QFlags!(Enum) res; + res.i = f; + return res; + } + + public static QFlags opCall(Enum)(int f) { + QFlags!(Enum) res; + res.i = cast(Enum) f; + return res; + } + +// this(Zero = 0) : i(0) {} +// this(QFlag f) : i(f) {} + +// QFlags!(Enum) opAssign(QFlags f) { i = f.i; return *this; } + QFlags!(Enum) opAssign(int f) { i = f; return *this; } + QFlags!(Enum) opAndAssign(int mask) { i &= mask; return *this; } + QFlags!(Enum) opAndAssign(uint mask) { i &= mask; return *this; } + QFlags!(Enum) opOrAssign(QFlags f) { i |= f.i; return *this; } + QFlags!(Enum) opOrAssign(Enum f) { i |= f; return *this; } + QFlags!(Enum) opXorAssign(QFlags f) { i ^= f.i; return *this; } + QFlags!(Enum) opXorAssign(Enum f) { i ^= f; return *this; } + + int toInt() { return i; } + + QFlags!(Enum) opOr(QFlags f) { QFlags g; g.i = i | f.i; return g; } + QFlags!(Enum) opOr(Enum f) { QFlags g; g.i = i | f; return g; } + QFlags!(Enum) opXor(QFlags f) { QFlags g; g.i = i ^ f.i; return g; } + QFlags!(Enum) opXor(Enum f) { QFlags g; g.i = i ^ f; return g; } + QFlags!(Enum) opAnd(int mask) { QFlags g; g.i = i & mask; return g; } + QFlags!(Enum) opAnd(uint mask) { QFlags g; g.i = i & mask; return g; } + QFlags!(Enum) opAnd(Enum f) { QFlags g; g.i = i & f; return g; } + QFlags!(Enum) opCom() { QFlags g; g.i = ~i; return g; } + +// bool operator!() { return !i; } + +// bool testFlag(Enum f) { return i & f; } +} + +/* TODO typesafety +#define Q_DECLARE_FLAGS(Flags, Enum)\ +typedef QFlags Flags; +#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags) \ +QFlags operator|(Flags::enum_type f1, Flags::enum_type f2) \ +{ return QFlags(f1) | f2; } \ +QFlags operator|(Flags::enum_type f1, QFlags f2) \ +{ return f2 | f1; } +*/ + +char[] QT_TR_NOOP(char[] x) { return x; } +char[] QT_TRANSLATE_NOOP(char[] s, char[] x) { return x; } +char[] QT_TRANSLATE_NOOP3(char[] s, char[] x, char[] comment) { return x; } + +//class QByteArray; +//QByteArray qgetenv(char[] varName); +//bool qputenv(char[] varName, QByteArray value); + +int qIntCast(double f) { return cast(int)(f); } +int qIntCast(float f) { return cast(int)(f); } + +/* + Reentrant versions of basic rand() functions for random number generation +*/ +void qsrand(uint seed); +int qrand(); + + +/* + This gives us the possibility to check which modules the user can + use. These are purely compile time checks and will generate no code. +*/ + +/* Qt modules */ + +const ushort QT_MODULE_CORE = 0x0001; +const ushort QT_MODULE_GUI = 0x0002; +const ushort QT_MODULE_NETWORK = 0x0004; +const ushort QT_MODULE_OPENGL = 0x0008; +const ushort QT_MODULE_SQL = 0x0010; +const ushort QT_MODULE_XML = 0x0020; +const ushort QT_MODULE_QT3SUPPORTLIGHT = 0x0040; +const ushort QT_MODULE_QT3SUPPORT = 0x0080; +const ushort QT_MODULE_SVG = 0x0100; +const ushort QT_MODULE_ACTIVEQT = 0x0200; +const ushort QT_MODULE_GRAPHICSVIEW = 0x0400; +const ushort QT_MODULE_SCRIPT = 0x0800; +const ushort QT_MODULE_XMLPATTERNS = 0x1000; +const ushort QT_MODULE_HELP = 0x2000; +const ushort QT_MODULE_TEST = 0x4000; +const ushort QT_MODULE_DBUS = 0x8000; + +/* Qt editions */ + +const ushort QT_EDITION_CONSOLE = (QT_MODULE_CORE + | QT_MODULE_NETWORK + | QT_MODULE_SQL + | QT_MODULE_SCRIPT + | QT_MODULE_XML + | QT_MODULE_XMLPATTERNS + | QT_MODULE_TEST + | QT_MODULE_DBUS); +const ushort QT_EDITION_DESKTOPLIGHT = (QT_MODULE_CORE + | QT_MODULE_GUI + | QT_MODULE_QT3SUPPORTLIGHT + | QT_MODULE_TEST + | QT_MODULE_DBUS); +const ushort QT_EDITION_OPENSOURCE = (QT_MODULE_CORE + | QT_MODULE_GUI + | QT_MODULE_NETWORK + | QT_MODULE_OPENGL + | QT_MODULE_SQL + | QT_MODULE_XML + | QT_MODULE_XMLPATTERNS + | QT_MODULE_SCRIPT + | QT_MODULE_QT3SUPPORTLIGHT + | QT_MODULE_QT3SUPPORT + | QT_MODULE_SVG + | QT_MODULE_GRAPHICSVIEW + | QT_MODULE_HELP + | QT_MODULE_TEST + | QT_MODULE_DBUS); +const ushort QT_EDITION_DESKTOP = (QT_EDITION_OPENSOURCE + | QT_MODULE_ACTIVEQT); +const ushort QT_EDITION_UNIVERSAL = QT_EDITION_DESKTOP; +const ushort QT_EDITION_ACADEMIC = QT_EDITION_DESKTOP; +const ushort QT_EDITION_EDUCATIONAL = QT_EDITION_DESKTOP; +const ushort QT_EDITION_EVALUATION = QT_EDITION_DESKTOP; + +mixin QT_END_NAMESPACE; + +private +struct Align +{ + ubyte a; + void* b; +} + +private +const PTR_ALIGN = Align.tupleof[1].alignof; + +private +template AlignPad(size_t base, size_t aligned) +{ + static if( aligned == 0 ) + const AlignPad = base; + else + const AlignPad = ((base+PTR_ALIGN-1)/PTR_ALIGN)*PTR_ALIGN + + aligned; +} + +template InstanceSize(T) +{ + static if( is( T == Object ) ) + const InstanceSize = 2*(void*).sizeof; + else + const InstanceSize = Max!( + AlignPad!( + InstanceSize!(Super!(T)), + InterfaceCount!(T)*(void*).sizeof), + + AlignPad!( + InstanceSizeImpl!(T, 0), + + InterfaceCount!(T)*(void*).sizeof)); +} + +private +template Super(T) +{ + static if( is( T S == super ) ) + alias First!(S) Super; + else + static assert(false, "Can't get super of "~T.mangleof); +} + +private +template First(T) +{ + alias T First; +} + +private +template First(T, Ts...) +{ + alias T First; +} + +private +template InstanceSizeImpl(T, size_t i) +{ + static if( i < T.tupleof.length ) + const InstanceSizeImpl = Max!( + T.tupleof[i].offsetof + T.tupleof[i].sizeof, + InstanceSizeImpl!(T, i+1)); + else + // This is necessary to account for classes without member + // variables. + const InstanceSizeImpl = 2*(void*).sizeof; +} + +private +template Max(size_t a, size_t b) +{ + static if( a > b ) + const Max = a; + else + const Max = b; +} + +private +template InterfaceCount(T) +{ + static if( is( T == Object ) ) + const InterfaceCount = 0u; + else static if( is( T S == super ) ) + const InterfaceCount = InterfaceCountImpl!(S); +} + +private +template InterfaceCountImpl(TBase, TInterfaces...) +{ + const InterfaceCountImpl = TInterfaces.length; +} + +/+ +scope class StackObject(C) +{ + byte[InstanceSize!(C)] data; + bool constructed; + + C opCall(A...)(A args) + { + assert(!constructed); + + auto r = new(&data)C(args); + r.__stackAllocated = true; + constructed = true; + + return r; + } + + ~this() + { + if (constructed) + { + auto obj = cast(C)&data; + delete obj; + } + } +} ++/ + +alias void DArray; + +mixin QT_END_HEADER; + diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/QObjectDefs.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/QObjectDefs.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,262 @@ +module qt.QObjectDefs; + +//import qt.core.QGlobal; +//import qt.core.Qt; +import QGlobal; + +const byte Q_MOC_OUTPUT_REVISION = 59; + +template QT_TR_FUNCTIONS_NOUTF8() +{ + static QString tr(char[] s, char[] c = null) + { return staticMetaObject.tr(s, c); } + static QString tr(char[] s, char[] c, int n) + { return staticMetaObject.tr(s, c, n); } +} + +template QT_TR_FUNCTIONS_UTF8() +{ + static QString trUtf8(char[] s, char[] c = null) + { return staticMetaObject.trUtf8(s, c); } + static QString trUtf8(char[] s, char[] c, int n) + { return staticMetaObject.trUtf8(s, c, n); } +} + +template QT_TR_FUNCTIONS() +{ + mixin QT_TR_FUNCTIONS_NOUTF8; + mixin QT_TR_FUNCTIONS_UTF8; +} + +template Q_OBJECT_CHECK() +{ + void qt_check_for_QOBJECT_macro(T)(T _q_argument) const + { int i = qYouForgotTheQ_OBJECT_Macro(this, _q_argument); i = i; } +} + +int qYouForgotTheQ_OBJECT_Macro(T)(T, T) { return 0; } + +void qYouForgotTheQ_OBJECT_Macro(T1,T2)(T1, T2) {} + +template Q_OBJECT() +{ + public mixin Q_OBJECT_CHECK; + public static const QMetaObject staticMetaObject; + public const QMetaObject *metaObject() const{} + public void *qt_metacast(const char *){} + public mixin QT_TR_FUNCTIONS; + public int qt_metacall(QMetaObject.Call, int, void **){} +} + +template Q_OBJECT_FAKE() +{ + mixin Q_OBJECT; +} + +template Q_GADGET() +{ + public static const QMetaObject staticMetaObject; +} + +char[] METHOD( char[] a ) { return "0"~a; } +char[] SLOT( char[] a ) { return "1"~a; } +char[] SIGNAL( char[] a ) { return "2"~a; } + +version(QT3_SUPPORT) { + const byte METHOD_CODE = 0; // member type codes + const byte SLOT_CODE = 1; + const byte SIGNAL_CODE = 2; +} + +const byte QMETHOD_CODE = 0; // member type codes +const byte QSLOT_CODE = 1; +const byte QSIGNAL_CODE = 2; + +QArgument!(T) Q_ARG(T)(char [] type, T data) + { return QArgument!(T)(type, data); } + +QReturnArgument!(T) Q_RETURN_ARG(T)(char [] type, T data) + { return QReturnArgument!(T)(type, data); } + +class QGenericArgument +{ +public: + this(char[] aName = null, const void *aData = null) + { _data = aData; _name = aName; } + void *data() const { return cast(void *)(_data); } + char[] name() { return _name; } + +private: + const void *_data; + char[] _name; +}; + +class QGenericReturnArgument : QGenericArgument +{ +}; + +class QArgument(T) : QGenericArgument +{ +public: + this(char[] aName, T aData) + { this(aName, cast(void *)aData); } +}; + +class QReturnArgument(T) : QGenericReturnArgument +{ +public: + this(char[] aName, T aData) + { this(aName, cast(void *)aData); } +}; + +//TODO(katrina) enable this when all the classes it uses are available +/*struct QMetaObject +{ + char[] className() const; + const QMetaObject *superClass() const; + + //TODO(katrina) enable QObject cast(QObject obj) const; + + // ### Qt 4: Merge overloads + QString tr(const char *s, const char *c) const; + QString trUtf8(const char *s, const char *c) const; + QString tr(const char *s, const char *c, int n) const; + QString trUtf8(const char *s, const char *c, int n) const; + + int methodOffset() const; + int enumeratorOffset() const; + int propertyOffset() const; + int classInfoOffset() const; + + int methodCount() const; + int enumeratorCount() const; + int propertyCount() const; + int classInfoCount() const; + + int indexOfMethod(const char *method) const; + int indexOfSignal(const char *signal) const; + int indexOfSlot(const char *slot) const; + int indexOfEnumerator(const char *name) const; + int indexOfProperty(const char *name) const; + int indexOfClassInfo(const char *name) const; + + QMetaMethod method(int index) const; + QMetaEnum enumerator(int index) const; + QMetaProperty property(int index) const; + QMetaClassInfo classInfo(int index) const; + QMetaProperty userProperty() const; + + static bool checkConnectArgs(const char *signal, const char *method); + static QByteArray normalizedSignature(const char *method); + static QByteArray normalizedType(const char *type); + + // internal index-based connect + static bool connect(const QObject *sender, int signal_index, + const QObject *receiver, int method_index, + int type = 0, int *types = 0); + // internal index-based disconnect + static bool disconnect(const QObject *sender, int signal_index, + const QObject *receiver, int method_index); + // internal slot-name based connect + static void connectSlotsByName(QObject *o); + + // internal index-based signal activation + static void activate(QObject *sender, int signal_index, void **argv); + static void activate(QObject *sender, int from_signal_index, int to_signal_index, void **argv); + static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv); + static void activate(QObject *sender, const QMetaObject *, int from_local_signal_index, int to_local_signal_index, void **argv); + // internal guarded pointers + static void addGuard(QObject **ptr); + static void removeGuard(QObject **ptr); + static void changeGuard(QObject **ptr, QObject *o); + + static bool invokeMethod(QObject *obj, const char *member, + qt.core.Qt.ConnectionType, + QGenericReturnArgument ret, + QGenericArgument val0 = QGenericArgument(0), + QGenericArgument val1 = QGenericArgument(), + QGenericArgument val2 = QGenericArgument(), + QGenericArgument val3 = QGenericArgument(), + QGenericArgument val4 = QGenericArgument(), + QGenericArgument val5 = QGenericArgument(), + QGenericArgument val6 = QGenericArgument(), + QGenericArgument val7 = QGenericArgument(), + QGenericArgument val8 = QGenericArgument(), + QGenericArgument val9 = QGenericArgument()); + + static bool invokeMethod(QObject *obj, const char *member, + QGenericReturnArgument ret, + QGenericArgument val0 = QGenericArgument(0), + QGenericArgument val1 = QGenericArgument(), + QGenericArgument val2 = QGenericArgument(), + QGenericArgument val3 = QGenericArgument(), + QGenericArgument val4 = QGenericArgument(), + QGenericArgument val5 = QGenericArgument(), + QGenericArgument val6 = QGenericArgument(), + QGenericArgument val7 = QGenericArgument(), + QGenericArgument val8 = QGenericArgument(), + QGenericArgument val9 = QGenericArgument()) + { + return invokeMethod(obj, member, qt.core.Qt.AutoConnection, ret, val0, val1, val2, val3, + val4, val5, val6, val7, val8, val9); + } + + static bool invokeMethod(QObject *obj, const char *member, + qt.core.Qt.ConnectionType type, + QGenericArgument val0 = QGenericArgument(0), + QGenericArgument val1 = QGenericArgument(), + QGenericArgument val2 = QGenericArgument(), + QGenericArgument val3 = QGenericArgument(), + QGenericArgument val4 = QGenericArgument(), + QGenericArgument val5 = QGenericArgument(), + QGenericArgument val6 = QGenericArgument(), + QGenericArgument val7 = QGenericArgument(), + QGenericArgument val8 = QGenericArgument(), + QGenericArgument val9 = QGenericArgument()) + { + return invokeMethod(obj, member, type, QGenericReturnArgument(), val0, val1, val2, + val3, val4, val5, val6, val7, val8, val9); + } + + + static bool invokeMethod(QObject *obj, const char *member, + QGenericArgument val0 = QGenericArgument(0), + QGenericArgument val1 = QGenericArgument(), + QGenericArgument val2 = QGenericArgument(), + QGenericArgument val3 = QGenericArgument(), + QGenericArgument val4 = QGenericArgument(), + QGenericArgument val5 = QGenericArgument(), + QGenericArgument val6 = QGenericArgument(), + QGenericArgument val7 = QGenericArgument(), + QGenericArgument val8 = QGenericArgument(), + QGenericArgument val9 = QGenericArgument()) + { + return invokeMethod(obj, member, qt.core.Qt.AutoConnection, QGenericReturnArgument(), val0, + val1, val2, val3, val4, val5, val6, val7, val8, val9); + } + + enum Call { + InvokeMetaMethod, + ReadProperty, + WriteProperty, + ResetProperty, + QueryPropertyDesignable, + QueryPropertyScriptable, + QueryPropertyStored, + QueryPropertyEditable, + QueryPropertyUser + }; + +version(QT3_SUPPORT) { + const char *superClassName() const; +} + + struct d_struct{ // private data + const QMetaObject *superdata; + const char *stringdata; + const uint *data; + const QMetaObject **extradata; + }; + d_struct d; +}; +*/ diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/core/CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/core/CMakeLists.txt Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,10 @@ +set(QT_CORE_SRCS_D +Qt.d +QChildEvent.d +QCoreApplication.d +QEvent.d +QEventLoop.d +QObject.d +QTimerEvent.d +QTranslator.d +) diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/core/QLine.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/core/QLine.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,413 @@ +module qt.core.QLine; + +public import qt.QGlobal; +public import qt.core.Qt; +public import qt.core.QPoint; +public import qt.core.QDataStream; + + +public struct QLine +{ + public static QLine opCall() { + QLine ln; + ln.pt1 = QPoint(); + ln.pt2 = QPoint(); + return ln; + } + + public this(QPoint pt1_, QPoint pt2_) { + pt1 = pt1_; + pt2 = pt2_; + } + + public this(int x1pos, int y1pos, int x2pos, int y2pos) { + pt1 = QPoint(x1pos, y1pos); + pt2 = QPoint(x2pos, y2pos); + } + + bool isNull() // const + { + return pt1 == pt2; + } + + int x1() // const + { + return pt1.x(); + } + + int y1() // const + { + return pt1.y(); + } + + int x2() // const + { + return pt2.x(); + } + + int y2() // const + { + return pt2.y(); + } + + QPoint p1() // const + { + return pt1; + } + + QPoint p2() // const + { + return pt2; + } + + int dx() // const + { + return pt2.x() - pt1.x(); + } + + int dy() // const + { + return pt2.y() - pt1.y(); + } + + void translate(ref QPoint point) + { + pt1 += point; + pt2 += point; + } + + void translate(int adx, int ady) + { + translate(QPoint(adx, ady)); + } + + QLine translated(ref QPoint p) // const + { + return QLine(pt1 + p, pt2 + p); + } + + QLine translated(int adx, int ady) // const + { + return translated(QPoint(adx, ady)); + } + + void p1(ref QPoint aP1) + { + pt1 = aP1; + } + + void p2(ref QPoint aP2) + { + pt2 = aP2; + } + + void setP1(ref QPoint aP1) // for convenience + { + pt1 = aP1; + } + + void setP2(ref QPoint aP2) // for convenience + { + pt2 = aP2; + } + + void setPoints(ref QPoint aP1, ref QPoint aP2) + { + pt1 = aP1; + pt2 = aP2; + } + + void setLine(int aX1, int aY1, int aX2, int aY2) + { + pt1 = QPoint(aX1, aY1); + pt2 = QPoint(aX2, aY2); + } + + bool opEquals(ref const QLine d) const + { + return pt1 == d.pt1 && pt2 == d.pt2; + } + + public final void writeTo(QDataStream arg__1) { + qtd_QLine_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final void readFrom(QDataStream arg__1) { + qtd_QLine_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); + } + + // service stuff + public alias void __isNativeValueType; + + struct QTypeInfo + { + enum bool isComplex = true; + enum bool isStatic = false; + enum bool isLarge = true; + enum bool isPointer = false; + enum bool isDummy = false; + } +private: + QPoint pt1, pt2; +} + + +public enum QLineF_IntersectType { + NoIntersection = 0, + BoundedIntersection = 1, + UnboundedIntersection = 2 +} + +public struct QLineF +{ + + alias QLineF_IntersectType IntersectType; + + alias QLineF_IntersectType.NoIntersection NoIntersection; + alias QLineF_IntersectType.BoundedIntersection BoundedIntersection; + alias QLineF_IntersectType.UnboundedIntersection UnboundedIntersection; + + public static QLineF opCall() { + QLineF ln; + ln.pt1 = QPointF(); + ln.pt2 = QPointF(); + return ln; + } + + public this(QPointF apt1, QPointF apt2) { + pt1 = apt1; + pt2 = apt2; + } + + public this(qreal x1pos, qreal y1pos, qreal x2pos, qreal y2pos) { + pt1 = QPointF(x1pos, y1pos); + pt2 = QPointF(x2pos, y2pos); + } + + public this(QLine line){ + pt1 = QPointF(line.p1()); + pt2 = QPointF(line.p2()); + } + + public final bool isNull() // const + { + return qtd_QLineF_isNull(&this); + } + + qreal x1() // const + { + return pt1.x(); + } + + qreal y1() // const + { + return pt1.y(); + } + + qreal x2() // const + { + return pt2.x(); + } + + qreal y2() // const + { + return pt2.y(); + } + + QPointF p1() // const + { + return pt1; + } + + QPointF p2() // const + { + return pt2; + } + + qreal dx() // const + { + return pt2.x() - pt1.x(); + } + + qreal dy() // const + { + return pt2.y() - pt1.y(); + } + + QLineF normalVector() // const + { + return QLineF(p1(), p1() + QPointF(dy(), -dx())); + } + + void translate(ref QPointF point) + { + pt1 += point; + pt2 += point; + } + + void translate(qreal adx, qreal ady) + { + this.translate(QPointF(adx, ady)); + } + + QLineF translated(ref QPointF p) // const + { + return QLineF(pt1 + p, pt2 + p); + } + + QLineF translated(qreal adx, qreal ady) // const + { + return translated(QPointF(adx, ady)); + } + + void setLength(qreal len) + { + if (isNull()) + return; + QLineF v = unitVector(); + pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len); + } + + void length(qreal len) + { + if (isNull()) + return; + QLineF v = unitVector(); + pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len); + } + + QPointF pointAt(qreal t) // const + { + qreal vx = pt2.x() - pt1.x(); + qreal vy = pt2.y() - pt1.y(); + return QPointF(pt1.x() + vx * t, pt1.y() + vy * t); + } + + QLine toLine() // const + { + return QLine(pt1.toPoint(), pt2.toPoint()); + } + + void setP1(ref QPointF aP1) + { + pt1 = aP1; + } + + void setP2(ref QPointF aP2) + { + pt2 = aP2; + } + + void p1(ref QPointF aP1) + { + pt1 = aP1; + } + + void p2(ref QPointF aP2) + { + pt2 = aP2; + } + + void setPoints(ref QPointF aP1, ref QPointF aP2) + { + pt1 = aP1; + pt2 = aP2; + } + + void setLine(qreal aX1, qreal aY1, qreal aX2, qreal aY2) + { + pt1 = QPointF(aX1, aY1); + pt2 = QPointF(aX2, aY2); + } + + bool opEquals(ref const QLineF d) const + { + return pt1 == d.pt1 && pt2 == d.pt2; + } + + public final double angle() { + return qtd_QLineF_angle(&this); + } + + public final double angle(ref QLineF l) { + return qtd_QLineF_angle_QLineF(&this, &l); + } + + public final double angleTo(ref QLineF l) { + return qtd_QLineF_angleTo_QLineF(&this, &l); + } + + // ### Qt 5: rename intersects() or intersection() and rename IntersectType IntersectionType + private final QLineF_IntersectType intersect(ref QLineF l, QPointF* intersectionPoint) { + return cast(QLineF_IntersectType) qtd_QLineF_intersect_QLineF_nativepointerQPointF(&this, &l, intersectionPoint); + } + + public final double length() { + return qtd_QLineF_length(&this); + } + + public final void writeTo(QDataStream arg__1) { + qtd_QLineF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final void readFrom(QDataStream arg__1) { + qtd_QLineF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final void setAngle(double angle) { + qtd_QLineF_setAngle_double(&this, angle); + } + + public final QLineF unitVector() { + return qtd_QLineF_unitVector(&this); + } + + public static QLineF fromPolar(double length, double angle) { + return qtd_QLineF_fromPolar_double_double(length, angle); + } + + // service stuff + public alias void __isNativeValueType; + + struct QTypeInfo + { + enum bool isComplex = true; + enum bool isStatic = false; + enum bool isLarge = true; + enum bool isPointer = false; + enum bool isDummy = false; + } + + private: + QPointF pt1, pt2; +} + + +// C wrappers +// QLine +private extern(C) void qtd_QLine_writeTo_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void qtd_QLine_readFrom_QDataStream(void* __this_nativeId, + void* arg__1); + +// QLineF +private extern(C) bool qtd_QLineF_isNull(void* __this_nativeId); +private extern(C) double qtd_QLineF_angle(void* __this_nativeId); +private extern(C) double qtd_QLineF_angle_QLineF(void* __this_nativeId, + void* l0); +private extern(C) double qtd_QLineF_angleTo_QLineF(void* __this_nativeId, + void* l0); +private extern(C) int qtd_QLineF_intersect_QLineF_nativepointerQPointF(void* __this_nativeId, + void* l0, + void* intersectionPoint1); +private extern(C) double qtd_QLineF_length(void* __this_nativeId); +private extern(C) void qtd_QLineF_writeTo_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void qtd_QLineF_readFrom_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void qtd_QLineF_setAngle_double(void* __this_nativeId, + double angle0); + +private extern(C) QLineF qtd_QLineF_unitVector(void* __this_nativeId); +private extern(C) QLineF qtd_QLineF_fromPolar_double_double(double length0, + double angle1); diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/core/QLineF.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/core/QLineF.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,4 @@ +module qt.core.QLineF; +/* dummy */ + +public import qt.core.QLine; \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/core/QList.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/core/QList.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,627 @@ +module qt.core.QList; + +import qt.QGlobal; +import qt.core.QTypeInfo; +import qt.core.QString; +import qtd.QtdObject; +import qtd.Atomic; +import qtd.MetaMarshall; + +import core.stdc.stdlib : qRealloc = realloc, qFree = free, qMalloc = malloc; +import core.stdc.string : memcpy, memmove; + +import std.traits; + +enum INT_MAX = int.max; + +bool isComplex(T)() + if (is(T.QTypeInfo)) +{ + return T.QTypeInfo.isComplex; +} + +bool isStatic(T)() + if (is(T.QTypeInfo)) +{ + return T.QTypeInfo.isStatic; +} + +bool isLarge(T)() + if (is(T.QTypeInfo)) +{ + return T.QTypeInfo.isLarge; +} + +template isQtReference(T) +{ + enum isQtReference = isQObjectType!T || isObjectType!T || isValueType!T || is(T == string); +} + +int qAllocMore(int alloc, int extra) +{ + if (alloc == 0 && extra == 0) + return 0; + const int page = 1 << 12; + int nalloc; + alloc += extra; + if (alloc < 1<<6) { + nalloc = (1<<3) + ((alloc >>3) << 3); + } else { + // don't do anything if the loop will overflow signed int. + if (alloc >= INT_MAX/2) + return INT_MAX; + nalloc = (alloc < page) ? 1 << 3 : page; + while (nalloc < alloc) { + if (nalloc <= 0) + return INT_MAX; + nalloc *= 2; + } + } + return nalloc - extra; +} + +void q_new_at(T)(T* ptr, const ref T t) +{ + memcpy(ptr, &t, T.sizeof); +/* static if (__traits(compiles, ptr.__postblit())) DMD bug #3539 + ptr.__postblit();*/ +} + +T* q_new(T)(const ref T t) +{ + T* ptr = cast(T*) qMalloc(T.sizeof); + q_new_at!T(ptr, t); + return ptr; +} + +void q_delete(T)(T* t) +{ + static if (__traits(compiles, t.__dtor())) + t.__dtor(); + qFree(t); +} + +private int grow(int size) +{ + // dear compiler: don't optimize me out. +// synchronized { + int x = qAllocMore(size * (void*).sizeof, QListData.DataHeaderSize) / (void*).sizeof; + return x; +// } +} + +struct QListData { +private: + struct Data { + Atomic!int ref_; + int alloc, begin, end; + uint sharable; + void*[1] array; + } + + enum { DataHeaderSize = Data.sizeof - (void*).sizeof } + + static Data shared_null; + Data *d; + + static this() + { + shared_null = Data(Atomic!int(1), 0, 0, 0, true, [null]); + } + + +// Data *detach(); // remove in 5.0 + + Data* detach2() + { + Data* x = d; + d = cast(Data*)(qMalloc(DataHeaderSize + x.alloc * (void*).sizeof)); + if (!d) + qFatal("QList: Out of memory"); + + memcpy(d, x, DataHeaderSize + x.alloc * (void*).sizeof); + d.alloc = x.alloc; + d.ref_.store(1); + d.sharable = true; + if (!d.alloc) + d.begin = d.end = 0; + + return x; + } + + void realloc(int alloc) + { +// assert(d.ref_ == 1); + Data* x = cast(Data*)(qRealloc(d, DataHeaderSize + alloc * (void*).sizeof)); + if (!x) + qFatal("QList: Out of memory"); + + d = x; + d.alloc = alloc; + if (!alloc) + d.begin = d.end = 0; + } + + void** append() + { +// #TODO Q_ASSERT(d.ref_ == 1); + if (d.end == d.alloc) { + int n = d.end - d.begin; + if (d.begin > 2 * d.alloc / 3) { + memcpy(d.array.ptr + n, d.array.ptr + d.begin, n * (void*).sizeof); + d.begin = n; + d.end = n * 2; + } else { + realloc(grow(d.alloc + 1)); + } + } + return d.array.ptr + d.end++; + } + + void **append(const ref QListData l) + { +// Q_ASSERT(d.ref_ == 1); + int e = d.end; + int n = l.d.end - l.d.begin; + if (n) { + if (e + n > d.alloc) + realloc(grow(e + l.d.end - l.d.begin)); + memcpy(d.array.ptr + d.end, l.d.array.ptr + l.d.begin, n * (void*).sizeof); + d.end += n; + } + return d.array.ptr + e; + } + + void **prepend() + { +// Q_ASSERT(d.ref_ == 1); + if (d.begin == 0) { + if (d.end >= d.alloc / 3) + realloc(grow(d.alloc + 1)); + + if (d.end < d.alloc / 3) + d.begin = d.alloc - 2 * d.end; + else + d.begin = d.alloc - d.end; + + memmove(d.array.ptr + d.begin, d.array.ptr, d.end * (void*).sizeof); + d.end += d.begin; + } + return d.array.ptr + --d.begin; + } + + void **insert(int i) + { +// Q_ASSERT(d.ref_ == 1); + if (i <= 0) + return prepend(); + if (i >= d.end - d.begin) + return append(); + + bool leftward = false; + int size = d.end - d.begin; + + if (d.begin == 0) { + if (d.end == d.alloc) { + // If the array is full, we expand it and move some items rightward + realloc(grow(d.alloc + 1)); + } else { + // If there is free space at the end of the array, we move some items rightward + } + } else { + if (d.end == d.alloc) { + // If there is free space at the beginning of the array, we move some items leftward + leftward = true; + } else { + // If there is free space at both ends, we move as few items as possible + leftward = (i < size - i); + } + } + + if (leftward) { + --d.begin; + memmove(d.array.ptr + d.begin, d.array.ptr + d.begin + 1, i * (void*).sizeof); + } else { + memmove(d.array.ptr + d.begin + i + 1, d.array.ptr + d.begin + i, + (size - i) * (void*).sizeof); + ++d.end; + } + return d.array.ptr + d.begin + i; + } + + void remove(int i) + { +// Q_ASSERT(d.ref_ == 1); + i += d.begin; + if (i - d.begin < d.end - i) { + if (int offset = i - d.begin) + memmove(d.array.ptr + d.begin + 1, d.array.ptr + d.begin, offset * (void*).sizeof); + d.begin++; + } else { + if (int offset = d.end - i - 1) + memmove(d.array.ptr + i, d.array.ptr + i + 1, offset * (void*).sizeof); + d.end--; + } + } + + void remove(int i, int n) + { +// Q_ASSERT(d.ref_ == 1); + i += d.begin; + int middle = i + n/2; + if (middle - d.begin < d.end - middle) { + memmove(d.array.ptr + d.begin + n, d.array.ptr + d.begin, + (i - d.begin) * (void*).sizeof); + d.begin += n; + } else { + memmove(d.array.ptr + i, d.array.ptr + i + n, + (d.end - i - n) * (void*).sizeof); + d.end -= n; + } + } + + void move(int from, int to) + { +// Q_ASSERT(d.ref_ == 1); + if (from == to) + return; + + from += d.begin; + to += d.begin; + void *t = d.array.ptr[from]; + + if (from < to) { + if (d.end == d.alloc || 3 * (to - from) < 2 * (d.end - d.begin)) { + memmove(d.array.ptr + from, d.array.ptr + from + 1, (to - from) * (void*).sizeof); + } else { + // optimization + if (int offset = from - d.begin) + memmove(d.array.ptr + d.begin + 1, d.array.ptr + d.begin, offset * (void*).sizeof); + if (int offset = d.end - (to + 1)) + memmove(d.array.ptr + to + 2, d.array.ptr + to + 1, offset * (void*).sizeof); + ++d.begin; + ++d.end; + ++to; + } + } else { + if (d.begin == 0 || 3 * (from - to) < 2 * (d.end - d.begin)) { + memmove(d.array.ptr + to + 1, d.array.ptr + to, (from - to) * (void*).sizeof); + } else { + // optimization + if (int offset = to - d.begin) + memmove(d.array.ptr + d.begin - 1, d.array.ptr + d.begin, offset * (void*).sizeof); + if (int offset = d.end - (from + 1)) + memmove(d.array.ptr + from, d.array.ptr + from + 1, offset * (void*).sizeof); + --d.begin; + --d.end; + --to; + } + } + d.array.ptr[to] = t; + } + + void **erase(void **xi) + { +// Q_ASSERT(d.ref_ == 1); + int i = xi - (d.array.ptr + d.begin); + remove(i); + return d.array.ptr + d.begin + i; + } + + int size() const { return d.end - d.begin; } + bool isEmpty() const { return d.end == d.begin; } + const (void*)* at(int i) const { return d.array.ptr + d.begin + i; } + const (void*)* begin() const { return d.array.ptr + d.begin; } + const (void*)* end() const { return d.array.ptr + d.end; } +} + +import std.stdio; +import std.conv; + +alias void Dummy; // DMD bug #3538 + +struct QList(T, alias Default = Dummy) +{ + static if (is(Default == Dummy)) + alias QTypeInfo!T TI; + else + alias Default TI; + + struct Node + { + void *v; + + static if (isQObjectType!T || isObjectType!T || isValueType!T || is(T == string)) // binded Qt types + { + T t() + { + static if(is(T == string)) + { + void* ptr = cast(void*)(TI.isLarge || TI.isStatic ? v : &this); + return QStringUtil.toNativeString(ptr); + } + else static if (isValueType!T) + { + void* ptr = cast(void*)(isLarge!T() || isStatic!T() ? v : &this); + return new T(ptr, QtdObjectFlags.nativeOwnership); + } + else + { + return T.__getObject( *cast(void**)(&this) ); + } + } + } + else // native types + { + ref T t() + { + static if(TI.isLarge || TI.isStatic) + return *cast(T*)(this.v); + else + return *cast(T*)(&this); + } + } + } + + union { + QListData p; + QListData.Data* d; + } + +public: + /* + void output() + { + writeln("QList atomic ", d.ref_.load()); + } + */ + + static QList!T opCall() + { + QList!T res; +// writeln("QList opCall"); + + res.d = &QListData.shared_null; + res.d.ref_.increment(); + + return res; + } + + this(this) + { +// writeln("QList postblit"); + d.ref_.increment(); + if (!d.sharable) + detach_helper(); + } + + ~this() + { +// writeln("QList ~this"); + if (d && !d.ref_.decrement()) + free(d); + } + + ref QList!T opAssign(const ref QList!T l) + { +// writeln("QList opAssign"); + if (d != l.d) { + QListData.Data* nd = cast(QListData.Data*)l.d; + nd.ref_.increment(); + if (!d.ref_.decrement()) + free(d); + d = nd; + if (!d.sharable) + detach_helper(); + } + return this; + } + + int length() const { return p.size(); } + int size() const { return length; } + + void detach() { if (d.ref_.load() != 1) detach_helper(); } + + private void detach_helper() + { + Node *n = cast(Node*)(p.begin()); + QListData.Data* x = p.detach2(); + node_copy(cast(Node*)(p.begin()), cast(Node*)(p.end()), n); + if (!x.ref_.decrement()) + free(x); + } + + void append(const T t) // fix to const ref for complex types TODO + { + detach(); + static if (isQObjectType!T || isObjectType!T || isValueType!T) + { + node_construct(cast(Node*)(p.append()), t); + } + else + { + const T cpy = t; + node_construct(cast(Node*)(p.append()), cpy); + } + } + + alias append opCatAssign; + + static if (isQObjectType!T || isObjectType!T || isValueType!T || is(T == string)) + { + T at(int i) const + { + assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); + return (cast(Node*)(p.at(i))).t(); + } + T opIndex(int i) + { + assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); + return (cast(Node*)(p.at(i))).t(); + } + } + else + { + const (T) at(int i) const // DMD BUG + { + assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); + return (cast(Node*)(p.at(i))).t(); + } + ref T opIndex(int i) + { + assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); + return (cast(Node*)(p.at(i))).t(); + } + } + + static if (isQObjectType!T || isObjectType!T || isValueType!T) //binded types + void node_construct(Node *n, const T t) + { + static if (isValueType!T) + { + if (isLarge!T() || isStatic!T()) // TODO should be static if + n.v = T.__constructNativeCopy(t.__nativeId); // n.v = new T(t); + else if (isComplex!T()) + T.__constructPlacedNativeCopy(t.__nativeId, n); // new (n) T(t); + else + T.__constructPlacedNativeCopy(t.__nativeId, n); // TODO should be *cast(T*)(n) = cast(T)(t); as it is a primitive type. fix when they are implemented with structs + } + else // in case of QObject or Object Qt types we place a pointer to a native object in the node + n = cast(Node*) t.__nativeId; + } + else static if (is(T == string)) + { + void node_construct(Node *n, T t) + { + QString.__constructPlacedQString(n, t); + } + } + else // native types + void node_construct(Node *n, const ref T t) + { + static if (TI.isLarge || TI.isStatic) + n.v = q_new!T(t); // n.v = new T(t); + else static if (TI.isComplex) + q_new_at(n, t); // new (n) T(t); + else + *cast(T*)(n) = cast(T)(t); + } + + void node_copy(Node *from, Node *to, Node *src) + { +// writeln("QList node_copy"); + static if (isQObjectType!T || isObjectType!T) + {} // ensure to do nothing. copying only a pointer + else static if(is(T == string)) + { + while(from != to) // TODO when porting to Qt 5 ensure that QTypeInfo.isLarge and .isStatic == false + QString.__constructPlacedNativeCopy(src++, from++); // new (from++) T(*reinterpret_cast(src++)); + } + else static if (isValueType!T) + { + if (TI.isLarge || TI.isStatic) // TODO should be static if + while(from != to) + (from++).v = T.__constructNativeCopy((src++).v); // (from++)->v = new T(*reinterpret_cast((src++)->v)); + else if (TI.isComplex) + while(from != to) + T.__constructPlacedNativeCopy(src++, from++); // new (from++) T(*reinterpret_cast(src++)); + } + else static if (TI.isLarge || TI.isStatic) + while(from != to) + (from++).v = q_new!T(*cast(T*)((src++).v)); + else static if (TI.isComplex) + while(from != to) + q_new_at(from++, *cast(T*)(src++)); + } + + T[] toArray() + { + T[] res; + res.length = this.length; + for(int i = 0; i < res.length; ++i) + { + static if (isValueType!T) + res[i] = new T(T.__constructNativeCopy(this.at(i).__nativeId)); // Node should probably provide a ptr method to directly extract pointer to the native value stored in the list to avoid creating a dummy D object in t() + else + res[i] = this.opIndex(i); + } + return res; + } + + void free(QListData.Data* data) + { +// writeln("QList data destroyed"); + node_destruct(cast(Node*)(data.array.ptr + data.begin), + cast(Node*)(data.array.ptr + data.end)); + if (data.ref_.load() == 0) + qFree(data); + } + + void node_destruct(Node *from, Node *to) + { + static if (isQObjectType!T || isObjectType!T) //binded types + {} // removing just pointers, do nothing + else static if (is(T == string)) + { + while (from != to) + --to, QString.__callNativeDestructor(to); + } + else static if (isValueType!T) //binded value types + { + if (isLarge!T() || isStatic!T()) // TODO should be static if + while (from != to) + --to, T.__deleteNativeObject(to.v); + else if (isComplex!T()) + while (from != to) + --to, T.__callNativeDestructor(to); + } + else + { + static if (TI.isLarge || TI.isStatic) + while (from != to) --to, q_delete(cast(T*)(to.v)); + else static if (TI.isComplex) + while (from != to) --to, cast(T*)(to).__dtor(); + } + } + + //iteration support + int opApply(int delegate(ref T) dg) + { + int result = 0; + int sz = this.length; + for (int i = 0; i < sz; i++) + { + static if (isQtReference!T) + { + T t = this[i]; // hack to avoid "is not an lvalue" error, since dg accepts ref T + result = dg(t); + } + else + result = dg(this[i]); + + if (result) + break; + } + return result; + } +} + +alias QList!string QStringList; + +QList!T toQList(T)(T[] src) +{ + auto res = QList!T.opCall(); + foreach(elem; src) + res.append(elem); + return res; +} + +QList!T qList(T)() +{ + return QList!T.opCall(); +} + +extern(C) void qtd_create_QList(void *nativeId); +extern(C) void qtd_create_QList_double(void *nativeId); + +extern(C) void qtd_create_QList_QObject(void *nativeId); diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/core/QMetaObject.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/core/QMetaObject.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,390 @@ +module qt.core.QMetaObject; + +import qt.QGlobal; +import qt.core.QObject; +import qtd.QtdObject; + +import std.algorithm; +import std.string; +import std.stdio; + +class Meta +{ + string name; +} + +class MetaType : Meta +{ + this() + { + } +} + +class MetaVariable : Meta +{ + MetaType type; +} + +class MetaCallable : Meta { } + +class MetaMethod : Meta { } + +class QMetaArgument : MetaVariable { } + +class QMetaMethod : MetaMethod +{ +// QMetaArgument[] arguments; + string signature; + int indexOfMethod; + + this(string signature_, int indexOfMethod_) + { + signature = signature_; + indexOfMethod = indexOfMethod_; + } + + string args() const + { + int openBracket = indexOf(signature, '('); + if(signature.length - openBracket - 2 > 0) + return signature[openBracket + 1 .. $-1]; + else + return ""; + } + + string name() const + { + int openBracket = indexOf(signature, '('); + return signature[0..openBracket]; + } +} + +class QMetaSignal : QMetaMethod +{ + this(string signature_, int indexOfMethod_) + { + super(signature_, indexOfMethod_); + } +} + +class QMetaSlot : QMetaMethod +{ + this(string signature_, int indexOfMethod_) + { + super(signature_, indexOfMethod_); + } +} + +class MetaObject : MetaType +{ + MetaObject _base; +} + +struct QMetaObjectNative +{ + QMetaObjectNative *superdata; + immutable(char) *stringdata; + const(uint) *data; + void *extradata; +} + +class QMetaException : Exception { this(string msg) { super(msg); } } + +final class QMetaObject +{ + enum Call + { + InvokeMetaMethod, + ReadProperty, + WriteProperty, + ResetProperty, + QueryPropertyDesignable, + QueryPropertyScriptable, + QueryPropertyStored, + QueryPropertyEditable, + QueryPropertyUser, + CreateInstance + } + + private + { + QMetaObjectNative* _nativeId; + QMetaObject _base; // super class + QMetaObject _firstDerived; // head of the linked list of derived classes + QMetaObject _next; // next sibling on this derivation level + QMetaMethod[] _methods; + ClassInfo _classInfo; + + QObject function(void* nativeId) _createWrapper; + } + + private void addDerived(QMetaObject mo) + { + mo._next = _firstDerived; + _firstDerived = mo; + } + + // NOTE: construction is split between this non-templated constructor and 'construct' function below. + this(QMetaObjectNative* nativeId, QMetaObject base) + { + _nativeId = nativeId; + if (base) + { + base.addDerived(this); + _base = base; + } + } + + // TODO: remove when D acquires templated constructors + void construct(T : QObject, Concrete = T)() + { + _classInfo = T.classinfo; + + _createWrapper = function QObject(void* nativeId) { + // COMPILER BUG: cast is should not be needed + auto obj = new Concrete(nativeId, cast(QtdObjectFlags)(QtdObjectFlags.nativeOwnership | QtdObjectFlags.dynamicEntity)); + // TODO: Probably this should be a virtual call from T's constructor + T.__createEntity(nativeId, cast(void*)obj); + return obj; + }; + } + + /++ + +/ + QMetaObject base() + { + return _base; + } + + /++ + +/ + QMetaObjectNative* nativeId() + { + return _nativeId; + } + + /++ + +/ + ClassInfo classInfo() + { + return _classInfo; + } + + const (QMetaMethod[]) methods() + { + return _methods; + } + + void addMethod(QMetaMethod method_) + { + _methods ~= method_; + } + + QMetaMethod lookUpMethod(string slot) + { + foreach (method; _methods) + if (method.signature == slot) + return method; + if (_base) + return _base.lookUpMethod(slot); + else + return null; + } + + QMetaSignal lookUpSignal(string signal) + { + foreach (method; _methods) + if (method.signature == signal && cast(QMetaSignal)method) + return cast(QMetaSignal)method; + if (_base) + return _base.lookUpSignal(signal); + else + return null; + } + + QMetaMethod[] lookUpMethodOverloads(string methodName) + { + typeof(return) result; + foreach (method; _methods) + if (method.name == methodName) + result ~= method; + if (_base) + result ~= _base.lookUpMethodOverloads(methodName); + return result; + } + + QMetaSignal[] lookUpSignalOverloads(string signalName) + { + typeof(return) result; + foreach (method; _methods) + if (method.name == signalName && cast(QMetaSignal)method) + result ~= cast(QMetaSignal)method; + if (_base) + result ~= _base.lookUpSignalOverloads(signalName); + return result; + } + + private QMetaObject lookupDerived(void*[] moIds) + { + assert (moIds.length >= 1); + + for (auto mo = _firstDerived; mo !is null; mo = mo._next) + { + if (mo._nativeId == moIds[0]) + { + if (moIds.length == 1) // exact match found + return mo; + else // look deeper + return mo.lookupDerived(moIds[1..$]); + } + } + + // no initialized wrapper that matches the native object. + // use the base class wrapper + return this; + } + + QObject getObject(void* nativeObjId) + { + QObject result; + + if (nativeObjId) + { + result = cast(QObject)qtd_get_d_qobject(nativeObjId); + if (!result) + { + auto moId = qtd_QObject_metaObject(nativeObjId); + if (_nativeId == moId) + result = _createWrapper(nativeObjId); + else + { + // get native metaobjects for the entire derivation lattice + // up to, but not including, the current metaobject. + size_t moCount = 1; + + for (void* tmp = moId;;) + { + tmp = qtd_QMetaObject_superClass(tmp); + assert(tmp); + if (tmp == _nativeId) + break; + moCount++; + } + + void*[] moIds = (cast(void**)alloca(moCount * (void*).sizeof))[0..moCount]; + + moIds[--moCount] = moId; + while (moCount > 0) + moIds[--moCount] = moId = qtd_QMetaObject_superClass(moId); + + result = lookupDerived(moIds)._createWrapper(nativeObjId); + } + } + } + + return result; + } + + static void activate(QObject sender, QMetaObject m, int local_signal_index, void **argv) + { + qtd_QMetaObject_activate_3(sender.__nativeId, m.nativeId, local_signal_index, argv); + } + + static void activate(QObject sender, QMetaObject m, int from_local_signal_index, int to_local_signal_index, void **argv) + { + qtd_QMetaObject_activate_4(sender.__nativeId, m.nativeId, from_local_signal_index, to_local_signal_index, argv); + } + + static bool connect(const QObject sender, int signal_index, + const QObject receiver, int method_index, + int type = 0, int *types = null) + { + return qtd_QMetaObject_connect(sender.__nativeId, signal_index, receiver.__nativeId, method_index, type, types); + } + + int indexOfMethod_Cpp(string method) + { + return qtd_QMetaObject_indexOfMethod(_nativeId, toStringz(method)); + } + + int methodCount() + { + return qtd_QMetaObject_methodCount(_nativeId); + } + + static void connectImpl(QObject sender, string signalString, QObject receiver, string methodString, int type) + { + QMetaSignal[] signals; + QMetaMethod[] methods; + QMetaSignal signal; + QMetaMethod method; + + if(indexOf(signalString, '(') > 0) + signal = sender.metaObject.lookUpSignal(signalString); + else + signals = sender.metaObject.lookUpSignalOverloads(signalString); // parameters not specified. Looking for a match + + if(indexOf(methodString, '(') > 0) + method = receiver.metaObject.lookUpMethod(methodString); + else + methods = receiver.metaObject.lookUpMethodOverloads(methodString); // parameters not specified. Looking for a match + + if(!signal && !method) + { + Top: + foreach(sig; signals) + foreach(meth; methods) + if(startsWith(sig.args, meth.args)) + { + signal = sig; + method = meth; + break Top; + } + } + else if (!signal) + { + foreach(sig; signals) + if(startsWith(sig.args, method.args)) + { + signal = sig; + break; + } + } + else if (!method) + { + foreach(meth; methods) + if(startsWith(signal.args, meth.args)) + { + method = meth; + break; + } + } + + bool success = false; + + if(!signal && !method) + { + success = false; + } + else + { + int signalIndex = signal.indexOfMethod; + int methodIndex = method.indexOfMethod; + success = QMetaObject.connect(sender, signalIndex, receiver, methodIndex, type); + } + + if(!success) + throw new QMetaException("QMetaObject: Signal " ~ signalString ~ " and slot " ~ methodString ~ " cannot be found"); + } +} + +extern(C) void qtd_QMetaObject_activate_3(void* sender, void* m, int local_signal_index, void **argv); +extern(C) void qtd_QMetaObject_activate_4(void *sender, void* m, int from_local_signal_index, int to_local_signal_index, void **argv); +extern(C) bool qtd_QMetaObject_connect(const void* sender, int signal_index, + const void* receiver, int method_index, + int type, int *types); + +extern(C) int qtd_QMetaObject_indexOfMethod(void *nativeId, const(char) *method); +extern(C) int qtd_QMetaObject_methodCount(void *nativeId); + +extern(C) void* qtd_QMetaObject_superClass(void* nativeId); diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/core/QMetaType.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/core/QMetaType.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,113 @@ +module qt.core.QMetaType; +public import qt.core.Qt; +private import qt.core.QDataStream; + +version (Tango) +{ + import tango.core.Array; + import tango.stdc.stringz; + import tango.core.Traits; +} + +alias extern(C) void *function(void *copy) Ctor; +alias extern(C) void function(void *obj) Dtor; +alias extern(C) void function(void *stream, void * object) StreamOp; + +struct DArrayToC +{ + void[] array; +} + +public template MetaTypeOps(T) +{ + // TODO: + // static assert(typeof(new T), "Type " ~ T.stringof ~ " has no default constructor"); + // static assert(typeof(new T(T.init))), "Type " ~ T.stringof ~ " has no default copy constructor"); + + extern(C) void* ctor(void* copy) + { + static if (is(T == class) || is(T == interface)) + { + return cast(void*)(copy ? new T(cast(T)copy) : new T); + } + else static if (isDynamicArrayType!(T) || isStaticArrayType!(T) ) + { + auto darray = new DArrayToC; + if(copy) + darray.array = (cast(DArrayToC*)copy).array.dup; + return cast(void*)darray; + } + else + { + auto data = new T; + if(copy) + *data = *cast(T*)copy; + return cast(void*)data; + } + } + + + extern(C) void dtor(void* obj) + { + static if (is(T == class) || is(T == interface)) + { + auto tmp = cast(T)obj; + delete tmp; + } + else + { + auto tmp = cast(T*)obj; + delete tmp; + } + } +} + +public int qRegisterMetaType(T)(string name = null) +{ + if (!name.length) + name = typeid(T).toString; + + return qtd_registerType(toStringz(name), &MetaTypeOps!(T).ctor, &MetaTypeOps!(T).dtor); +} + +/* Not work.... +private class DataStreamPriv: QDataStream +{ + this(void * cobj) + { + super(cobj); + } +} +*/ +/* +public void qRegisterMetaTypeStreamOperators(T)(void function(ref QDataStream, T ) saveOp, void function (ref QDataStream, ref T) loadOp, string name = null) +{ + static void function(ref QDataStream, T ) SaveOp; + static void function (ref QDataStream, ref T) LoadOp; + SaveOp = saveOp; + LoadOp = loadOp; + + if (!name.length) + name = typeid(T).toString; + + extern(C) void saveOpC(void *stream, void *object) + { + QDataStream dstream = new DataStreamPriv(stream); + Stdout(object).newline; + static if (is(T == class) || is(T == interface)) + SaveOp(dstream, cast(T)object); + else + SaveOp(dstream, *cast(T*)object); + } + + extern(C) void loadOpC(void *stream, void *object) + { + //return stream; + } + + qtd_registerStreamOperators(toStringz(name), cast(StreamOp)&saveOpC, cast(StreamOp)&loadOpC); +} +*/ +private extern(C) void qtd_registerStreamOperators(char *typeName, StreamOp saveOp, StreamOp loadOp); +private extern(C) int qtd_registerType(in char* namePtr, Ctor ctor, Dtor dtor); +extern(C) int qtd_MetatypeId(in char *id); // TODO: wrap to D. \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/core/QModelIndex.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/core/QModelIndex.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,128 @@ +module qt.core.QModelIndex; + +public import qt.QGlobal; +private import qt.core.QObject; + +// automatic imports------------- +//private import qt.core.QVariant; +private import qt.core.QAbstractItemModel; +public import qt.core.Qt; + + +public struct QModelIndex +{ + public static QModelIndex opCall() { + QModelIndex mi; + mi.r = mi.c = -1; + mi.p = mi.m = null; + return mi; + } + + public final QModelIndex child(int row, int column) { + return __qtd_QModelIndex_child_int_int(&this, row, column); + } + + public final int column() const { + return __qtd_QModelIndex_column(cast(void*)&this); + } + + public final QVariant data(int role = 0) { + void* __qt_return_value = __qtd_QModelIndex_data_int(&this, role); + return new QVariant(__qt_return_value); + } + + public final int flags() { + return __qtd_QModelIndex_flags(&this); + } + + public final long internalId() { + return __qtd_QModelIndex_internalId(&this); + } + + public final void* internalPointer() const { + //return __qtd_QModelIndex_internalPointer(&this); + return cast(void*)p; + } + + public final Object object() { + return cast(Object) p; + } + + public final bool isValid() const { + return __qtd_QModelIndex_isValid(cast(void*)&this); + } + + public final QAbstractItemModel model() { +// void* __qt_return_value = __qtd_QModelIndex_model(&this); + void* __qt_return_value = m; + if (__qt_return_value is null) + return null; + void* d_obj = qtd_get_d_qobject(__qt_return_value); + return cast(QAbstractItemModel) d_obj; + } + + private final bool operator_less(QModelIndex other) { + return __qtd_QModelIndex_operator_less_QModelIndex(&this, other); + } + + private final bool operator_equal(QModelIndex other) { + return __qtd_QModelIndex_operator_equal_QModelIndex(&this, other); + } + + public final QModelIndex parent() { + return __qtd_QModelIndex_parent(&this); + } + + public final int row() const { + return __qtd_QModelIndex_row(cast(void*)&this); + } + + public final QModelIndex sibling(int row, int column) { + return __qtd_QModelIndex_sibling_int_int(&this, row, column); + } + + public alias void __isNativeValueType; + + struct QTypeInfo + { + enum bool isComplex = true; + enum bool isStatic = false; + enum bool isLarge = true; + enum bool isPointer = false; + enum bool isDummy = false; + } + +private: + int r; + int c; + void *p; + void *m; +} + + +alias QModelIndex QModelIndexAccessor; + + +// C wrappers +private extern(C) void* __qtd_QModelIndex_QModelIndex_QModelIndex(QModelIndex other0); +private extern(C) QModelIndex __qtd_QModelIndex_child_int_int(void* __this_nativeId, + int row0, + int column1); +private extern(C) int __qtd_QModelIndex_column(void* __this_nativeId); +private extern(C) void* __qtd_QModelIndex_data_int(void* __this_nativeId, + int role0); +private extern(C) int __qtd_QModelIndex_flags(void* __this_nativeId); +private extern(C) long __qtd_QModelIndex_internalId(void* __this_nativeId); +private extern(C) void* __qtd_QModelIndex_internalPointer(void* __this_nativeId); +private extern(C) bool __qtd_QModelIndex_isValid(void* __this_nativeId); +private extern(C) void* __qtd_QModelIndex_model(void* __this_nativeId); +private extern(C) bool __qtd_QModelIndex_operator_less_QModelIndex(void* __this_nativeId, + QModelIndex other0); +private extern(C) bool __qtd_QModelIndex_operator_equal_QModelIndex(void* __this_nativeId, + QModelIndex other0); +private extern(C) QModelIndex __qtd_QModelIndex_parent(void* __this_nativeId); +private extern(C) int __qtd_QModelIndex_row(void* __this_nativeId); +private extern(C) QModelIndex __qtd_QModelIndex_sibling_int_int(void* __this_nativeId, + int row0, + int column1); + \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/core/QPoint.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/core/QPoint.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,254 @@ +module qt.core.QPoint; + +public import qt.QGlobal; +public import qt.core.Qt; +public import qt.core.QDataStream; + + +public struct QPoint +{ + +// Functions + public static QPoint opCall() { + QPoint pt; + pt.xp = pt.yp = 0; + return pt; + } + + public this(int xpos, int ypos) { + xp = xpos; + yp = ypos; + } + + bool isNull() // const + { return xp == 0 && yp == 0; } + + int x() const + { return xp; } + + int y() const + { return yp; } + + void x(int xpos) + { xp = xpos; } + + void y(int ypos) + { yp = ypos; } + + void setX(int xpos) // for convenience + { xp = xpos; } + + void setY(int ypos) // for convenience + { yp = ypos; } + + public final int manhattanLength() { + return qtd_QPoint_manhattanLength(&this); + } +/* +inline int &rx() +{ return xp; } + +inline int &ry() +{ return yp; } +*/ + + QPoint opAddAssign(ref QPoint p) + { xp+=p.xp; yp+=p.yp; return this; } + + QPoint opSubAssign(ref QPoint p) + { xp-=p.xp; yp-=p.yp; return this; } + + QPoint opMulAssign(qreal c) + { xp = qRound(xp*c); yp = qRound(yp*c); return this; } + + bool opEquals(ref const QPoint p) const + { return xp == p.xp && yp == p.yp; } + + QPoint opAdd(ref QPoint p) + { return QPoint(this.xp+p.xp, this.yp+p.yp); } + + QPoint opSub(ref QPoint p) + { return QPoint(this.xp-p.xp, this.yp-p.yp); } + + QPoint opMul(qreal c) + { return QPoint(qRound(this.xp*c), qRound(this.yp*c)); } + + QPoint opDivAssign(qreal c) + { + xp = qRound(xp/c); + yp = qRound(yp/c); + return this; + } + + QPoint opDiv(qreal c) + { + return QPoint(qRound(this.xp/c), qRound(this.yp/c)); + } + + public final void writeTo(QDataStream arg__1) { + qtd_QPoint_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final void readFrom(QDataStream arg__1) { + qtd_QPoint_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); + } + + // service stuff + public alias void __isNativeValueType; + + struct QTypeInfo + { + enum bool isComplex = true; + enum bool isStatic = false; + enum bool isLarge = true; + enum bool isPointer = false; + enum bool isDummy = false; + } + + +private: + // ### Qt 5; remove the ifdef and just have the same order on all platforms. + version(OSX) + { + int yp; + int xp; + } + else + { + int xp; + int yp; + } +} + + +public struct QPointF +{ + public static QPointF opCall() { + QPointF pt; + pt.xp = pt.yp = 0; + return pt; + } + + public this(qreal xpos, qreal ypos) { + xp = xpos; + yp = ypos; + } + + public this(QPoint p) { + xp = p.x(); + yp = p.y(); + } + + bool isNull() //const + { + return qIsNull(xp) && qIsNull(yp); + } + + qreal x() //const + { + return xp; + } + + qreal y() //const + { + return yp; + } + + void x(qreal xpos) + { + xp = xpos; + } + + void y(qreal ypos) + { + yp = ypos; + } +/* +inline qreal &QPointF::rx() +{ + return xp; +} + +inline qreal &QPointF::ry() +{ + return yp; +} +*/ + + QPointF opAddAssign(ref QPointF p) + { xp+=p.xp; yp+=p.yp; return this; } + + QPointF opSubAssign(ref QPointF p) + { xp-=p.xp; yp-=p.yp; return this; } + + QPointF opMulAssign(qreal c) + { xp*=c; yp*=c; return this; } + + bool opEquals(ref const QPointF p) const + { return qFuzzyCompare(xp, p.xp) && qFuzzyCompare(yp, p.yp); } + + QPointF opAdd(ref QPointF p) + { return QPointF(this.xp+p.xp, this.yp+p.yp); } + + QPointF opSub(ref QPointF p) + { return QPointF(this.xp-p.xp, this.yp-p.yp); } + + QPointF opMul(qreal c) + { return QPointF(this.xp*c, this.yp*c); } + + QPointF opDivAssign(qreal c) + { + xp/=c; + yp/=c; + return this; + } + + QPointF opDiv(qreal c) + { + return QPointF(xp/c, yp/c); + } + + QPoint toPoint() //const + { + return QPoint(qRound(xp), qRound(yp)); + } + + public final void writeTo(QDataStream arg__1) { + qtd_QPointF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final void readFrom(QDataStream arg__1) { + qtd_QPointF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); + } + + // service stuff + public alias void __isNativeValueType; + + struct QTypeInfo + { + enum bool isComplex = true; + enum bool isStatic = false; + enum bool isLarge = true; + enum bool isPointer = false; + enum bool isDummy = false; + } + +private: + qreal xp; + qreal yp; +} + + +// C wrappers +// QPoint +private extern(C) int qtd_QPoint_manhattanLength(void* __this_nativeId); +private extern(C) void qtd_QPoint_writeTo_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void qtd_QPoint_readFrom_QDataStream(void* __this_nativeId, + void* arg__1); + +// QPointF +private extern(C) void qtd_QPointF_writeTo_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void qtd_QPointF_readFrom_QDataStream(void* __this_nativeId, + void* arg__1); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/core/QPointF.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/core/QPointF.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,4 @@ +module qt.core.QPointF; +/* dummy */ + +public import qt.core.QPoint; diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/core/QRect.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/core/QRect.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,388 @@ +module qt.core.QRect; + +public import qt.QGlobal; +public import qt.core.Qt; +public import qt.core.QDataStream; +public import qt.core.QSize; +public import qt.core.QPoint; + + +public struct QRect +{ + public static QRect opCall() { + QRect rt; + rt.x1 = rt.y1 = 0; + rt.x2 = rt.y2 = -1; + return rt; + } + + public this(int aleft, int atop, int awidth, int aheight) + { + x1 = aleft; + y1 = atop; + x2 = (aleft + awidth - 1); + y2 = (atop + aheight - 1); + } + + public this(QPoint atopLeft, QPoint abottomRight) + { + x1 = atopLeft.x(); + y1 = atopLeft.y(); + x2 = abottomRight.x(); + y2 = abottomRight.y(); + } + + public this(ref QPoint atopLeft, ref QSize asize) + { + x1 = atopLeft.x(); + y1 = atopLeft.y(); + x2 = (x1+asize.width() - 1); + y2 = (y1+asize.height() - 1); + } + + bool isNull() const + { return x2 == x1 - 1 && y2 == y1 - 1; } + + bool isEmpty() const + { return x1 > x2 || y1 > y2; } + + bool isValid() const + { return x1 <= x2 && y1 <= y2; } + + int left() const + { return x1; } + + int top() const + { return y1; } + + int right() const + { return x2; } + + int bottom() const + { return y2; } + + int x() const + { return x1; } + + int y() const + { return y1; } + + void left(int pos) + { x1 = pos; } + + void top(int pos) + { y1 = pos; } + + void right(int pos) + { x2 = pos; } + + void bottom(int pos) + { y2 = pos; } + + void setLeft(int pos) + { x1 = pos; } + + void setTop(int pos) + { y1 = pos; } + + void setRight(int pos) + { x2 = pos; } + + void setBottom(int pos) + { y2 = pos; } + + void setTopLeft(const QPoint p) + { x1 = p.x(); y1 = p.y(); } + + void setBottomRight(const QPoint p) + { x2 = p.x(); y2 = p.y(); } + + void setTopRight(const QPoint p) + { x2 = p.x(); y1 = p.y(); } + + void setBottomLeft(const QPoint p) + { x1 = p.x(); y2 = p.y(); } + + void setX(int ax) + { x1 = ax; } + + void setY(int ay) + { y1 = ay; } + + QPoint topLeft() const + { return QPoint(x1, y1); } + + QPoint bottomRight() const + { return QPoint(x2, y2); } + + QPoint topRight() const + { return QPoint(x2, y1); } + + QPoint bottomLeft() const + { return QPoint(x1, y2); } + + QPoint center() const + { return QPoint((x1+x2)/2, (y1+y2)/2); } + + int width() const + { return x2 - x1 + 1; } + + int height() const + { return y2 - y1 + 1; } + + QSize size() const + { return QSize(width(), height()); } + + void translate(int dx, int dy) + { + x1 += dx; + y1 += dy; + x2 += dx; + y2 += dy; + } + + void translate(const QPoint p) + { + x1 += p.x(); + y1 += p.y(); + x2 += p.x(); + y2 += p.y(); + } + + QRect translated(int dx, int dy) const + { return QRect(QPoint(x1 + dx, y1 + dy), QPoint(x2 + dx, y2 + dy)); } + + QRect translated(const QPoint p) const + { return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); } + + void moveTo(int ax, int ay) + { + x2 += ax - x1; + y2 += ay - y1; + x1 = ax; + y1 = ay; + } + + void moveTo(const QPoint p) + { + x2 += p.x() - x1; + y2 += p.y() - y1; + x1 = p.x(); + y1 = p.y(); + } + + void moveLeft(int pos) + { x2 += (pos - x1); x1 = pos; } + + void moveTop(int pos) + { y2 += (pos - y1); y1 = pos; } + + void moveRight(int pos) + { + x1 += (pos - x2); + x2 = pos; + } + + void moveBottom(int pos) + { + y1 += (pos - y2); + y2 = pos; + } + + void moveTopLeft(const QPoint p) + { + moveLeft(p.x()); + moveTop(p.y()); + } + + void moveBottomRight(const QPoint p) + { + moveRight(p.x()); + moveBottom(p.y()); + } + + void moveTopRight(const QPoint p) + { + moveRight(p.x()); + moveTop(p.y()); + } + + void moveBottomLeft(const QPoint p) + { + moveLeft(p.x()); + moveBottom(p.y()); + } + + void getRect(int *ax, int *ay, int *aw, int *ah) const + { + *ax = x1; + *ay = y1; + *aw = x2 - x1 + 1; + *ah = y2 - y1 + 1; + } + + void setRect(int ax, int ay, int aw, int ah) + { + x1 = ax; + y1 = ay; + x2 = (ax + aw - 1); + y2 = (ay + ah - 1); + } + + void getCoords(int *xp1, int *yp1, int *xp2, int *yp2) const + { + *xp1 = x1; + *yp1 = y1; + *xp2 = x2; + *yp2 = y2; + } + + void setCoords(int xp1, int yp1, int xp2, int yp2) + { + x1 = xp1; + y1 = yp1; + x2 = xp2; + y2 = yp2; + } + + QRect adjusted(int xp1, int yp1, int xp2, int yp2) const + { return QRect(QPoint(x1 + xp1, y1 + yp1), QPoint(x2 + xp2, y2 + yp2)); } + + void adjust(int dx1, int dy1, int dx2, int dy2) + { + x1 += dx1; + y1 += dy1; + x2 += dx2; + y2 += dy2; + } + + void setWidth(int w) + { x2 = (x1 + w - 1); } + + void setHeight(int h) + { y2 = (y1 + h - 1); } + + void setSize(const QSize s) + { + x2 = (s.width() + x1 - 1); + y2 = (s.height() + y1 - 1); + } + + bool contains(int ax, int ay, bool aproper) const + { + return contains(QPoint(ax, ay), aproper); + } + + bool contains(int ax, int ay) const + { + return contains(QPoint(ax, ay), false); + } + + QRect opOrAssign(const QRect r) + { + this = this | r; + return this; + } + + QRect opAndAssign(const QRect r) + { + this = this & r; + return this; + } + + QRect intersected(const QRect other) const + { + return this & other; + } + + QRect united(const QRect r) const + { + return this | r; + } + + bool opEquals(ref const QRect r) const + { + return x1==r.x1 && x2==r.x2 && y1==r.y1 && y2==r.y2; + } + + public final void writeTo(QDataStream arg__1) { + qtd_QRect_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final void readFrom(QDataStream arg__1) { + qtd_QRect_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final QRect opAnd(const QRect r) const { + return qtd_QRect_operator_and_QRect(&this, &r); + } + + public final QRect opOr(const QRect r) const { + return qtd_QRect_operator_or_QRect(&this, &r); + } + + public final bool contains(const QPoint p, bool proper = false) const { + return qtd_QRect_contains_QPoint_bool(&this, &p, proper); + } + + public final bool contains(const QRect r, bool proper = false) const { + return qtd_QRect_contains_QRect_bool(&this, &r, proper); + } + + public final bool intersects(const QRect r) const { + return qtd_QRect_intersects_QRect(&this, &r); + } + + public final QRect normalized() const { + return qtd_QRect_normalized(&this); + } + + // service stuff + public alias void __isNativeValueType; + + struct QTypeInfo + { + enum bool isComplex = true; + enum bool isStatic = false; + enum bool isLarge = true; + enum bool isPointer = false; + enum bool isDummy = false; + } + + +private: + version(OSX) + { + int y1; + int x1; + int y2; + int x2; + } + else + { + int x1; + int y1; + int x2; + int y2; + } +} + + +// C wrappers +private extern(C) bool qtd_QRect_contains_QPoint_bool(const void* __this_nativeId, + const void* p0, + bool proper1); +private extern(C) bool qtd_QRect_contains_QRect_bool(const void* __this_nativeId, + const void* r0, + bool proper1); +private extern(C) bool qtd_QRect_intersects_QRect(const void* __this_nativeId, + const void* r0); +private extern(C) QRect qtd_QRect_normalized(const void* __this_nativeId); +private extern(C) void qtd_QRect_writeTo_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void qtd_QRect_readFrom_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) QRect qtd_QRect_operator_and_QRect(const void* __this_nativeId, + const void* r0); +private extern(C) QRect qtd_QRect_operator_or_QRect(const void* __this_nativeId, + const void* r0); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/core/QRectF.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/core/QRectF.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,340 @@ +module qt.core.QRectF; + +public import qt.QGlobal; +public import qt.core.Qt; +public import qt.core.QPointF; +public import qt.core.QRect; +public import qt.core.QSizeF; +public import qt.core.QDataStream; + + +public struct QRectF +{ + public static QRectF opCall() + { + QRectF rt; + rt.xp = rt.yp = 0.; + rt.w = rt.h = 0.; + return rt; + } + + public this(qreal aleft, qreal atop, qreal awidth, qreal aheight) + { + xp = aleft; + yp = atop; + w = awidth; + h = aheight; + } + + public this(QPointF atopLeft, QSizeF asize) + { + xp = atopLeft.x(); + yp = atopLeft.y(); + w = asize.width(); + h = asize.height(); + } + + public this(QPointF atopLeft, QPointF abottomRight) + { + xp = atopLeft.x(); + yp = atopLeft.y(); + w = abottomRight.x() - xp; + h = abottomRight.y() - yp; + } + + public this(QRect r) + { + xp = r.x(); + yp = r.y(); + w = r.width(); + h = r.height(); + } + + bool isNull() const + { return qIsNull(w) && qIsNull(h); } + + bool isEmpty() const + { return w <= 0. || h <= 0.; } + + bool isValid() const + { return w > 0. && h > 0.; } + + qreal x() const + { return xp; } + + qreal y() const + { return yp; } + + qreal left() const + { return xp; } + + qreal top() const + { return yp; } + + qreal right() const + { return xp + w; } + + qreal bottom() const + { return yp + h; } + + QPointF topLeft() const + { return QPointF(xp, yp); } + + QPointF bottomRight() const + { return QPointF(xp+w, yp+h); } + + QPointF topRight() const + { return QPointF(xp+w, yp); } + + QPointF bottomLeft() const + { return QPointF(xp, yp+h); } + + void setLeft(qreal pos) { qreal diff = pos - xp; xp += diff; w -= diff; } + + void setRight(qreal pos) { w = pos - xp; } + + void setTop(qreal pos) { qreal diff = pos - yp; yp += diff; h -= diff; } + + void setBottom(qreal pos) { h = pos - yp; } + + void setTopLeft(ref QPointF p) { setLeft(p.x()); setTop(p.y()); } + + void setTopRight(ref QPointF p) { setRight(p.x()); setTop(p.y()); } + + void setBottomLeft(ref QPointF p) { setLeft(p.x()); setBottom(p.y()); } + + void setBottomRight(ref QPointF p) { setRight(p.x()); setBottom(p.y()); } + + QPointF center() const + { return QPointF(xp + w/2, yp + h/2); } + + void moveLeft(qreal pos) { xp = pos; } + + void moveTop(qreal pos) { yp = pos; } + + void moveRight(qreal pos) { xp = pos - w; } + + void moveBottom(qreal pos) { yp = pos - h; } + + void moveTopLeft(ref QPointF p) { moveLeft(p.x()); moveTop(p.y()); } + + void moveTopRight(ref QPointF p) { moveRight(p.x()); moveTop(p.y()); } + + void moveBottomLeft(ref QPointF p) { moveLeft(p.x()); moveBottom(p.y()); } + + void moveBottomRight(ref QPointF p) { moveRight(p.x()); moveBottom(p.y()); } + + void moveCenter(ref QPointF p) { xp = p.x() - w/2; yp = p.y() - h/2; } + + qreal width() const + { return w; } + + qreal height() const + { return h; } + + QSizeF size() const + { return QSizeF(w, h); } + + void translate(qreal dx, qreal dy) + { + xp += dx; + yp += dy; + } + + void translate(ref QPointF p) + { + xp += p.x(); + yp += p.y(); + } + + void moveTo(qreal ax, qreal ay) + { + xp = ax; + yp = ay; + } + + void moveTo(ref QPointF p) + { + xp = p.x(); + yp = p.y(); + } + + QRectF translated(qreal dx, qreal dy) const + { return QRectF(xp + dx, yp + dy, w, h); } + + QRectF translated(ref QPointF p) const + { return QRectF(xp + p.x(), yp + p.y(), w, h); } + + void getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const + { + *ax = this.xp; + *ay = this.yp; + *aaw = this.w; + *aah = this.h; + } + + void setRect(qreal ax, qreal ay, qreal aaw, qreal aah) + { + this.xp = ax; + this.yp = ay; + this.w = aaw; + this.h = aah; + } + + void getCoords(qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2) const + { + *xp1 = xp; + *yp1 = yp; + *xp2 = xp + w; + *yp2 = yp + h; + } + + void setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2) + { + xp = xp1; + yp = yp1; + w = xp2 - xp1; + h = yp2 - yp1; + } + + void adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2) + { xp += xp1; yp += yp1; w += xp2 - xp1; h += yp2 - yp1; } + + QRectF adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const + { return QRectF(xp + xp1, yp + yp1, w + xp2 - xp1, h + yp2 - yp1); } + + void setWidth(qreal aw) // for convenience + { this.w = aw; } + + void setHeight(qreal ah) // for convenience + { this.h = ah; } + + void setSize(ref QSizeF s) // for convenience + { + w = s.width(); + h = s.height(); + } + + void width(qreal aw) + { this.w = aw; } + + void height(qreal ah) + { this.h = ah; } + + void size(ref QSizeF s) + { + w = s.width(); + h = s.height(); + } + + bool contains(qreal ax, qreal ay) const + { + return contains(QPointF(ax, ay)); + } + + QRectF opOrAssign(ref QRectF r) + { + this = this | r; + return this; + } + + QRectF opAndAssign(ref QRectF r) + { + this = this & r; + return this; + } + + QRectF intersected(ref QRectF r) const + { + return this & r; + } + + QRectF united(ref QRectF r) const + { + return this | r; + } + + bool opEquals(ref const QRectF r) const + { + return qFuzzyCompare(xp, r.xp) && qFuzzyCompare(yp, r.yp) + && qFuzzyCompare(w, r.w) && qFuzzyCompare(h, r.h); + } + + QRect toRect() const + { + return QRect(qRound(xp), qRound(yp), qRound(w), qRound(h)); + } + + public final bool contains(QPointF p) const { + return qtd_QRectF_contains_QPointF(cast(void*)&this, &p); + } + + public final bool contains(QRectF r) const { + return qtd_QRectF_contains_QRectF(cast(void*)&this, &r); + } + + public final bool intersects(QRectF r) const { + return qtd_QRectF_intersects_QRectF(cast(void*)&this, &r); + } + + public final QRectF normalized() const { + return qtd_QRectF_normalized(cast(void*)&this); + } + + public final QRectF opAnd(ref QRectF r) const { + return qtd_QRectF_operator_and_QRectF(cast(void*)&this, &r); + } + + public final void writeTo(QDataStream arg__1) { + qtd_QRectF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final void readFrom(QDataStream arg__1) { + qtd_QRectF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); + } + + public final QRectF opOr(ref QRectF r) const { + return qtd_QRectF_operator_or_QRectF(cast(void*)&this, &r); + } + + public final QRect toAlignedRect() const + { + return qtd_QRectF_toAlignedRect(cast(void*)&this); + } + + // service stuff + public alias void __isNativeValueType; + + struct QTypeInfo + { + enum bool isComplex = true; + enum bool isStatic = false; + enum bool isLarge = true; + enum bool isPointer = false; + enum bool isDummy = false; + } +private: + qreal xp; + qreal yp; + qreal w; + qreal h; +} + + +// C wrappers +private extern(C) bool qtd_QRectF_contains_QPointF(void* __this_nativeId, + void* p0); +private extern(C) bool qtd_QRectF_contains_QRectF(void* __this_nativeId, + void* r0); +private extern(C) bool qtd_QRectF_intersects_QRectF(void* __this_nativeId, + void* r0); +private extern(C) QRectF qtd_QRectF_normalized(void* __this_nativeId); +private extern(C) QRectF qtd_QRectF_operator_and_QRectF(void* __this_nativeId, + void* r0); +private extern(C) void qtd_QRectF_writeTo_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void qtd_QRectF_readFrom_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) QRectF qtd_QRectF_operator_or_QRectF(void* __this_nativeId, + void* r0); +private extern(C) QRect qtd_QRectF_toAlignedRect(void* __this_nativeId); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/core/QSize.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/core/QSize.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,297 @@ +module qt.core.QSize; + +public import qt.QGlobal; +public import qt.core.Qt; + + +public struct QSize +{ +/* ctors, reserved for D2 + public this() + { wd = ht = -1; } + + public this(int w, int h) + { wd = w; ht = h; } +*/ + + public static QSize opCall() { + QSize sz; + sz.wd = sz.ht = -1; + return sz; + } + + public this(int w, int h) { + wd = w; + ht = h; + } + + final bool isNull() + { return wd==0 && ht==0; } + + final bool isEmpty() + { return wd<1 || ht<1; } + + final bool isValid() + { return wd>=0 && ht>=0; } + + final int width() const + { return wd; } + + final int height() const + { return ht; } + + final void width(int w) + { wd = w; } + + final void height(int h) + { ht = h; } + + final void setWidth(int w) // for convenience + { wd = w; } + + final void setHeight(int h) // for convenience + { ht = h; } + + void transpose() { + int tmp = wd; + wd = ht; + ht = tmp; + } + + void scale(int w, int h, Qt.AspectRatioMode mode) { + scale(QSize(w, h), mode); + } + + void scale(ref QSize s, Qt.AspectRatioMode mode) { + __qtd_QSize_scale_QSize_AspectRatioMode(&this, &s, mode); + } + + QSize expandedTo(ref QSize otherSize) { + return QSize(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht)); + } + + QSize boundedTo(ref QSize otherSize) { + return QSize(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht)); + } +/* + public final void writeTo(QDataStream arg__1) { + __qtd_QSize_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.nativeId); + } + + public final void readFrom(QDataStream arg__1) { + __qtd_QSize_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.nativeId); + } +*/ + QSize opAddAssign(ref QSize s) + { wd+=s.wd; ht+=s.ht; return this; } + + QSize opSubAssign(ref QSize s) + { wd-=s.wd; ht-=s.ht; return this; } + + QSize opMulAssign(qreal c) + { wd = qRound(wd*c); ht = qRound(ht*c); return this; } + + bool opEquals(ref const QSize s) const + { return wd == s.wd && ht == s.ht; } + + QSize opAdd(ref QSize s) + { return QSize(this.wd+s.wd, this.ht+s.ht); } + + QSize opSub(ref QSize s) + { return QSize(this.wd-s.wd, this.ht-s.ht); } + + QSize opMul(qreal c) + { return QSize(qRound(this.wd*c), qRound(this.ht*c)); } + + QSize opDivAssign(qreal c) { + assert(!qFuzzyCompare(c + 1, 1.)); + wd = qRound(wd/c); ht = qRound(ht/c); + return this; + } + + QSize opDiv(qreal c) { + assert(!qFuzzyCompare(c + 1, 1.)); + return QSize(qRound(this.wd/c), qRound(this.ht/c)); + } + + // service stuff + public alias void __isNativeValueType; + + struct QTypeInfo + { + enum bool isComplex = true; + enum bool isStatic = false; + enum bool isLarge = true; + enum bool isPointer = false; + enum bool isDummy = false; + } +private: + int wd; + int ht; +} + + +public struct QSizeF +{ +/* ctors, reserved for D2 + this() + { wd = ht = -1.; } + + this(ref QSize sz) + { wd = sz.width(); ht = sz.height(); } + + this(qreal w, qreal h) + { wd = w; ht = h; } +*/ + public static QSizeF opCall() { + QSizeF sz; + sz.wd = sz.ht = -1.; + return sz; + } + + public static QSizeF opCall(ref QSizeF s) { + QSizeF sz; + sz.wd = s.width(); sz.ht = s.height(); + return sz; + } + + public static QSizeF opCall(qreal w, qreal h) { + QSizeF sz; + sz.wd = w; sz.ht = h; + return sz; + } + + bool isNull() + { return qIsNull(wd) && qIsNull(ht); } + + bool isEmpty() + { return wd <= 0. || ht <= 0.; } + + bool isValid() + { return wd >= 0. && ht >= 0.; } + + qreal width() + { return wd; } + + qreal height() + { return ht; } + + void width(qreal w) + { wd = w; } + + void height(qreal h) + { ht = h; } + + void setWidth(qreal w) + { wd = w; } + + void setHeight(qreal h) + { ht = h; } + + void scale(qreal w, qreal h, Qt.AspectRatioMode mode) + { scale(QSizeF(w, h), mode); } + + public final void scale(QSizeF s, Qt.AspectRatioMode mode) + { __qtd_QSizeF_scale_QSizeF_AspectRatioMode(&this, &s, mode); } + + void transpose() { + qreal tmp = wd; + wd = ht; + ht = tmp; + } + + QSizeF expandedTo(ref QSizeF otherSize) + { return QSizeF(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht)); } + + QSizeF boundedTo(ref QSizeF otherSize) + { return QSizeF(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht)); } + + QSize toSize() + { return QSize(qRound(wd), qRound(ht)); } +/* + public final void writeTo(QDataStream arg__1) { + __qtd_QSizeF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.nativeId); + } + + public final void readFrom(QDataStream arg__1) { + __qtd_QSizeF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.nativeId); +*/ + QSizeF opAddAssign(ref QSizeF s) + { wd += s.wd; ht += s.ht; return this; } + + QSizeF opSubAssign(ref QSizeF s) + { wd -= s.wd; ht -= s.ht; return this; } + + QSizeF opMulAssign(qreal c) + { wd *= c; ht *= c; return this; } + + bool opEquals(ref const QSizeF s) const + { return qFuzzyCompare(wd, s.wd) && qFuzzyCompare(ht, s.ht); } + + QSizeF opAdd(ref QSizeF s) + { return QSizeF(this.wd+s.wd, this.ht+s.ht); } + + QSizeF opSub(ref QSizeF s) + { return QSizeF(this.wd-s.wd, this.ht-s.ht); } + + QSizeF opMul(qreal c) + { return QSizeF(this.wd*c, this.ht*c); } + + QSizeF opDivAssign(qreal c) + { + assert(!qFuzzyCompare(c + 1, 1.)); + wd = wd/c; ht = ht/c; + return this; + } + + QSizeF opDiv(qreal c) + { + assert(!qFuzzyCompare(c + 1, 1.)); + return QSizeF(this.wd/c, this.ht/c); + } + + // service stuff + public alias void __isNativeValueType; + + struct QTypeInfo + { + enum bool isComplex = true; + enum bool isStatic = false; + enum bool isLarge = true; + enum bool isPointer = false; + enum bool isDummy = false; + } +private: + qreal wd; + qreal ht; +} + + +extern (C) void qtd_append_array_QSize(QSize[]* arr, QSize arg) +{ + *arr ~= arg; +} + +extern (C) void qtd_append_array_QSizeF(QSizeF[]* arr, QSizeF arg) +{ + *arr ~= arg; +} + +// C wrappers +// QSize +private extern(C) void __qtd_QSize_scale_QSize_AspectRatioMode(void* __this_nativeId, + void* s0, + int mode1); +private extern(C) void __qtd_QSize_writeTo_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void __qtd_QSize_readFrom_QDataStream(void* __this_nativeId, + void* arg__1); + +// QSizeF +private extern(C) void __qtd_QSizeF_writeTo_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void __qtd_QSizeF_readFrom_QDataStream(void* __this_nativeId, + void* arg__1); +private extern(C) void __qtd_QSizeF_scale_QSizeF_AspectRatioMode(void* __this_nativeId, + void* s0, + int mode1); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/core/QSizeF.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/core/QSizeF.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,4 @@ +module qt.core.QSizeF; +/* dummy */ + +public import qt.core.QSize; diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/core/QString.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/core/QString.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,112 @@ +module qt.core.QString; + +import qt.QGlobal; + +version (Tango) +{ + public import tango.text.convert.Utf : toUTF8 = toString; +} +else +{ + public import std.utf : toUTF8; +} + +struct QString +{ + public static QString opCall() + { + QString str; + qtd_QString_placed_ctor(&str); + return str; + } + + ~this() + { + qtd_QString_call_destructor(&this); + } + + void opAssign(string str) + { + qtd_QString_assign_fromUtf8(&this, str); + } + + this(string str) + { + qtd_QString_new_fromUtf8_at(&this, str); + } + + public static void __constructPlacedQString(void* place, string source) { + qtd_QString_new_fromUtf8_at(place, source); + } + + // service stuff + static void* __constructNativeCopy(const void* orig) { + return qtd_QString_QString_QString(cast(void*)orig); + } + + static void* __constructPlacedNativeCopy(const void* orig, void* place) { + return qtd_QString_placed_copy(orig, place); + } + + public static void __deleteNativeObject(void* ptr) { + qtd_QString_destructor(ptr); + } + + public static void __callNativeDestructor(void* ptr) { + qtd_QString_call_destructor(ptr); + } + struct QTypeInfo + { + enum bool isComplex = true; + enum bool isStatic = false; + enum bool isLarge = false; + enum bool isPointer = false; + enum bool isDummy = false; + } + +private: + void *dummy; // sizeof(QString) == sizeof(void*) +} + +struct QStringUtil +{ + public static final string toNativeString(void* qstring) { + wchar* arr = qtd_QString_utf16(qstring); + int size = qtd_QString_size(qstring); + return .toUTF8(arr[0..size]); + } + + public static string fromUtf8(string source) { + return source; + } + + public static QStringUtil opCall(void* ptr, bool proxy) { + QStringUtil str; + str.__nativeId = ptr; + return str; + } + + public void* __nativeId; + + public final string toNativeString() { + return QStringUtil.toNativeString(__nativeId); + } + + public void assign(string text) { + qtd_QString_operatorAssign(__nativeId, text); + } +} +private extern(C) void* qtd_QString_placed_copy(const void* orig, void* place); + +private extern (C) void qtd_QString_destructor(void* __this_nativeId); +private extern (C) void qtd_QString_call_destructor(void *ptr); + +private extern (C) void* qtd_QString_QString_QString(void* orig); + +private extern (C) wchar* qtd_QString_utf16(void* __this_nativeId); +private extern (C) int qtd_QString_size(void* __this_nativeId); +private extern (C) void qtd_QString_operatorAssign(void* __this_nativeId, string text); +private extern (C) void* qtd_QString_new_fromUtf8_at(void* place, string text); + +private extern (C) void qtd_QString_placed_ctor(void* place); +private extern (C) void qtd_QString_assign_fromUtf8(QString *__qt_this, string text); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/core/QTypeInfo.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/core/QTypeInfo.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,139 @@ +module qt.core.QTypeInfo; + +//import qt.QGlobal; +//import qtd.Atomic; + +/* + The catch-all template. +*/ +import std.traits; + +import qtd.MetaMarshall; +import qt.core.QString; + +bool qIsDetached(T)(ref T) { return true; } + +template isBasicType(T) +{ + enum isBasicType = isNumeric!T || is(T == bool) || is(T == enum); +} + +template QTypeInfo(T) +{ + static if(is(T == string)) + { + alias QString.QTypeInfo QTypeInfo; + } + else static if(isBasicType!T) + { + public enum + { + isPointer = false, + isComplex = false, + isStatic = false, + isLarge = (T.sizeof > (void*).sizeof), + isDummy = false + } + } + else static if(is(T.QTypeInfo)) + { + alias T.QTypeInfo QTypeInfo; // alias member QTypeInfo + } + else static if ( isQObjectType!T || isObjectType!T ) + { + public enum // are pointers + { + isPointer = true, + isComplex = false, + isStatic = false, + isLarge = false, + isDummy = false + } + } + else // default parameters + { + public enum + { + isPointer = isPointer!T, + isComplex = !isPointer, + isStatic = !isPointer, + isLarge = (T.sizeof > (void*).sizeof), + isDummy = false + } + } +} + + +/* + Specialize a specific type with: + + Q_DECLARE_TYPEINFO(type, flags); + + where 'type' is the name of the type to specialize and 'flags' is + logically-OR'ed combination of the flags below. +*/ + +/* presents in QGlobal +enum { /* TYPEINFO flags + Q_COMPLEX_TYPE = 0, + Q_PRIMITIVE_TYPE = 0x1, + Q_STATIC_TYPE = 0, + Q_MOVABLE_TYPE = 0x2, + Q_DUMMY_TYPE = 0x4 +} +*/ + +/* +template QTypeInfo(alias FLAGS) +{ + template QTypeInfo(TYPE) + { + public: + enum { + isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0), + isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), + isLarge = (TYPE.sizeof > (void*).sizeof), + isPointer = false, + isDummy = (((FLAGS) & Q_DUMMY_TYPE) != 0) + } + } +} +*/ +/* + Specialize a shared type with: + + Q_DECLARE_SHARED(type); + + where 'type' is the name of the type to specialize. NOTE: shared + types must declare a 'bool isDetached(void) const;' member for this + to work. +*/ +/* +#if defined Q_CC_MSVC && _MSC_VER < 1300 +template +inline void qSwap_helper(T &value1, T &value2, T*) +{ + T t = value1; + value1 = value2; + value2 = t; +} +#define Q_DECLARE_SHARED(TYPE) \ +template <> inline bool qIsDetached(TYPE &t) { return t.isDetached(); } \ +template <> inline void qSwap_helper(TYPE &value1, TYPE &value2, TYPE*) \ +{ \ + const TYPE::DataPtr t = value1.data_ptr(); \ + value1.data_ptr() = value2.data_ptr(); \ + value2.data_ptr() = t; \ +} +#else +#define Q_DECLARE_SHARED(TYPE) \ +template <> inline bool qIsDetached(TYPE &t) { return t.isDetached(); } \ +template inline void qSwap(T &, T &); \ +template <> inline void qSwap(TYPE &value1, TYPE &value2) \ +{ \ + const TYPE::DataPtr t = value1.data_ptr(); \ + value1.data_ptr() = value2.data_ptr(); \ + value2.data_ptr() = t; \ +} +#endif +*/ diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/core/QVariant.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/core/QVariant.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,741 @@ +module qt.core.QVariant; + +public import qt.QGlobal; +private import qtd.QtdObject; +private import qt.core.QMetaType; + +// automatic imports------------- +private import qt.core.QSizeF; +private import qt.core.QPoint; +private import qt.core.QRectF; +public import qt.core.Qt; +private import qt.core.QDateTime; +private import qt.core.QDataStream; +private import qt.core.QTime; +private import qt.core.QUrl; +private import qt.core.QRegExp; +private import qt.core.QBitArray; +private import qt.core.QLine; +private import qt.core.QByteArray; +private import qt.core.QSize; +private import qt.core.QDate; +private import qt.core.QPointF; +private import qt.core.QLineF; +private import qt.core.QRect; +private import qt.core.QLocale; + +import std.string; + + +public class QVariant : QtdObject +{ + enum Type { + Invalid = 0, + + Bool = 1, + Int = 2, + UInt = 3, + LongLong = 4, + ULongLong = 5, + Double = 6, + Char = 7, + Map = 8, + List = 9, + String = 10, + StringList = 11, + ByteArray = 12, + BitArray = 13, + Date = 14, + Time = 15, + DateTime = 16, + Url = 17, + Locale = 18, + Rect = 19, + RectF = 20, + Size = 21, + SizeF = 22, + Line = 23, + LineF = 24, + Point = 25, + PointF = 26, + RegExp = 27, + LastCoreType = RegExp, + + // value 62 is internally reserved + + Font = 64, + Pixmap = 65, + Brush = 66, + Color = 67, + Palette = 68, + Icon = 69, + Image = 70, + Polygon = 71, + Region = 72, + Bitmap = 73, + Cursor = 74, + SizePolicy = 75, + KeySequence = 76, + Pen = 77, + TextLength = 78, + TextFormat = 79, + Matrix = 80, + Transform = 81, + LastGuiType = Transform, + + UserType = 127, + + LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type + } + +// Functions + + private template getMetaId() + { + const char[] getMetaId = " + int i = qtd_MetatypeId(toStringz(name)); + if(i <= 0) + i = qRegisterMetaType!(T)(name);"; + } + + static public QVariant fromValue(T)(T obj) + { + QVariant var; + static if (is(T == class) || is(T == interface)) + { + string name = obj.classinfo.name; + mixin(getMetaId!()); + var = new QVariant(i, cast(void*)(obj)); + } + else static if (isDynamicArrayType!(T) || isStaticArrayType!(T) ) + { + string name = typeid(ElementTypeOfArray!(T)).toString ~ "[]"; + mixin(getMetaId!()); + auto darray = new DArrayToC; + darray.array = obj.dup; + var = new QVariant(i, cast(void*)(darray)); + } + else + { + string name = typeid(T).toString; + mixin(getMetaId!()); + auto data = new T; + *data = obj; + var = new QVariant(i, cast(void*)(data)); + } + return var; + } + + static public QVariant opCall(T)(T obj) + { + return fromValue(obj); + } + + public this() { + void* __qt_return_value = qtd_QVariant_QVariant(); + super(__qt_return_value); + } + + + public this(QDataStream s) { + void* __qt_return_value = qtd_QVariant_QVariant_QDataStream(s is null ? null : s.__nativeId); + super(__qt_return_value); + } + + + public this(Qt.GlobalColor color) { + void* __qt_return_value = qtd_QVariant_QVariant_GlobalColor(color); + super(__qt_return_value); + } + + + public this(bool b) { + void* __qt_return_value = qtd_QVariant_QVariant_bool(b); + super(__qt_return_value); + } + + + public this(QBitArray bitarray) { + void* __qt_return_value = qtd_QVariant_QVariant_QBitArray(bitarray is null ? null : bitarray.__nativeId); + super(__qt_return_value); + } + + + public this(QByteArray bytearray) { + void* __qt_return_value = qtd_QVariant_QVariant_QByteArray(bytearray is null ? null : bytearray.__nativeId); + super(__qt_return_value); + } + + + public this(QDate date) { + void* __qt_return_value = qtd_QVariant_QVariant_QDate(date is null ? null : date.__nativeId); + super(__qt_return_value); + } + + + public this(QDateTime datetime) { + void* __qt_return_value = qtd_QVariant_QVariant_QDateTime(datetime is null ? null : datetime.__nativeId); + super(__qt_return_value); + } + + + public this(string str) { + void* __qt_return_value = qtd_QVariant_QVariant_String(str); + super(__qt_return_value); + } + + + public this(QLine line) { + void* __qt_return_value = qtd_QVariant_QVariant_QLine(&line); + super(__qt_return_value); + } + + + public this(QLineF line) { + void* __qt_return_value = qtd_QVariant_QVariant_QLineF(&line); + super(__qt_return_value); + } + + + public this(QLocale locale) { + void* __qt_return_value = qtd_QVariant_QVariant_QLocale(locale is null ? null : locale.__nativeId); + super(__qt_return_value); + } + + + public this(QPoint pt) { + void* __qt_return_value = qtd_QVariant_QVariant_QPoint(&pt); + super(__qt_return_value); + } + + + public this(QPointF pt) { + void* __qt_return_value = qtd_QVariant_QVariant_QPointF(&pt); + super(__qt_return_value); + } + + + public this(QRect rect) { + void* __qt_return_value = qtd_QVariant_QVariant_QRect(&rect); + super(__qt_return_value); + } + + + public this(QRectF rect) { + void* __qt_return_value = qtd_QVariant_QVariant_QRectF(&rect); + super(__qt_return_value); + } + + + public this(QRegExp regExp) { + void* __qt_return_value = qtd_QVariant_QVariant_QRegExp(regExp is null ? null : regExp.__nativeId); + super(__qt_return_value); + } + + + public this(QSize size) { + void* __qt_return_value = qtd_QVariant_QVariant_QSize(&size); + super(__qt_return_value); + } + + + public this(QSizeF size) { + void* __qt_return_value = qtd_QVariant_QVariant_QSizeF(&size); + super(__qt_return_value); + } + + + public this(QTime time) { + void* __qt_return_value = qtd_QVariant_QVariant_QTime(time is null ? null : time.__nativeId); + super(__qt_return_value); + } + + + public this(QUrl url) { + void* __qt_return_value = qtd_QVariant_QVariant_QUrl(url is null ? null : url.__nativeId); + super(__qt_return_value); + } + + + public this(QVariant other) { + void* __qt_return_value = qtd_QVariant_QVariant_QVariant(other is null ? null : other.__nativeId); + super(__qt_return_value); + } + +/* + public this(char* str) { + void* __qt_return_value = qtd_QVariant_QVariant_nativepointerchar(str); + super(__qt_return_value); + } +*/ + + public this(double d) { + void* __qt_return_value = qtd_QVariant_QVariant_double(d); + super(__qt_return_value); + } + + + public this(int i) { + void* __qt_return_value = qtd_QVariant_QVariant_int(i); + super(__qt_return_value); + } + + + public this(int typeOrUserType, void* copy) { + void* __qt_return_value = qtd_QVariant_QVariant_int_nativepointervoid(typeOrUserType, copy); + super(__qt_return_value); + } + + + public this(long ll) { + void* __qt_return_value = qtd_QVariant_QVariant_long(ll); + super(__qt_return_value); + } + + + public this(uint ui) { + void* __qt_return_value = qtd_QVariant_QVariant_uint(ui); + super(__qt_return_value); + } + + + public this(ulong ull) { + void* __qt_return_value = qtd_QVariant_QVariant_ulong(ull); + super(__qt_return_value); + } + + private final bool canConvertImpl(string name) + { + int i = qtd_MetatypeId(toStringz(name)); + assert(i > 0); + return qtd_QVariant_canConvert(__nativeId, i); + } + + public final bool canConvert(Type)() { + static if ( is(Type == QBitArray) ) + return canConvertImpl("QBitArray"); + else static if ( is(Type == bool) ) + return canConvertImpl("bool"); + else static if ( is(Type == QByteArray) ) + return canConvertImpl("QByteArray"); + else static if ( is(Type == QDate) ) + return canConvertImpl("QDate"); + else static if ( is(Type == QDateTime) ) + return canConvertImpl("QDateTime"); + else static if ( is(Type == double) ) + return canConvertImpl("double"); + else static if ( is(Type == int) ) + return canConvertImpl("int"); + else static if ( is(Type == QLine) ) + return canConvertImpl("QLine"); + else static if ( is(Type == QLineF) ) + return canConvertImpl("QLineF"); + else static if ( is(Type == QLocale) ) + return canConvertImpl("QLocale"); + else static if ( is(Type == long) ) + return canConvertImpl("long"); + else static if ( is(Type == QPoint) ) + return canConvertImpl("QPoint"); + else static if ( is(Type == QPointF) ) + return canConvertImpl("QPointF"); + else static if ( is(Type == QRect) ) + return canConvertImpl("QRect"); + else static if ( is(Type == QRectF) ) + return canConvertImpl("QRectF"); + else static if ( is(Type == QRegExp) ) + return canConvertImpl("QRegExp"); + else static if ( is(Type == QSize) ) + return canConvertImpl("QSize"); + else static if ( is(Type == QSizeF) ) + return canConvertImpl("QSizeF"); + else static if ( is(Type == string) ) + return canConvertImpl("QString"); + else static if ( is(Type == QTime) ) + return canConvertImpl("QTime"); + else static if ( is(Type == uint) ) + return canConvertImpl("unsigned int"); // TODO: + else static if ( is(Type == ulong) ) + return canConvertImpl("unsigned long long"); // TODO: + else static if ( is(Type == QUrl) ) + return canConvertImpl("QUrl"); + else + { + static if( is( Type == class ) || is( Type == interface ) ) + { + Object object = cast(Object)qtd_QVariant_data(__nativeId); + if(object) + return cast(Type)(object) !is null; + return false; + } + else static if (isDynamicArrayType!(Type) || isStaticArrayType!(Type) ) + { + auto array = cast(DArrayToC*)qtd_QVariant_data(__nativeId); + return cast(Type)(array.array) !is null; + } + else + { + int i = qtd_MetatypeId(toStringz(typeid(Type).toString)); + return qtd_QVariant_canConvert(__nativeId, i); + } + } + } + + public final Type value(Type)() { + static if ( is(Type == QBitArray) ) + return toBitArra; + else static if ( is(Type == bool) ) + return toBool; + else static if ( is(Type == QByteArray) ) + return toByteArray; + else static if ( is(Type == QDate) ) + return toDate; + else static if ( is(Type == QDateTime) ) + return toDateTime; + else static if ( is(Type == double) ) + return toDouble; + else static if ( is(Type == int) ) + return toInt; + else static if ( is(Type == QLine) ) + return toLine; + else static if ( is(Type == QLineF) ) + return toLineF; + else static if ( is(Type == QLocale) ) + return toLocale; + else static if ( is(Type == long) ) + return toLongLong; + else static if ( is(Type == QPoint) ) + return toPoint; + else static if ( is(Type == QPointF) ) + return toPointF; + else static if ( is(Type == QRect) ) + return toRect; + else static if ( is(Type == QRectF) ) + return toRectF; + else static if ( is(Type == QRegExp) ) + return toRegExp; + else static if ( is(Type == QSize) ) + return toSize; + else static if ( is(Type == QSizeF) ) + return toSizeF; + else static if ( is(Type == string) ) + return toString; + else static if ( is(Type == QTime) ) + return toTime; + else static if ( is(Type == uint) ) + return toUInt; + else static if ( is(Type == ulong) ) + return toULongLong; + else static if ( is(Type == QUrl) ) + return toUrl; + else static if( is( Type == class ) || is( Type == interface ) ) + { + Object object = cast(Object)qtd_QVariant_data(__nativeId); + if(object) + return cast(Type)(object); + return null; + } + else static if (isDynamicArrayType!(Type) || isStaticArrayType!(Type) ) + { + auto array = cast(DArrayToC*)qtd_QVariant_data(__nativeId); + return cast(Type)(array.array); + } + else + { + return *cast(Type*)qtd_QVariant_data(__nativeId); + } + } + + public final void clear() { + qtd_QVariant_clear(__nativeId); + } + + protected final bool cmp(QVariant other) { + return qtd_QVariant_cmp_QVariant(__nativeId, other is null ? null : other.__nativeId); + } + + protected final void create(int type, void* copy) { + qtd_QVariant_create_int_nativepointervoid(__nativeId, type, copy); + } + + public final bool isNull() { + return qtd_QVariant_isNull(__nativeId); + } + + public final bool isValid() { + return qtd_QVariant_isValid(__nativeId); + } + + public final void load(QDataStream ds) { + qtd_QVariant_load_QDataStream(__nativeId, ds is null ? null : ds.__nativeId); + } + + public final void writeTo(QDataStream s) { + qtd_QVariant_writeTo_QDataStream(__nativeId, s is null ? null : s.__nativeId); + } + + public final QVariant operator_assign(QVariant other) { + void* __qt_return_value = qtd_QVariant_operator_assign_QVariant(__nativeId, other is null ? null : other.__nativeId); + return new QVariant(__qt_return_value, QtdObjectFlags.nativeOwnership); + } + + private final bool operator_equal(QVariant v) { + return qtd_QVariant_operator_equal_QVariant(__nativeId, v is null ? null : v.__nativeId); + } + + public final void readFrom(QDataStream s) { + qtd_QVariant_readFrom_QDataStream(__nativeId, s is null ? null : s.__nativeId); + } + + public final void save(QDataStream ds) { + qtd_QVariant_save_QDataStream(__nativeId, ds is null ? null : ds.__nativeId); + } + + public final QBitArray toBitArray() { + void* __qt_return_value = qtd_QVariant_toBitArray(__nativeId); + return new QBitArray(__qt_return_value); + } + + public final bool toBool() { + return qtd_QVariant_toBool(__nativeId); + } + + public final QByteArray toByteArray() { + void* __qt_return_value = qtd_QVariant_toByteArray(__nativeId); + return new QByteArray(__qt_return_value); + } + + public final QDate toDate() { + void* __qt_return_value = qtd_QVariant_toDate(__nativeId); + return new QDate(__qt_return_value); + } + + public final QDateTime toDateTime() { + void* __qt_return_value = qtd_QVariant_toDateTime(__nativeId); + return new QDateTime(__qt_return_value); + } + + public final double toDouble(bool* ok = null) { + return qtd_QVariant_toDouble_nativepointerbool(__nativeId, ok); + } + + public final int toInt(bool* ok = null) { + return qtd_QVariant_toInt_nativepointerbool(__nativeId, ok); + } + + public final QLine toLine() { + return qtd_QVariant_toLine(__nativeId); + } + + public final QLineF toLineF() { + return qtd_QVariant_toLineF(__nativeId); + } + + public final QLocale toLocale() { + void* __qt_return_value = qtd_QVariant_toLocale(__nativeId); + return new QLocale(__qt_return_value); + } + + public final long toLongLong(bool* ok = null) { + return qtd_QVariant_toLongLong_nativepointerbool(__nativeId, ok); + } + + public final QPoint toPoint() { + return qtd_QVariant_toPoint(__nativeId); + } + + public final QPointF toPointF() { + return qtd_QVariant_toPointF(__nativeId); + } + + public final QRect toRect() { + return qtd_QVariant_toRect(__nativeId); + } + + public final QRectF toRectF() { + return qtd_QVariant_toRectF(__nativeId); + } + + public final QRegExp toRegExp() { + void* __qt_return_value = qtd_QVariant_toRegExp(__nativeId); + return new QRegExp(__qt_return_value); + } + + public final QSize toSize() { + return qtd_QVariant_toSize(__nativeId); + } + + public final QSizeF toSizeF() { + return qtd_QVariant_toSizeF(__nativeId); + } + + public final string toString() { + string res; + qtd_QVariant_toString(__nativeId, &res); + return res; + } + + public final QTime toTime() { + void* __qt_return_value = qtd_QVariant_toTime(__nativeId); + return new QTime(__qt_return_value); + } + + public final uint toUInt(bool* ok = null) { + return qtd_QVariant_toUInt_nativepointerbool(__nativeId, ok); + } + + public final ulong toULongLong(bool* ok = null) { + return qtd_QVariant_toULongLong_nativepointerbool(__nativeId, ok); + } + + public final QUrl toUrl() { + void* __qt_return_value = qtd_QVariant_toUrl(__nativeId); + return new QUrl(__qt_return_value); + } + + public final char* typeName() { + return qtd_QVariant_typeName(__nativeId); + } + + public final Type type() { + return cast(Type)qtd_QVariant_type(__nativeId); + } + + public final int userType() { + return qtd_QVariant_userType(__nativeId); + } +// Field accessors + + public this(void* native_id, QtdObjectFlags flags = QtdObjectFlags.none) { + super(native_id, flags); + } + + protected override void __deleteNative() { + qtd_QVariant_destructor(__nativeId); + } + + public alias void __isValueType; + + public alias void __isQtType_QVariant; + + struct QTypeInfo + { + enum bool isComplex = true; + enum bool isStatic = false; + enum bool isLarge = true; + enum bool isPointer = false; + enum bool isDummy = false; + } + + static void* __constructNativeCopy(const void* orig) { + return qtd_QVariant_QVariant_QVariant(cast(void*)orig); + } + + static void* __constructPlacedNativeCopy(const void* orig, void* place) { + return qtd_QVariant_placed_copy(orig, place); + } + + public static void __deleteNativeObject(void* ptr) { + qtd_QVariant_destructor(ptr); + } + + public static void __callNativeDestructor(void* ptr) { + qtd_QVariant_call_destructor(ptr); + } +// Injected code in class +} + +extern (C) void qtd_QVariant_destructor(void *ptr); +extern (C) void qtd_QVariant_call_destructor(void *ptr); + +private extern(C) void* qtd_QVariant_placed_copy(const void* orig, void* place); + + +// C wrappers +private extern(C) void* qtd_QVariant_QVariant(); +private extern(C) void* qtd_QVariant_QVariant_QDataStream(void* s0); +private extern(C) void* qtd_QVariant_QVariant_GlobalColor(int color0); +private extern(C) void* qtd_QVariant_QVariant_bool(bool b0); +private extern(C) void* qtd_QVariant_QVariant_QBitArray(void* bitarray0); +private extern(C) void* qtd_QVariant_QVariant_QByteArray(void* bytearray0); +private extern(C) void* qtd_QVariant_QVariant_QDate(void* date0); +private extern(C) void* qtd_QVariant_QVariant_QDateTime(void* datetime0); +private extern(C) void* qtd_QVariant_QVariant_String(string string0); +private extern(C) void* qtd_QVariant_QVariant_QLine(void* line0); +private extern(C) void* qtd_QVariant_QVariant_QLineF(void* line0); +private extern(C) void* qtd_QVariant_QVariant_QLocale(void* locale0); +private extern(C) void* qtd_QVariant_QVariant_QPoint(void* pt0); +private extern(C) void* qtd_QVariant_QVariant_QPointF(void* pt0); +private extern(C) void* qtd_QVariant_QVariant_QRect(void* rect0); +private extern(C) void* qtd_QVariant_QVariant_QRectF(void* rect0); +private extern(C) void* qtd_QVariant_QVariant_QRegExp(void* regExp0); +private extern(C) void* qtd_QVariant_QVariant_QSize(void* size0); +private extern(C) void* qtd_QVariant_QVariant_QSizeF(void* size0); +private extern(C) void* qtd_QVariant_QVariant_QTime(void* time0); +private extern(C) void* qtd_QVariant_QVariant_QUrl(void* url0); +private extern(C) void* qtd_QVariant_QVariant_QVariant(void* other0); +private extern(C) void* qtd_QVariant_QVariant_nativepointerchar(char* str0); +private extern(C) void* qtd_QVariant_QVariant_double(double d0); +private extern(C) void* qtd_QVariant_QVariant_int(int i0); +private extern(C) void* qtd_QVariant_QVariant_int_nativepointervoid(int typeOrUserType0, + void* copy1); +private extern(C) void* qtd_QVariant_QVariant_long(long ll0); +private extern(C) void* qtd_QVariant_QVariant_uint(uint ui0); +private extern(C) void* qtd_QVariant_QVariant_ulong(ulong ull0); +private extern(C) bool qtd_QVariant_canConvert(void* __this_nativeId, int); +private extern(C) void qtd_QVariant_clear(void* __this_nativeId); +private extern(C) bool qtd_QVariant_cmp_QVariant(void* __this_nativeId, + void* other0); +private extern(C) void qtd_QVariant_create_int_nativepointervoid(void* __this_nativeId, + int type0, + void* copy1); +private extern(C) bool qtd_QVariant_isNull(void* __this_nativeId); +private extern(C) bool qtd_QVariant_isValid(void* __this_nativeId); +private extern(C) void qtd_QVariant_load_QDataStream(void* __this_nativeId, + void* ds0); +private extern(C) void qtd_QVariant_writeTo_QDataStream(void* __this_nativeId, + void* s0); +private extern(C) void* qtd_QVariant_operator_assign_QVariant(void* __this_nativeId, + void* other0); +private extern(C) bool qtd_QVariant_operator_equal_QVariant(void* __this_nativeId, + void* v0); +private extern(C) void qtd_QVariant_readFrom_QDataStream(void* __this_nativeId, + void* s0); +private extern(C) void qtd_QVariant_save_QDataStream(void* __this_nativeId, + void* ds0); +private extern(C) void* qtd_QVariant_toBitArray(void* __this_nativeId); +private extern(C) bool qtd_QVariant_toBool(void* __this_nativeId); +private extern(C) void* qtd_QVariant_toByteArray(void* __this_nativeId); +private extern(C) void* qtd_QVariant_toDate(void* __this_nativeId); +private extern(C) void* qtd_QVariant_toDateTime(void* __this_nativeId); +private extern(C) double qtd_QVariant_toDouble_nativepointerbool(void* __this_nativeId, + bool* ok0); +private extern(C) int qtd_QVariant_toInt_nativepointerbool(void* __this_nativeId, + bool* ok0); +private extern(C) QLine qtd_QVariant_toLine(void* __this_nativeId); +private extern(C) QLineF qtd_QVariant_toLineF(void* __this_nativeId); +private extern(C) void* qtd_QVariant_toLocale(void* __this_nativeId); +private extern(C) long qtd_QVariant_toLongLong_nativepointerbool(void* __this_nativeId, + bool* ok0); +private extern(C) QPoint qtd_QVariant_toPoint(void* __this_nativeId); +private extern(C) QPointF qtd_QVariant_toPointF(void* __this_nativeId); +private extern(C) QRect qtd_QVariant_toRect(void* __this_nativeId); +private extern(C) QRectF qtd_QVariant_toRectF(void* __this_nativeId); +private extern(C) void* qtd_QVariant_toRegExp(void* __this_nativeId); +private extern(C) QSize qtd_QVariant_toSize(void* __this_nativeId); +private extern(C) QSizeF qtd_QVariant_toSizeF(void* __this_nativeId); +private extern(C) void qtd_QVariant_toString(void* __this_nativeId, + void* __java_return_value); +private extern(C) void* qtd_QVariant_toTime(void* __this_nativeId); +private extern(C) uint qtd_QVariant_toUInt_nativepointerbool(void* __this_nativeId, + bool* ok0); +private extern(C) ulong qtd_QVariant_toULongLong_nativepointerbool(void* __this_nativeId, + bool* ok0); +private extern(C) void* qtd_QVariant_toUrl(void* __this_nativeId); +private extern(C) char* qtd_QVariant_typeName(void* __this_nativeId); +private extern(C) int qtd_QVariant_type(void* __this_nativeId); +private extern(C) int qtd_QVariant_userType(void* __this_nativeId); +private extern(C) void *qtd_QVariant_data(void* __this_nativeId); + +// Just the private functions for abstract functions implemeneted in superclasses + +// Virtual Dispatch functions diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/opengl/gl.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/opengl/gl.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,7 @@ +module qt.opengl.gl; + +public +{ + import qt.opengl.gltypes; + import qt.opengl.glfuncs; +} diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/opengl/glfuncs.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/opengl/glfuncs.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,375 @@ +module qt.opengl.glfuncs; + +private import qt.opengl.gltypes; + +/* +extern (C) +{ + void glEnable(GLenum); + void glEnableClientState(GLenum); + void glDisableClientState(GLenum); + void glClear(GLbitfield); + void glLoadIdentity(); + void glBegin(GLenum); + void glColor3f(GLfloat,GLfloat,GLfloat); + void glVertex3f(GLfloat,GLfloat,GLfloat); + void glEnd(); + void glViewport(GLint,GLint,GLsizei,GLsizei); + void glMatrixMode(GLenum); + void glGetDoublev(GLenum,GLdouble*); + void glGetFloatv(GLenum,GLfloat*); + void glGetIntegerv(GLenum,GLint*); + void glScalef(GLfloat,GLfloat,GLfloat); + void glDeleteLists(GLuint, GLsizei); + void glShadeModel(GLenum); + void glTranslated(GLdouble, GLdouble, GLdouble); + void glTranslatef(GLfloat, GLfloat, GLfloat); + void glRotated(GLdouble, GLdouble, GLdouble, GLdouble); + void glCallList(GLuint); + void glOrtho (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); + GLuint glGenLists (GLsizei range); +} +alias ptrdiff_t GLintptrARB; +alias ptrdiff_t GLsizeiptrARB; + +*/ + +extern (System) +{ + void glAccum (GLenum op, GLfloat value); + void glAlphaFunc (GLenum func, GLclampf ref_); + GLboolean glAreTexturesResident (GLsizei n, GLuint *textures, GLboolean *residences); + void glArrayElement (GLint i); + void glBegin (GLenum mode); + void glBindTexture (GLenum target, GLuint texture); + void glBitmap (GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, GLubyte *bitmap); + void glBlendFunc (GLenum sfactor, GLenum dfactor); + void glCallList (GLuint list); + void glCallLists (GLsizei n, GLenum type, GLvoid *lists); + void glClear (GLbitfield mask); + void glClearAccum (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); + void glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); + void glClearDepth (GLclampd depth); + void glClearIndex (GLfloat c); + void glClearStencil (GLint s); + void glClipPlane (GLenum plane, GLdouble *equation); + void glColor3b (GLbyte red, GLbyte green, GLbyte blue); + void glColor3bv (GLbyte *v); + void glColor3d (GLdouble red, GLdouble green, GLdouble blue); + void glColor3dv (GLdouble *v); + void glColor3f (GLfloat red, GLfloat green, GLfloat blue); + void glColor3fv (GLfloat *v); + void glColor3i (GLint red, GLint green, GLint blue); + void glColor3iv (GLint *v); + void glColor3s (GLshort red, GLshort green, GLshort blue); + void glColor3sv (GLshort *v); + void glColor3ub (GLubyte red, GLubyte green, GLubyte blue); + void glColor3ubv (GLubyte *v); + void glColor3ui (GLuint red, GLuint green, GLuint blue); + void glColor3uiv (GLuint *v); + void glColor3us (GLushort red, GLushort green, GLushort blue); + void glColor3usv (GLushort *v); + void glColor4b (GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha); + void glColor4bv (GLbyte *v); + void glColor4d (GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha); + void glColor4dv (GLdouble *v); + void glColor4f (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); + void glColor4fv (GLfloat *v); + void glColor4i (GLint red, GLint green, GLint blue, GLint alpha); + void glColor4iv (GLint *v); + void glColor4s (GLshort red, GLshort green, GLshort blue, GLshort alpha); + void glColor4sv (GLshort *v); + void glColor4ub (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); + void glColor4ubv (GLubyte *v); + void glColor4ui (GLuint red, GLuint green, GLuint blue, GLuint alpha); + void glColor4uiv (GLuint *v); + void glColor4us (GLushort red, GLushort green, GLushort blue, GLushort alpha); + void glColor4usv (GLushort *v); + void glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); + void glColorMaterial (GLenum face, GLenum mode); + void glColorPointer (GLint size, GLenum type, GLsizei stride, GLvoid *pointer); + void glCopyPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum type); + void glCopyTexImage1D (GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border); + void glCopyTexImage2D (GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); + void glCopyTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); + void glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); + void glCullFace (GLenum mode); + void glDeleteLists (GLuint list, GLsizei range); + void glDeleteTextures (GLsizei n, GLuint *textures); + void glDepthFunc (GLenum func); + void glDepthMask (GLboolean flag); + void glDepthRange (GLclampd zNear, GLclampd zFar); + void glDisable (GLenum cap); + void glDisableClientState (GLenum array); + void glDrawArrays (GLenum mode, GLint first, GLsizei count); + void glDrawBuffer (GLenum mode); + void glDrawElements (GLenum mode, GLsizei count, GLenum type, GLvoid *indices); + void glDrawPixels (GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); + void glEdgeFlag (GLboolean flag); + void glEdgeFlagPointer (GLsizei stride, GLvoid *pointer); + void glEdgeFlagv (GLboolean *flag); + void glEnable (GLenum cap); + void glEnableClientState (GLenum array); + void glEnd (); + void glEndList (); + void glEvalCoord1d (GLdouble u); + void glEvalCoord1dv (GLdouble *u); + void glEvalCoord1f (GLfloat u); + void glEvalCoord1fv (GLfloat *u); + void glEvalCoord2d (GLdouble u, GLdouble v); + void glEvalCoord2dv (GLdouble *u); + void glEvalCoord2f (GLfloat u, GLfloat v); + void glEvalCoord2fv (GLfloat *u); + void glEvalMesh1 (GLenum mode, GLint i1, GLint i2); + void glEvalMesh2 (GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2); + void glEvalPoint1 (GLint i); + void glEvalPoint2 (GLint i, GLint j); + void glFeedbackBuffer (GLsizei size, GLenum type, GLfloat *buffer); + void glFinish (); + void glFlush (); + void glFogf (GLenum pname, GLfloat param); + void glFogfv (GLenum pname, GLfloat *params); + void glFogi (GLenum pname, GLint param); + void glFogiv (GLenum pname, GLint *params); + void glFrontFace (GLenum mode); + void glFrustum (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); + GLuint glGenLists (GLsizei range); + void glGenTextures (GLsizei n, GLuint *textures); + void glGetBooleanv (GLenum pname, GLboolean *params); + void glGetClipPlane (GLenum plane, GLdouble *equation); + void glGetDoublev (GLenum pname, GLdouble *params); + GLenum glGetError (); + void glGetFloatv (GLenum pname, GLfloat *params); + void glGetIntegerv (GLenum pname, GLint *params); + void glGetLightfv (GLenum light, GLenum pname, GLfloat *params); + void glGetLightiv (GLenum light, GLenum pname, GLint *params); + void glGetMapdv (GLenum target, GLenum query, GLdouble *v); + void glGetMapfv (GLenum target, GLenum query, GLfloat *v); + void glGetMapiv (GLenum target, GLenum query, GLint *v); + void glGetMaterialfv (GLenum face, GLenum pname, GLfloat *params); + void glGetMaterialiv (GLenum face, GLenum pname, GLint *params); + void glGetPixelMapfv (GLenum map, GLfloat *values); + void glGetPixelMapuiv (GLenum map, GLuint *values); + void glGetPixelMapusv (GLenum map, GLushort *values); + void glGetPointerv (GLenum pname, GLvoid* *params); + void glGetPolygonStipple (GLubyte *mask); + GLubyte * glGetString (GLenum name); + void glGetTexEnvfv (GLenum target, GLenum pname, GLfloat *params); + void glGetTexEnviv (GLenum target, GLenum pname, GLint *params); + void glGetTexGendv (GLenum coord, GLenum pname, GLdouble *params); + void glGetTexGenfv (GLenum coord, GLenum pname, GLfloat *params); + void glGetTexGeniv (GLenum coord, GLenum pname, GLint *params); + void glGetTexImage (GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); + void glGetTexLevelParameterfv (GLenum target, GLint level, GLenum pname, GLfloat *params); + void glGetTexLevelParameteriv (GLenum target, GLint level, GLenum pname, GLint *params); + void glGetTexParameterfv (GLenum target, GLenum pname, GLfloat *params); + void glGetTexParameteriv (GLenum target, GLenum pname, GLint *params); + void glHint (GLenum target, GLenum mode); + void glIndexMask (GLuint mask); + void glIndexPointer (GLenum type, GLsizei stride, GLvoid *pointer); + void glIndexd (GLdouble c); + void glIndexdv (GLdouble *c); + void glIndexf (GLfloat c); + void glIndexfv (GLfloat *c); + void glIndexi (GLint c); + void glIndexiv (GLint *c); + void glIndexs (GLshort c); + void glIndexsv (GLshort *c); + void glIndexub (GLubyte c); + void glIndexubv (GLubyte *c); + void glInitNames (); + void glInterleavedArrays (GLenum format, GLsizei stride, GLvoid *pointer); + GLboolean glIsEnabled (GLenum cap); + GLboolean glIsList (GLuint list); + GLboolean glIsTexture (GLuint texture); + void glLightModelf (GLenum pname, GLfloat param); + void glLightModelfv (GLenum pname, GLfloat *params); + void glLightModeli (GLenum pname, GLint param); + void glLightModeliv (GLenum pname, GLint *params); + void glLightf (GLenum light, GLenum pname, GLfloat param); + void glLightfv (GLenum light, GLenum pname, GLfloat *params); + void glLighti (GLenum light, GLenum pname, GLint param); + void glLightiv (GLenum light, GLenum pname, GLint *params); + void glLineStipple (GLint factor, GLushort pattern); + void glLineWidth (GLfloat width); + void glListBase (GLuint base); + void glLoadIdentity (); + void glLoadMatrixd (GLdouble *m); + void glLoadMatrixf (GLfloat *m); + void glLoadName (GLuint name); + void glLogicOp (GLenum opcode); + void glMap1d (GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, GLdouble *points); + void glMap1f (GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, GLfloat *points); + void glMap2d (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble *points); + void glMap2f (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat *points); + void glMapGrid1d (GLint un, GLdouble u1, GLdouble u2); + void glMapGrid1f (GLint un, GLfloat u1, GLfloat u2); + void glMapGrid2d (GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2); + void glMapGrid2f (GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2); + void glMaterialf (GLenum face, GLenum pname, GLfloat param); + void glMaterialfv (GLenum face, GLenum pname, GLfloat *params); + void glMateriali (GLenum face, GLenum pname, GLint param); + void glMaterialiv (GLenum face, GLenum pname, GLint *params); + void glMatrixMode (GLenum mode); + void glMultMatrixd (GLdouble *m); + void glMultMatrixf (GLfloat *m); + void glNewList (GLuint list, GLenum mode); + void glNormal3b (GLbyte nx, GLbyte ny, GLbyte nz); + void glNormal3bv (GLbyte *v); + void glNormal3d (GLdouble nx, GLdouble ny, GLdouble nz); + void glNormal3dv (GLdouble *v); + void glNormal3f (GLfloat nx, GLfloat ny, GLfloat nz); + void glNormal3fv (GLfloat *v); + void glNormal3i (GLint nx, GLint ny, GLint nz); + void glNormal3iv (GLint *v); + void glNormal3s (GLshort nx, GLshort ny, GLshort nz); + void glNormal3sv (GLshort *v); + void glNormalPointer (GLenum type, GLsizei stride, GLvoid *pointer); + void glOrtho (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); + void glPassThrough (GLfloat token); + void glPixelMapfv (GLenum map, GLsizei mapsize, GLfloat *values); + void glPixelMapuiv (GLenum map, GLsizei mapsize, GLuint *values); + void glPixelMapusv (GLenum map, GLsizei mapsize, GLushort *values); + void glPixelStoref (GLenum pname, GLfloat param); + void glPixelStorei (GLenum pname, GLint param); + void glPixelTransferf (GLenum pname, GLfloat param); + void glPixelTransferi (GLenum pname, GLint param); + void glPixelZoom (GLfloat xfactor, GLfloat yfactor); + void glPointSize (GLfloat size); + void glPolygonMode (GLenum face, GLenum mode); + void glPolygonOffset (GLfloat factor, GLfloat units); + void glPolygonStipple (GLubyte *mask); + void glPopAttrib (); + void glPopClientAttrib (); + void glPopMatrix (); + void glPopName (); + void glPrioritizeTextures (GLsizei n, GLuint *textures, GLclampf *priorities); + void glPushAttrib (GLbitfield mask); + void glPushClientAttrib (GLbitfield mask); + void glPushMatrix (); + void glPushName (GLuint name); + void glRasterPos2d (GLdouble x, GLdouble y); + void glRasterPos2dv (GLdouble *v); + void glRasterPos2f (GLfloat x, GLfloat y); + void glRasterPos2fv (GLfloat *v); + void glRasterPos2i (GLint x, GLint y); + void glRasterPos2iv (GLint *v); + void glRasterPos2s (GLshort x, GLshort y); + void glRasterPos2sv (GLshort *v); + void glRasterPos3d (GLdouble x, GLdouble y, GLdouble z); + void glRasterPos3dv (GLdouble *v); + void glRasterPos3f (GLfloat x, GLfloat y, GLfloat z); + void glRasterPos3fv (GLfloat *v); + void glRasterPos3i (GLint x, GLint y, GLint z); + void glRasterPos3iv (GLint *v); + void glRasterPos3s (GLshort x, GLshort y, GLshort z); + void glRasterPos3sv (GLshort *v); + void glRasterPos4d (GLdouble x, GLdouble y, GLdouble z, GLdouble w); + void glRasterPos4dv (GLdouble *v); + void glRasterPos4f (GLfloat x, GLfloat y, GLfloat z, GLfloat w); + void glRasterPos4fv (GLfloat *v); + void glRasterPos4i (GLint x, GLint y, GLint z, GLint w); + void glRasterPos4iv (GLint *v); + void glRasterPos4s (GLshort x, GLshort y, GLshort z, GLshort w); + void glRasterPos4sv (GLshort *v); + void glReadBuffer (GLenum mode); + void glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); + void glRectd (GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2); + void glRectdv (GLdouble *v1, GLdouble *v2); + void glRectf (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2); + void glRectfv (GLfloat *v1, GLfloat *v2); + void glRecti (GLint x1, GLint y1, GLint x2, GLint y2); + void glRectiv (GLint *v1, GLint *v2); + void glRects (GLshort x1, GLshort y1, GLshort x2, GLshort y2); + void glRectsv (GLshort *v1, GLshort *v2); + GLint glRenderMode (GLenum mode); + void glRotated (GLdouble angle, GLdouble x, GLdouble y, GLdouble z); + void glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z); + void glScaled (GLdouble x, GLdouble y, GLdouble z); + void glScalef (GLfloat x, GLfloat y, GLfloat z); + void glScissor (GLint x, GLint y, GLsizei width, GLsizei height); + void glSelectBuffer (GLsizei size, GLuint *buffer); + void glShadeModel (GLenum mode); + void glStencilFunc (GLenum func, GLint ref_, GLuint mask); + void glStencilMask (GLuint mask); + void glStencilOp (GLenum fail, GLenum zfail, GLenum zpass); + void glTexCoord1d (GLdouble s); + void glTexCoord1dv (GLdouble *v); + void glTexCoord1f (GLfloat s); + void glTexCoord1fv (GLfloat *v); + void glTexCoord1i (GLint s); + void glTexCoord1iv (GLint *v); + void glTexCoord1s (GLshort s); + void glTexCoord1sv (GLshort *v); + void glTexCoord2d (GLdouble s, GLdouble t); + void glTexCoord2dv (GLdouble *v); + void glTexCoord2f (GLfloat s, GLfloat t); + void glTexCoord2fv (GLfloat *v); + void glTexCoord2i (GLint s, GLint t); + void glTexCoord2iv (GLint *v); + void glTexCoord2s (GLshort s, GLshort t); + void glTexCoord2sv (GLshort *v); + void glTexCoord3d (GLdouble s, GLdouble t, GLdouble r); + void glTexCoord3dv (GLdouble *v); + void glTexCoord3f (GLfloat s, GLfloat t, GLfloat r); + void glTexCoord3fv (GLfloat *v); + void glTexCoord3i (GLint s, GLint t, GLint r); + void glTexCoord3iv (GLint *v); + void glTexCoord3s (GLshort s, GLshort t, GLshort r); + void glTexCoord3sv (GLshort *v); + void glTexCoord4d (GLdouble s, GLdouble t, GLdouble r, GLdouble q); + void glTexCoord4dv (GLdouble *v); + void glTexCoord4f (GLfloat s, GLfloat t, GLfloat r, GLfloat q); + void glTexCoord4fv (GLfloat *v); + void glTexCoord4i (GLint s, GLint t, GLint r, GLint q); + void glTexCoord4iv (GLint *v); + void glTexCoord4s (GLshort s, GLshort t, GLshort r, GLshort q); + void glTexCoord4sv (GLshort *v); + void glTexCoordPointer (GLint size, GLenum type, GLsizei stride, GLvoid *pointer); + void glTexEnvf (GLenum target, GLenum pname, GLfloat param); + void glTexEnvfv (GLenum target, GLenum pname, GLfloat *params); + void glTexEnvi (GLenum target, GLenum pname, GLint param); + void glTexEnviv (GLenum target, GLenum pname, GLint *params); + void glTexGend (GLenum coord, GLenum pname, GLdouble param); + void glTexGendv (GLenum coord, GLenum pname, GLdouble *params); + void glTexGenf (GLenum coord, GLenum pname, GLfloat param); + void glTexGenfv (GLenum coord, GLenum pname, GLfloat *params); + void glTexGeni (GLenum coord, GLenum pname, GLint param); + void glTexGeniv (GLenum coord, GLenum pname, GLint *params); + void glTexImage1D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, GLvoid *pixels); + void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLvoid *pixels); + void glTexParameterf (GLenum target, GLenum pname, GLfloat param); + void glTexParameterfv (GLenum target, GLenum pname, GLfloat *params); + void glTexParameteri (GLenum target, GLenum pname, GLint param); + void glTexParameteriv (GLenum target, GLenum pname, GLint *params); + void glTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, GLvoid *pixels); + void glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); + void glTranslated (GLdouble x, GLdouble y, GLdouble z); + void glTranslatef (GLfloat x, GLfloat y, GLfloat z); + void glVertex2d (GLdouble x, GLdouble y); + void glVertex2dv (GLdouble *v); + void glVertex2f (GLfloat x, GLfloat y); + void glVertex2fv (GLfloat *v); + void glVertex2i (GLint x, GLint y); + void glVertex2iv (GLint *v); + void glVertex2s (GLshort x, GLshort y); + void glVertex2sv (GLshort *v); + void glVertex3d (GLdouble x, GLdouble y, GLdouble z); + void glVertex3dv (GLdouble *v); + void glVertex3f (GLfloat x, GLfloat y, GLfloat z); + void glVertex3fv (GLfloat *v); + void glVertex3i (GLint x, GLint y, GLint z); + void glVertex3iv (GLint *v); + void glVertex3s (GLshort x, GLshort y, GLshort z); + void glVertex3sv (GLshort *v); + void glVertex4d (GLdouble x, GLdouble y, GLdouble z, GLdouble w); + void glVertex4dv (GLdouble *v); + void glVertex4f (GLfloat x, GLfloat y, GLfloat z, GLfloat w); + void glVertex4fv (GLfloat *v); + void glVertex4i (GLint x, GLint y, GLint z, GLint w); + void glVertex4iv (GLint *v); + void glVertex4s (GLshort x, GLshort y, GLshort z, GLshort w); + void glVertex4sv (GLshort *v); + void glVertexPointer (GLint size, GLenum type, GLsizei stride, GLvoid *pointer); + void glViewport (GLint x, GLint y, GLsizei width, GLsizei height); +} \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/opengl/gltypes.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/opengl/gltypes.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,631 @@ +module qt.opengl.gltypes; + +alias uint GLenum; +alias ubyte GLboolean; +alias uint GLbitfield; +alias void GLvoid; +alias byte GLbyte; +alias short GLshort; +alias int GLint; +alias ubyte GLubyte; +alias ushort GLushort; +alias uint GLuint; +alias int GLsizei; +alias float GLfloat; +alias float GLclampf; +alias double GLdouble; +alias double GLclampd; +alias char GLchar; +alias ptrdiff_t GLintptr; +alias ptrdiff_t GLsizeiptr; + +// Boolean values +enum : GLboolean +{ + GL_FALSE = 0x0, + GL_TRUE = 0x1, +} + +enum : GLenum +{ + // Data types + GL_BYTE = 0x1400, + GL_UNSIGNED_BYTE = 0x1401, + GL_SHORT = 0x1402, + GL_UNSIGNED_SHORT = 0x1403, + GL_INT = 0x1404, + GL_UNSIGNED_INT = 0x1405, + GL_FLOAT = 0x1406, + GL_DOUBLE = 0x140A, + GL_2_BYTES = 0x1407, + GL_3_BYTES = 0x1408, + GL_4_BYTES = 0x1409, + + // Primitives + GL_POINTS = 0x0000, + GL_LINES = 0x0001, + GL_LINE_LOOP = 0x0002, + GL_LINE_STRIP = 0x0003, + GL_TRIANGLES = 0x0004, + GL_TRIANGLE_STRIP = 0x0005, + GL_TRIANGLE_FAN = 0x0006, + GL_QUADS = 0x0007, + GL_QUAD_STRIP = 0x0008, + GL_POLYGON = 0x0009, + + // Vertex Arrays + GL_VERTEX_ARRAY = 0x8074, + GL_NORMAL_ARRAY = 0x8075, + GL_COLOR_ARRAY = 0x8076, + GL_INDEX_ARRAY = 0x8077, + GL_TEXTURE_COORD_ARRAY = 0x8078, + GL_EDGE_FLAG_ARRAY = 0x8079, + GL_VERTEX_ARRAY_SIZE = 0x807A, + GL_VERTEX_ARRAY_TYPE = 0x807B, + GL_VERTEX_ARRAY_STRIDE = 0x807C, + GL_NORMAL_ARRAY_TYPE = 0x807E, + GL_NORMAL_ARRAY_STRIDE = 0x807F, + GL_COLOR_ARRAY_SIZE = 0x8081, + GL_COLOR_ARRAY_TYPE = 0x8082, + GL_COLOR_ARRAY_STRIDE = 0x8083, + GL_INDEX_ARRAY_TYPE = 0x8085, + GL_INDEX_ARRAY_STRIDE = 0x8086, + GL_TEXTURE_COORD_ARRAY_SIZE = 0x8088, + GL_TEXTURE_COORD_ARRAY_TYPE = 0x8089, + GL_TEXTURE_COORD_ARRAY_STRIDE = 0x808A, + GL_EDGE_FLAG_ARRAY_STRIDE = 0x808C, + GL_VERTEX_ARRAY_POINTER = 0x808E, + GL_NORMAL_ARRAY_POINTER = 0x808F, + GL_COLOR_ARRAY_POINTER = 0x8090, + GL_INDEX_ARRAY_POINTER = 0x8091, + GL_TEXTURE_COORD_ARRAY_POINTER = 0x8092, + GL_EDGE_FLAG_ARRAY_POINTER = 0x8093, + GL_V2F = 0x2A20, + GL_V3F = 0x2A21, + GL_C4UB_V2F = 0x2A22, + GL_C4UB_V3F = 0x2A23, + GL_C3F_V3F = 0x2A24, + GL_N3F_V3F = 0x2A25, + GL_C4F_N3F_V3F = 0x2A26, + GL_T2F_V3F = 0x2A27, + GL_T4F_V4F = 0x2A28, + GL_T2F_C4UB_V3F = 0x2A29, + GL_T2F_C3F_V3F = 0x2A2A, + GL_T2F_N3F_V3F = 0x2A2B, + GL_T2F_C4F_N3F_V3F = 0x2A2C, + GL_T4F_C4F_N3F_V4F = 0x2A2D, + + // Matrix Mode + GL_MATRIX_MODE = 0x0BA0, + GL_MODELVIEW = 0x1700, + GL_PROJECTION = 0x1701, + GL_TEXTURE = 0x1702, + + // Points + GL_POINT_SMOOTH = 0x0B10, + GL_POINT_SIZE = 0x0B11, + GL_POINT_SIZE_GRANULARITY = 0x0B13, + GL_POINT_SIZE_RANGE = 0x0B12, + + // Lines + GL_LINE_SMOOTH = 0x0B20, + GL_LINE_STIPPLE = 0x0B24, + GL_LINE_STIPPLE_PATTERN = 0x0B25, + GL_LINE_STIPPLE_REPEAT = 0x0B26, + GL_LINE_WIDTH = 0x0B21, + GL_LINE_WIDTH_GRANULARITY = 0x0B23, + GL_LINE_WIDTH_RANGE = 0x0B22, + + // Polygons + GL_POINT = 0x1B00, + GL_LINE = 0x1B01, + GL_FILL = 0x1B02, + GL_CW = 0x0900, + GL_CCW = 0x0901, + GL_FRONT = 0x0404, + GL_BACK = 0x0405, + GL_POLYGON_MODE = 0x0B40, + GL_POLYGON_SMOOTH = 0x0B41, + GL_POLYGON_STIPPLE = 0x0B42, + GL_EDGE_FLAG = 0x0B43, + GL_CULL_FACE = 0x0B44, + GL_CULL_FACE_MODE = 0x0B45, + GL_FRONT_FACE = 0x0B46, + GL_POLYGON_OFFSET_FACTOR = 0x8038, + GL_POLYGON_OFFSET_UNITS = 0x2A00, + GL_POLYGON_OFFSET_POINT = 0x2A01, + GL_POLYGON_OFFSET_LINE = 0x2A02, + GL_POLYGON_OFFSET_FILL = 0x8037, + + // Display Lists + GL_COMPILE = 0x1300, + GL_COMPILE_AND_EXECUTE = 0x1301, + GL_LIST_BASE = 0x0B32, + GL_LIST_INDEX = 0x0B33, + GL_LIST_MODE = 0x0B30, + + // Depth buffer + GL_NEVER = 0x0200, + GL_LESS = 0x0201, + GL_EQUAL = 0x0202, + GL_LEQUAL = 0x0203, + GL_GREATER = 0x0204, + GL_NOTEQUAL = 0x0205, + GL_GEQUAL = 0x0206, + GL_ALWAYS = 0x0207, + GL_DEPTH_TEST = 0x0B71, + GL_DEPTH_BITS = 0x0D56, + GL_DEPTH_CLEAR_VALUE = 0x0B73, + GL_DEPTH_FUNC = 0x0B74, + GL_DEPTH_RANGE = 0x0B70, + GL_DEPTH_WRITEMASK = 0x0B72, + GL_DEPTH_COMPONENT = 0x1902, + + // Lighting + GL_LIGHTING = 0x0B50, + GL_LIGHT0 = 0x4000, + GL_LIGHT1 = 0x4001, + GL_LIGHT2 = 0x4002, + GL_LIGHT3 = 0x4003, + GL_LIGHT4 = 0x4004, + GL_LIGHT5 = 0x4005, + GL_LIGHT6 = 0x4006, + GL_LIGHT7 = 0x4007, + GL_SPOT_EXPONENT = 0x1205, + GL_SPOT_CUTOFF = 0x1206, + GL_CONSTANT_ATTENUATION = 0x1207, + GL_LINEAR_ATTENUATION = 0x1208, + GL_QUADRATIC_ATTENUATION = 0x1209, + GL_AMBIENT = 0x1200, + GL_DIFFUSE = 0x1201, + GL_SPECULAR = 0x1202, + GL_SHININESS = 0x1601, + GL_EMISSION = 0x1600, + GL_POSITION = 0x1203, + GL_SPOT_DIRECTION = 0x1204, + GL_AMBIENT_AND_DIFFUSE = 0x1602, + GL_COLOR_INDEXES = 0x1603, + GL_LIGHT_MODEL_TWO_SIDE = 0x0B52, + GL_LIGHT_MODEL_LOCAL_VIEWER = 0x0B51, + GL_LIGHT_MODEL_AMBIENT = 0x0B53, + GL_FRONT_AND_BACK = 0x0408, + GL_SHADE_MODEL = 0x0B54, + GL_FLAT = 0x1D00, + GL_SMOOTH = 0x1D01, + GL_COLOR_MATERIAL = 0x0B57, + GL_COLOR_MATERIAL_FACE = 0x0B55, + GL_COLOR_MATERIAL_PARAMETER = 0x0B56, + GL_NORMALIZE = 0x0BA1, + + // User clipping planes + GL_CLIP_PLANE0 = 0x3000, + GL_CLIP_PLANE1 = 0x3001, + GL_CLIP_PLANE2 = 0x3002, + GL_CLIP_PLANE3 = 0x3003, + GL_CLIP_PLANE4 = 0x3004, + GL_CLIP_PLANE5 = 0x3005, + + // Accumulation buffer + GL_ACCUM_RED_BITS = 0x0D58, + GL_ACCUM_GREEN_BITS = 0x0D59, + GL_ACCUM_BLUE_BITS = 0x0D5A, + GL_ACCUM_ALPHA_BITS = 0x0D5B, + GL_ACCUM_CLEAR_VALUE = 0x0B80, + GL_ACCUM = 0x0100, + GL_ADD = 0x0104, + GL_LOAD = 0x0101, + GL_MULT = 0x0103, + GL_RETURN = 0x0102, + + // Alpha testing + GL_ALPHA_TEST = 0x0BC0, + GL_ALPHA_TEST_REF = 0x0BC2, + GL_ALPHA_TEST_FUNC = 0x0BC1, + + // Blending + GL_BLEND = 0x0BE2, + GL_BLEND_SRC = 0x0BE1, + GL_BLEND_DST = 0x0BE0, + GL_ZERO = 0x0, + GL_ONE = 0x1, + GL_SRC_COLOR = 0x0300, + GL_ONE_MINUS_SRC_COLOR = 0x0301, + GL_SRC_ALPHA = 0x0302, + GL_ONE_MINUS_SRC_ALPHA = 0x0303, + GL_DST_ALPHA = 0x0304, + GL_ONE_MINUS_DST_ALPHA = 0x0305, + GL_DST_COLOR = 0x0306, + GL_ONE_MINUS_DST_COLOR = 0x0307, + GL_SRC_ALPHA_SATURATE = 0x0308, + + // Render Mode + GL_FEEDBACK = 0x1C01, + GL_RENDER = 0x1C00, + GL_SELECT = 0x1C02, + + // Feedback + GL_2D = 0x0600, + GL_3D = 0x0601, + GL_3D_COLOR = 0x0602, + GL_3D_COLOR_TEXTURE = 0x0603, + GL_4D_COLOR_TEXTURE = 0x0604, + GL_POINT_TOKEN = 0x0701, + GL_LINE_TOKEN = 0x0702, + GL_LINE_RESET_TOKEN = 0x0707, + GL_POLYGON_TOKEN = 0x0703, + GL_BITMAP_TOKEN = 0x0704, + GL_DRAW_PIXEL_TOKEN = 0x0705, + GL_COPY_PIXEL_TOKEN = 0x0706, + GL_PASS_THROUGH_TOKEN = 0x0700, + GL_FEEDBACK_BUFFER_POINTER = 0x0DF0, + GL_FEEDBACK_BUFFER_SIZE = 0x0DF1, + GL_FEEDBACK_BUFFER_TYPE = 0x0DF2, + + // Selection + GL_SELECTION_BUFFER_POINTER = 0x0DF3, + GL_SELECTION_BUFFER_SIZE = 0x0DF4, + + // Fog + GL_FOG = 0x0B60, + GL_FOG_MODE = 0x0B65, + GL_FOG_DENSITY = 0x0B62, + GL_FOG_COLOR = 0x0B66, + GL_FOG_INDEX = 0x0B61, + GL_FOG_START = 0x0B63, + GL_FOG_END = 0x0B64, + GL_LINEAR = 0x2601, + GL_EXP = 0x0800, + GL_EXP2 = 0x0801, + + // Logic Ops + GL_LOGIC_OP = 0x0BF1, + GL_INDEX_LOGIC_OP = 0x0BF1, + GL_COLOR_LOGIC_OP = 0x0BF2, + GL_LOGIC_OP_MODE = 0x0BF0, + GL_CLEAR = 0x1500, + GL_SET = 0x150F, + GL_COPY = 0x1503, + GL_COPY_INVERTED = 0x150C, + GL_NOOP = 0x1505, + GL_INVERT = 0x150A, + GL_AND = 0x1501, + GL_NAND = 0x150E, + GL_OR = 0x1507, + GL_NOR = 0x1508, + GL_XOR = 0x1506, + GL_EQUIV = 0x1509, + GL_AND_REVERSE = 0x1502, + GL_AND_INVERTED = 0x1504, + GL_OR_REVERSE = 0x150B, + GL_OR_INVERTED = 0x150D, + + // Stencil + GL_STENCIL_TEST = 0x0B90, + GL_STENCIL_WRITEMASK = 0x0B98, + GL_STENCIL_BITS = 0x0D57, + GL_STENCIL_FUNC = 0x0B92, + GL_STENCIL_VALUE_MASK = 0x0B93, + GL_STENCIL_REF = 0x0B97, + GL_STENCIL_FAIL = 0x0B94, + GL_STENCIL_PASS_DEPTH_PASS = 0x0B96, + GL_STENCIL_PASS_DEPTH_FAIL = 0x0B95, + GL_STENCIL_CLEAR_VALUE = 0x0B91, + GL_STENCIL_INDEX = 0x1901, + GL_KEEP = 0x1E00, + GL_REPLACE = 0x1E01, + GL_INCR = 0x1E02, + GL_DECR = 0x1E03, + + // Buffers, Pixel Drawing/Reading + GL_NONE = 0x0, + GL_LEFT = 0x0406, + GL_RIGHT = 0x0407, + GL_FRONT_LEFT = 0x0400, + GL_FRONT_RIGHT = 0x0401, + GL_BACK_LEFT = 0x0402, + GL_BACK_RIGHT = 0x0403, + GL_AUX0 = 0x0409, + GL_AUX1 = 0x040A, + GL_AUX2 = 0x040B, + GL_AUX3 = 0x040C, + GL_COLOR_INDEX = 0x1900, + GL_RED = 0x1903, + GL_GREEN = 0x1904, + GL_BLUE = 0x1905, + GL_ALPHA = 0x1906, + GL_LUMINANCE = 0x1909, + GL_LUMINANCE_ALPHA = 0x190A, + GL_ALPHA_BITS = 0x0D55, + GL_RED_BITS = 0x0D52, + GL_GREEN_BITS = 0x0D53, + GL_BLUE_BITS = 0x0D54, + GL_INDEX_BITS = 0x0D51, + GL_SUBPIXEL_BITS = 0x0D50, + GL_AUX_BUFFERS = 0x0C00, + GL_READ_BUFFER = 0x0C02, + GL_DRAW_BUFFER = 0x0C01, + GL_DOUBLEBUFFER = 0x0C32, + GL_STEREO = 0x0C33, + GL_BITMAP = 0x1A00, + GL_COLOR = 0x1800, + GL_DEPTH = 0x1801, + GL_STENCIL = 0x1802, + GL_DITHER = 0x0BD0, + GL_RGB = 0x1907, + GL_RGBA = 0x1908, + + // Implementation limits + GL_MAX_LIST_NESTING = 0x0B31, + GL_MAX_ATTRIB_STACK_DEPTH = 0x0D35, + GL_MAX_MODELVIEW_STACK_DEPTH = 0x0D36, + GL_MAX_NAME_STACK_DEPTH = 0x0D37, + GL_MAX_PROJECTION_STACK_DEPTH = 0x0D38, + GL_MAX_TEXTURE_STACK_DEPTH = 0x0D39, + GL_MAX_EVAL_ORDER = 0x0D30, + GL_MAX_LIGHTS = 0x0D31, + GL_MAX_CLIP_PLANES = 0x0D32, + GL_MAX_TEXTURE_SIZE = 0x0D33, + GL_MAX_PIXEL_MAP_TABLE = 0x0D34, + GL_MAX_VIEWPORT_DIMS = 0x0D3A, + GL_MAX_CLIENT_ATTRIB_STACK_DEPTH = 0x0D3B, + + // Gets + GL_ATTRIB_STACK_DEPTH = 0x0BB0, + GL_CLIENT_ATTRIB_STACK_DEPTH = 0x0BB1, + GL_COLOR_CLEAR_VALUE = 0x0C22, + GL_COLOR_WRITEMASK = 0x0C23, + GL_CURRENT_INDEX = 0x0B01, + GL_CURRENT_COLOR = 0x0B00, + GL_CURRENT_NORMAL = 0x0B02, + GL_CURRENT_RASTER_COLOR = 0x0B04, + GL_CURRENT_RASTER_DISTANCE = 0x0B09, + GL_CURRENT_RASTER_INDEX = 0x0B05, + GL_CURRENT_RASTER_POSITION = 0x0B07, + GL_CURRENT_RASTER_TEXTURE_COORDS = 0x0B06, + GL_CURRENT_RASTER_POSITION_VALID = 0x0B08, + GL_CURRENT_TEXTURE_COORDS = 0x0B03, + GL_INDEX_CLEAR_VALUE = 0x0C20, + GL_INDEX_MODE = 0x0C30, + GL_INDEX_WRITEMASK = 0x0C21, + GL_MODELVIEW_MATRIX = 0x0BA6, + GL_MODELVIEW_STACK_DEPTH = 0x0BA3, + GL_NAME_STACK_DEPTH = 0x0D70, + GL_PROJECTION_MATRIX = 0x0BA7, + GL_PROJECTION_STACK_DEPTH = 0x0BA4, + GL_RENDER_MODE = 0x0C40, + GL_RGBA_MODE = 0x0C31, + GL_TEXTURE_MATRIX = 0x0BA8, + GL_TEXTURE_STACK_DEPTH = 0x0BA5, + GL_VIEWPORT = 0x0BA2, + + // Evaluators + GL_AUTO_NORMAL = 0x0D80, + GL_MAP1_COLOR_4 = 0x0D90, + GL_MAP1_GRID_DOMAIN = 0x0DD0, + GL_MAP1_GRID_SEGMENTS = 0x0DD1, + GL_MAP1_INDEX = 0x0D91, + GL_MAP1_NORMAL = 0x0D92, + GL_MAP1_TEXTURE_COORD_1 = 0x0D93, + GL_MAP1_TEXTURE_COORD_2 = 0x0D94, + GL_MAP1_TEXTURE_COORD_3 = 0x0D95, + GL_MAP1_TEXTURE_COORD_4 = 0x0D96, + GL_MAP1_VERTEX_3 = 0x0D97, + GL_MAP1_VERTEX_4 = 0x0D98, + GL_MAP2_COLOR_4 = 0x0DB0, + GL_MAP2_GRID_DOMAIN = 0x0DD2, + GL_MAP2_GRID_SEGMENTS = 0x0DD3, + GL_MAP2_INDEX = 0x0DB1, + GL_MAP2_NORMAL = 0x0DB2, + GL_MAP2_TEXTURE_COORD_1 = 0x0DB3, + GL_MAP2_TEXTURE_COORD_2 = 0x0DB4, + GL_MAP2_TEXTURE_COORD_3 = 0x0DB5, + GL_MAP2_TEXTURE_COORD_4 = 0x0DB6, + GL_MAP2_VERTEX_3 = 0x0DB7, + GL_MAP2_VERTEX_4 = 0x0DB8, + GL_COEFF = 0x0A00, + GL_DOMAIN = 0x0A02, + GL_ORDER = 0x0A01, + + // Hints + GL_FOG_HINT = 0x0C54, + GL_LINE_SMOOTH_HINT = 0x0C52, + GL_PERSPECTIVE_CORRECTION_HINT = 0x0C50, + GL_POINT_SMOOTH_HINT = 0x0C51, + GL_POLYGON_SMOOTH_HINT = 0x0C53, + GL_DONT_CARE = 0x1100, + GL_FASTEST = 0x1101, + GL_NICEST = 0x1102, + + // Scissor box + GL_SCISSOR_TEST = 0x0C11, + GL_SCISSOR_BOX = 0x0C10, + + // Pixel Mode / Transfer + GL_MAP_COLOR = 0x0D10, + GL_MAP_STENCIL = 0x0D11, + GL_INDEX_SHIFT = 0x0D12, + GL_INDEX_OFFSET = 0x0D13, + GL_RED_SCALE = 0x0D14, + GL_RED_BIAS = 0x0D15, + GL_GREEN_SCALE = 0x0D18, + GL_GREEN_BIAS = 0x0D19, + GL_BLUE_SCALE = 0x0D1A, + GL_BLUE_BIAS = 0x0D1B, + GL_ALPHA_SCALE = 0x0D1C, + GL_ALPHA_BIAS = 0x0D1D, + GL_DEPTH_SCALE = 0x0D1E, + GL_DEPTH_BIAS = 0x0D1F, + GL_PIXEL_MAP_S_TO_S_SIZE = 0x0CB1, + GL_PIXEL_MAP_I_TO_I_SIZE = 0x0CB0, + GL_PIXEL_MAP_I_TO_R_SIZE = 0x0CB2, + GL_PIXEL_MAP_I_TO_G_SIZE = 0x0CB3, + GL_PIXEL_MAP_I_TO_B_SIZE = 0x0CB4, + GL_PIXEL_MAP_I_TO_A_SIZE = 0x0CB5, + GL_PIXEL_MAP_R_TO_R_SIZE = 0x0CB6, + GL_PIXEL_MAP_G_TO_G_SIZE = 0x0CB7, + GL_PIXEL_MAP_B_TO_B_SIZE = 0x0CB8, + GL_PIXEL_MAP_A_TO_A_SIZE = 0x0CB9, + GL_PIXEL_MAP_S_TO_S = 0x0C71, + GL_PIXEL_MAP_I_TO_I = 0x0C70, + GL_PIXEL_MAP_I_TO_R = 0x0C72, + GL_PIXEL_MAP_I_TO_G = 0x0C73, + GL_PIXEL_MAP_I_TO_B = 0x0C74, + GL_PIXEL_MAP_I_TO_A = 0x0C75, + GL_PIXEL_MAP_R_TO_R = 0x0C76, + GL_PIXEL_MAP_G_TO_G = 0x0C77, + GL_PIXEL_MAP_B_TO_B = 0x0C78, + GL_PIXEL_MAP_A_TO_A = 0x0C79, + GL_PACK_ALIGNMENT = 0x0D05, + GL_PACK_LSB_FIRST = 0x0D01, + GL_PACK_ROW_LENGTH = 0x0D02, + GL_PACK_SKIP_PIXELS = 0x0D04, + GL_PACK_SKIP_ROWS = 0x0D03, + GL_PACK_SWAP_BYTES = 0x0D00, + GL_UNPACK_ALIGNMENT = 0x0CF5, + GL_UNPACK_LSB_FIRST = 0x0CF1, + GL_UNPACK_ROW_LENGTH = 0x0CF2, + GL_UNPACK_SKIP_PIXELS = 0x0CF4, + GL_UNPACK_SKIP_ROWS = 0x0CF3, + GL_UNPACK_SWAP_BYTES = 0x0CF0, + GL_ZOOM_X = 0x0D16, + GL_ZOOM_Y = 0x0D17, + + // Texture mapping + GL_TEXTURE_ENV = 0x2300, + GL_TEXTURE_ENV_MODE = 0x2200, + GL_TEXTURE_1D = 0x0DE0, + GL_TEXTURE_2D = 0x0DE1, + GL_TEXTURE_WRAP_S = 0x2802, + GL_TEXTURE_WRAP_T = 0x2803, + GL_TEXTURE_MAG_FILTER = 0x2800, + GL_TEXTURE_MIN_FILTER = 0x2801, + GL_TEXTURE_ENV_COLOR = 0x2201, + GL_TEXTURE_GEN_S = 0x0C60, + GL_TEXTURE_GEN_T = 0x0C61, + GL_TEXTURE_GEN_MODE = 0x2500, + GL_TEXTURE_BORDER_COLOR = 0x1004, + GL_TEXTURE_WIDTH = 0x1000, + GL_TEXTURE_HEIGHT = 0x1001, + GL_TEXTURE_BORDER = 0x1005, + GL_TEXTURE_COMPONENTS = 0x1003, + GL_TEXTURE_RED_SIZE = 0x805C, + GL_TEXTURE_GREEN_SIZE = 0x805D, + GL_TEXTURE_BLUE_SIZE = 0x805E, + GL_TEXTURE_ALPHA_SIZE = 0x805F, + GL_TEXTURE_LUMINANCE_SIZE = 0x8060, + GL_TEXTURE_INTENSITY_SIZE = 0x8061, + GL_NEAREST_MIPMAP_NEAREST = 0x2700, + GL_NEAREST_MIPMAP_LINEAR = 0x2702, + GL_LINEAR_MIPMAP_NEAREST = 0x2701, + GL_LINEAR_MIPMAP_LINEAR = 0x2703, + GL_OBJECT_LINEAR = 0x2401, + GL_OBJECT_PLANE = 0x2501, + GL_EYE_LINEAR = 0x2400, + GL_EYE_PLANE = 0x2502, + GL_SPHERE_MAP = 0x2402, + GL_DECAL = 0x2101, + GL_MODULATE = 0x2100, + GL_NEAREST = 0x2600, + GL_REPEAT = 0x2901, + GL_CLAMP = 0x2900, + GL_S = 0x2000, + GL_T = 0x2001, + GL_R = 0x2002, + GL_Q = 0x2003, + GL_TEXTURE_GEN_R = 0x0C62, + GL_TEXTURE_GEN_Q = 0x0C63, + + // Utility + GL_VENDOR = 0x1F00, + GL_RENDERER = 0x1F01, + GL_VERSION = 0x1F02, + GL_EXTENSIONS = 0x1F03, + + // Errors + GL_NO_ERROR = 0x0, + GL_INVALID_VALUE = 0x0501, + GL_INVALID_ENUM = 0x0500, + GL_INVALID_OPERATION = 0x0502, + GL_STACK_OVERFLOW = 0x0503, + GL_STACK_UNDERFLOW = 0x0504, + GL_OUT_OF_MEMORY = 0x0505, +} + +// glPush/PopAttrib bits +enum : GLuint +{ + GL_CURRENT_BIT = 0x00000001, + GL_POINT_BIT = 0x00000002, + GL_LINE_BIT = 0x00000004, + GL_POLYGON_BIT = 0x00000008, + GL_POLYGON_STIPPLE_BIT = 0x00000010, + GL_PIXEL_MODE_BIT = 0x00000020, + GL_LIGHTING_BIT = 0x00000040, + GL_FOG_BIT = 0x00000080, + GL_DEPTH_BUFFER_BIT = 0x00000100, + GL_ACCUM_BUFFER_BIT = 0x00000200, + GL_STENCIL_BUFFER_BIT = 0x00000400, + GL_VIEWPORT_BIT = 0x00000800, + GL_TRANSFORM_BIT = 0x00001000, + GL_ENABLE_BIT = 0x00002000, + GL_COLOR_BUFFER_BIT = 0x00004000, + GL_HINT_BIT = 0x00008000, + GL_EVAL_BIT = 0x00010000, + GL_LIST_BIT = 0x00020000, + GL_TEXTURE_BIT = 0x00040000, + GL_SCISSOR_BIT = 0x00080000, + GL_ALL_ATTRIB_BITS = 0x000FFFFF, +} + +// gl 1.1 +enum : GLenum +{ +GL_PROXY_TEXTURE_1D = 0x8063, +GL_PROXY_TEXTURE_2D = 0x8064, +GL_TEXTURE_PRIORITY = 0x8066, +GL_TEXTURE_RESIDENT = 0x8067, +GL_TEXTURE_BINDING_1D = 0x8068, +GL_TEXTURE_BINDING_2D = 0x8069, +GL_TEXTURE_INTERNAL_FORMAT = 0x1003, +GL_ALPHA4 = 0x803B, +GL_ALPHA8 = 0x803C, +GL_ALPHA12 = 0x803D, +GL_ALPHA16 = 0x803E, +GL_LUMINANCE4 = 0x803F, +GL_LUMINANCE8 = 0x8040, +GL_LUMINANCE12 = 0x8041, +GL_LUMINANCE16 = 0x8042, +GL_LUMINANCE4_ALPHA4 = 0x8043, +GL_LUMINANCE6_ALPHA2 = 0x8044, +GL_LUMINANCE8_ALPHA8 = 0x8045, +GL_LUMINANCE12_ALPHA4 = 0x8046, +GL_LUMINANCE12_ALPHA12 = 0x8047, +GL_LUMINANCE16_ALPHA16 = 0x8048, +GL_INTENSITY = 0x8049, +GL_INTENSITY4 = 0x804A, +GL_INTENSITY8 = 0x804B, +GL_INTENSITY12 = 0x804C, +GL_INTENSITY16 = 0x804D, +GL_R3_G3_B2 = 0x2A10, +GL_RGB4 = 0x804F, +GL_RGB5 = 0x8050, +GL_RGB8 = 0x8051, +GL_RGB10 = 0x8052, +GL_RGB12 = 0x8053, +GL_RGB16 = 0x8054, +GL_RGBA2 = 0x8055, +GL_RGBA4 = 0x8056, +GL_RGB5_A1 = 0x8057, +GL_RGBA8 = 0x8058, +GL_RGB10_A2 = 0x8059, +GL_RGBA12 = 0x805A, +GL_RGBA16 = 0x805B, +} + +enum : GLuint +{ + GL_CLIENT_PIXEL_STORE_BIT = 0x00000001, + GL_CLIENT_VERTEX_ARRAY_BIT = 0x00000002, + GL_ALL_CLIENT_ATTRIB_BITS = 0xFFFFFFFF, + GL_CLIENT_ALL_ATTRIB_BITS = 0xFFFFFFFF, +} diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qt/opengl/glu.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qt/opengl/glu.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,196 @@ +module qt.opengl.glu; + +private import qt.opengl.gltypes; + +//============================================================================== +// CONSTANTS +//============================================================================== +enum : GLenum +{ + // StringName + GLU_VERSION = 100800, + GLU_EXTENSIONS = 100801, + // ErrorCode + GLU_INVALID_ENUM = 100900, + GLU_INVALID_VALUE = 100901, + GLU_OUT_OF_MEMORY = 100902, + GLU_INVALID_OPERATION = 100904, + // NurbsDisplay + GLU_OUTLINE_POLYGON = 100240, + GLU_OUTLINE_PATCH = 100241, + // NurbsCallback + GLU_NURBS_ERROR = 100103, + GLU_ERROR = 100103, + GLU_NURBS_BEGIN = 100164, + GLU_NURBS_BEGIN_EXT = 100164, + GLU_NURBS_VERTEX = 100165, + GLU_NURBS_VERTEX_EXT = 100165, + GLU_NURBS_NORMAL = 100166, + GLU_NURBS_NORMAL_EXT = 100166, + GLU_NURBS_COLOR = 100167, + GLU_NURBS_COLOR_EXT = 100167, + GLU_NURBS_TEXTURE_COORD = 100168, + GLU_NURBS_TEX_COORD_EXT = 100168, + GLU_NURBS_END = 100169, + GLU_NURBS_END_EXT = 100169, + GLU_NURBS_BEGIN_DATA = 100170, + GLU_NURBS_BEGIN_DATA_EXT = 100170, + GLU_NURBS_VERTEX_DATA = 100171, + GLU_NURBS_VERTEX_DATA_EXT = 100171, + GLU_NURBS_NORMAL_DATA = 100172, + GLU_NURBS_NORMAL_DATA_EXT = 100172, + GLU_NURBS_COLOR_DATA = 100173, + GLU_NURBS_COLOR_DATA_EXT = 100173, + GLU_NURBS_TEXTURE_COORD_DATA = 100174, + GLU_NURBS_TEX_COORD_DATA_EXT = 100174, + GLU_NURBS_END_DATA = 100175, + GLU_NURBS_END_DATA_EXT = 100175, + // NurbsError + GLU_NURBS_ERROR1 = 100251, + GLU_NURBS_ERROR2 = 100252, + GLU_NURBS_ERROR3 = 100253, + GLU_NURBS_ERROR4 = 100254, + GLU_NURBS_ERROR5 = 100255, + GLU_NURBS_ERROR6 = 100256, + GLU_NURBS_ERROR7 = 100257, + GLU_NURBS_ERROR8 = 100258, + GLU_NURBS_ERROR9 = 100259, + GLU_NURBS_ERROR10 = 100260, + GLU_NURBS_ERROR11 = 100261, + GLU_NURBS_ERROR12 = 100262, + GLU_NURBS_ERROR13 = 100263, + GLU_NURBS_ERROR14 = 100264, + GLU_NURBS_ERROR15 = 100265, + GLU_NURBS_ERROR16 = 100266, + GLU_NURBS_ERROR17 = 100267, + GLU_NURBS_ERROR18 = 100268, + GLU_NURBS_ERROR19 = 100269, + GLU_NURBS_ERROR20 = 100270, + GLU_NURBS_ERROR21 = 100271, + GLU_NURBS_ERROR22 = 100272, + GLU_NURBS_ERROR23 = 100273, + GLU_NURBS_ERROR24 = 100274, + GLU_NURBS_ERROR25 = 100275, + GLU_NURBS_ERROR26 = 100276, + GLU_NURBS_ERROR27 = 100277, + GLU_NURBS_ERROR28 = 100278, + GLU_NURBS_ERROR29 = 100279, + GLU_NURBS_ERROR30 = 100280, + GLU_NURBS_ERROR31 = 100281, + GLU_NURBS_ERROR32 = 100282, + GLU_NURBS_ERROR33 = 100283, + GLU_NURBS_ERROR34 = 100284, + GLU_NURBS_ERROR35 = 100285, + GLU_NURBS_ERROR36 = 100286, + GLU_NURBS_ERROR37 = 100287, + // NurbsProperty + GLU_AUTO_LOAD_MATRIX = 100200, + GLU_CULLING = 100201, + GLU_SAMPLING_TOLERANCE = 100203, + GLU_DISPLAY_MODE = 100204, + GLU_PARAMETRIC_TOLERANCE = 100202, + GLU_SAMPLING_METHOD = 100205, + GLU_U_STEP = 100206, + GLU_V_STEP = 100207, + GLU_NURBS_MODE = 100160, + GLU_NURBS_MODE_EXT = 100160, + GLU_NURBS_TESSELLATOR = 100161, + GLU_NURBS_TESSELLATOR_EXT = 100161, + GLU_NURBS_RENDERER = 100162, + GLU_NURBS_RENDERER_EXT = 100162, + // NurbsSampling + GLU_OBJECT_PARAMETRIC_ERROR = 100208, + GLU_OBJECT_PARAMETRIC_ERROR_EXT = 100208, + GLU_OBJECT_PATH_LENGTH = 100209, + GLU_OBJECT_PATH_LENGTH_EXT = 100209, + GLU_PATH_LENGTH = 100215, + GLU_PARAMETRIC_ERROR = 100216, + GLU_DOMAIN_DISTANCE = 100217, + // NurbsTrim + GLU_MAP1_TRIM_2 = 100210, + GLU_MAP2_TRIM_3 = 100211, + // QuadricDrawStyle + GLU_POINT = 100010, + GLU_LINE = 100011, + GLU_FILL = 100012, + GLU_SILHOUETTE = 100013, + // QuadricNormal + GLU_SMOOTH = 100000, + GLU_FLAT = 100001, + GLU_NONE = 100002, + // QuadricOrientation + GLU_OUTSIDE = 100020, + GLU_INSIDE = 100021, + // TessCallback + GLU_TESS_BEGIN = 100100, + GLU_BEGIN = 100100, + GLU_TESS_VERTEX = 100101, + GLU_VERTEX = 100101, + GLU_TESS_END = 100102, + GLU_END = 100102, + GLU_TESS_ERROR = 100103, + GLU_TESS_EDGE_FLAG = 100104, + GLU_EDGE_FLAG = 100104, + GLU_TESS_COMBINE = 100105, + GLU_TESS_BEGIN_DATA = 100106, + GLU_TESS_VERTEX_DATA = 100107, + GLU_TESS_END_DATA = 100108, + GLU_TESS_ERROR_DATA = 100109, + GLU_TESS_EDGE_FLAG_DATA = 100110, + GLU_TESS_COMBINE_DATA = 100111, + // TessContour + GLU_CW = 100120, + GLU_CCW = 100121, + GLU_INTERIOR = 100122, + GLU_EXTERIOR = 100123, + GLU_UNKNOWN = 100124, + // TessProperty + GLU_TESS_WINDING_RULE = 100140, + GLU_TESS_BOUNDARY_ONLY = 100141, + GLU_TESS_TOLERANCE = 100142, + // TessError + GLU_TESS_ERROR1 = 100151, + GLU_TESS_ERROR2 = 100152, + GLU_TESS_ERROR3 = 100153, + GLU_TESS_ERROR4 = 100154, + GLU_TESS_ERROR5 = 100155, + GLU_TESS_ERROR6 = 100156, + GLU_TESS_ERROR7 = 100157, + GLU_TESS_ERROR8 = 100158, + GLU_TESS_MISSING_BEGIN_POLYGON = 100151, + GLU_TESS_MISSING_BEGIN_COUNTER = 100152, + GLU_TESS_MISSING_END_POLYGON = 100153, + GLU_TESS_MISSING_END_COUNTER = 100154, + GLU_TESS_COORD_TOO_LARGE = 100155, + GLU_TESS_NEED_COMBINE_CALLBACK = 100156, + // TessWinding + GLU_TESS_WINDING_ODD = 100130, + GLU_TESS_WINDING_NONZERO = 100131, + GLU_TESS_WINDING_POSITIVE = 100132, + GLU_TESS_WINDING_NEGATIVE = 100133, + GLU_TESS_WINDING_ABS_GEQ_TWO = 100134, +} + +const GLdouble GLU_TESS_MAX_COORD = 1.0e150; + +//============================================================================== +// TYPES +//============================================================================== +struct GLUnurbs {} +struct GLUquadric {} +struct GLUtesselator {} + +typedef GLUnurbs GLUnurbsObj; +typedef GLUquadric GLUquadricObj; +typedef GLUtesselator GLUtesselatorObj; +typedef GLUtesselator GLUtriangulatorObj; + +extern(System) +{ + void gluOrtho2D(GLdouble,GLdouble,GLdouble,GLdouble); + void gluPerspective(GLdouble,GLdouble,GLdouble,GLdouble); + void gluLookAt(GLdouble,GLdouble,GLdouble,GLdouble,GLdouble,GLdouble,GLdouble,GLdouble,GLdouble); + GLint gluProject(GLdouble,GLdouble,GLdouble,GLdouble*,GLdouble*,GLint*,GLdouble*,GLdouble*,GLdouble*); + GLint gluUnProject(GLdouble,GLdouble,GLdouble,GLdouble*,GLdouble*,GLint*,GLdouble*,GLdouble*,GLdouble*); +} + diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qtd/Array.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qtd/Array.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,37 @@ +/** + * + * Copyright: Copyright QtD Team, 2008-2009 + * Authors: Max Samukha + * License: Boost License 1.0 +* +* Copyright QtD Team, 2008-2009 +* Distributed under the Boost Software License, Version 1.0. +* (See accompanying file boost-license-1.0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +* +*/ + +module qtd.ArrayOpsPrimitive; + +import qt.QGlobal; + +// int +private extern(C) void qtd_allocate_int_array(int[]* arr, size_t len) +{ + *arr = new int[len]; +} + +private extern(C) void qtd_assign_int_array_element(int[]* arr, size_t pos, int elem) +{ + (*arr)[pos] = elem; +} + +private extern(C) void qtd_get_int_from_array(int* arr, size_t pos, int* elem) +{ + *elem = arr[pos]; +} + +// uint +private extern(C) void qtd_allocate_uint_array(int[]* arr, size_t len) +{ + *arr = new int[len]; +} + +private extern(C) void qtd_assign_uint_array_element(int[]* arr, size_t pos, uint elem) +{ + (*arr)[pos] = elem; +} + +private extern(C) void qtd_get_uint_from_array(uint* arr, size_t pos, uint* elem) +{ + *elem = arr[pos]; +} + +// double +private extern(C) void qtd_allocate_double_array(double[]* arr, size_t len) +{ + *arr = new double[len]; +} + +private extern(C) void qtd_assign_double_array_element(double[]* arr, size_t pos, double elem) +{ + (*arr)[pos] = elem; +} + +private extern(C) void qtd_get_double_from_array(double* arr, size_t pos, double* elem) +{ + *elem = arr[pos]; +} + +// string +private extern(C) void qtd_allocate_string_array(string[]* arr, size_t len) +{ + *arr = new string[len]; +} + +private extern(C) void qtd_assign_string_array_element(string[]* arr, size_t pos, string* elem) +{ +} + +private extern(C) void* qtd_string_from_array(string[]* arr, size_t pos) +{ + return &((*arr)[pos]); +} +/* +private extern(C) void qtd_get_string_from_array(string* arr, size_t pos, char** elem, size_t* elem_size) +{ + *elem = arr[pos].ptr; + *elem_size = arr[pos].length; +} +*/ + +private extern(C) void qtd_get_string_from_array(string* arr, size_t pos, string* elem) +{ + *elem = arr[pos]; +} + +version(cpp_shared) +{ + extern (C) void qtd_core_ArrayOps_initCallBacks(void* callbacks); + + static this() { + void*[13] callbacks; + + callbacks[0] = &qtd_allocate_int_array; + callbacks[1] = &qtd_assign_int_array_element; + callbacks[2] = &qtd_get_int_from_array; + + callbacks[3] = &qtd_allocate_uint_array; + callbacks[4] = &qtd_assign_uint_array_element; + callbacks[5] = &qtd_get_uint_from_array; + + callbacks[6] = &qtd_allocate_double_array; + callbacks[7] = &qtd_assign_double_array_element; + callbacks[8] = &qtd_get_double_from_array; + + callbacks[9] = &qtd_allocate_string_array; + callbacks[10] = &qtd_assign_string_array_element; + callbacks[11] = &qtd_string_from_array; + callbacks[12] = &qtd_get_string_from_array; + + qtd_core_ArrayOps_initCallBacks(callbacks.ptr); + } +} diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qtd/Atomic.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qtd/Atomic.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,1818 @@ +/** + * The atomic module is intended to provide some basic support for lock-free + * concurrent programming. Some common operations are defined, each of which + * may be performed using the specified memory barrier or a less granular + * barrier if the hardware does not support the version requested. This + * model is based on a design by Alexander Terekhov as outlined in + * + * this thread. Another useful reference for memory ordering on modern + * architectures is this + * article by Paul McKenney. + * + * Copyright: Copyright (C) 2005-2006 Sean Kelly. All rights reserved. + * License: BSD style: $(LICENSE) + * Authors: Sean Kelly + */ +module qtd.Atomic; +//deprecated: +//////////////////////////////////////////////////////////////////////////////// +// Synchronization Options +//////////////////////////////////////////////////////////////////////////////// + + +/** + * Memory synchronization flag. If the supplied option is not available on the + * current platform then a stronger method will be used instead. + */ +enum msync +{ + raw, /// not sequenced + hlb, /// hoist-load barrier + hsb, /// hoist-store barrier + slb, /// sink-load barrier + ssb, /// sink-store barrier + acq, /// hoist-load + hoist-store barrier + rel, /// sink-load + sink-store barrier + seq, /// fully sequenced (acq + rel) +} + + +//////////////////////////////////////////////////////////////////////////////// +// Internal Type Checking +//////////////////////////////////////////////////////////////////////////////// + + +private +{ + version( D_Ddoc ) {} else + { + import std.traits; + + + template isValidAtomicType( T ) + { + const bool isValidAtomicType = T.sizeof == byte.sizeof || + T.sizeof == short.sizeof || + T.sizeof == int.sizeof || + T.sizeof == long.sizeof; + } + + + template isValidNumericType( T ) + { + const bool isValidNumericType = isIntegral!( T ) || + isPointer!( T ); + } + + + template isHoistOp( msync ms ) + { + const bool isHoistOp = ms == msync.hlb || + ms == msync.hsb || + ms == msync.acq || + ms == msync.seq; + } + + + template isSinkOp( msync ms ) + { + const bool isSinkOp = ms == msync.slb || + ms == msync.ssb || + ms == msync.rel || + ms == msync.seq; + } + } +} + + +//////////////////////////////////////////////////////////////////////////////// +// DDoc Documentation for Atomic Functions +//////////////////////////////////////////////////////////////////////////////// + + +version( D_Ddoc ) +{ + //////////////////////////////////////////////////////////////////////////// + // Atomic Load + //////////////////////////////////////////////////////////////////////////// + + + /** + * Supported msync values: + * msync.raw + * msync.hlb + * msync.acq + * msync.seq + */ + template atomicLoad( msync ms, T ) + { + /** + * Refreshes the contents of 'val' from main memory. This operation is + * both lock-free and atomic. + * + * Params: + * val = The value to load. This value must be properly aligned. + * + * Returns: + * The loaded value. + */ + T atomicLoad( ref T val ) + { + return val; + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Store + //////////////////////////////////////////////////////////////////////////// + + + /** + * Supported msync values: + * msync.raw + * msync.ssb + * msync.acq + * msync.rel + * msync.seq + */ + template atomicStore( msync ms, T ) + { + /** + * Stores 'newval' to the memory referenced by 'val'. This operation + * is both lock-free and atomic. + * + * Params: + * val = The destination variable. + * newval = The value to store. + */ + void atomicStore( ref T val, T newval ) + { + + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic StoreIf + //////////////////////////////////////////////////////////////////////////// + + + /** + * Supported msync values: + * msync.raw + * msync.ssb + * msync.acq + * msync.rel + * msync.seq + */ + template atomicStoreIf( msync ms, T ) + { + /** + * Stores 'newval' to the memory referenced by 'val' if val is equal to + * 'equalTo'. This operation is both lock-free and atomic. + * + * Params: + * val = The destination variable. + * newval = The value to store. + * equalTo = The comparison value. + * + * Returns: + * true if the store occurred, false if not. + */ + bool atomicStoreIf( ref T val, T newval, T equalTo ) + { + return false; + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Increment + //////////////////////////////////////////////////////////////////////////// + + + /** + * Supported msync values: + * msync.raw + * msync.ssb + * msync.acq + * msync.rel + * msync.seq + */ + template atomicIncrement( msync ms, T ) + { + /** + * This operation is only legal for built-in value and pointer types, + * and is equivalent to an atomic "val = val + 1" operation. This + * function exists to facilitate use of the optimized increment + * instructions provided by some architecures. If no such instruction + * exists on the target platform then the behavior will perform the + * operation using more traditional means. This operation is both + * lock-free and atomic. + * + * Params: + * val = The value to increment. + * + * Returns: + * The result of an atomicLoad of val immediately following the + * increment operation. This value is not required to be equal to the + * newly stored value. Thus, competing writes are allowed to occur + * between the increment and successive load operation. + */ + T atomicIncrement( ref T val ) + { + return val; + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Decrement + //////////////////////////////////////////////////////////////////////////// + + + /** + * Supported msync values: + * msync.raw + * msync.ssb + * msync.acq + * msync.rel + * msync.seq + */ + template atomicDecrement( msync ms, T ) + { + /** + * This operation is only legal for built-in value and pointer types, + * and is equivalent to an atomic "val = val - 1" operation. This + * function exists to facilitate use of the optimized decrement + * instructions provided by some architecures. If no such instruction + * exists on the target platform then the behavior will perform the + * operation using more traditional means. This operation is both + * lock-free and atomic. + * + * Params: + * val = The value to decrement. + * + * Returns: + * The result of an atomicLoad of val immediately following the + * increment operation. This value is not required to be equal to the + * newly stored value. Thus, competing writes are allowed to occur + * between the increment and successive load operation. + */ + T atomicDecrement( ref T val ) + { + return val; + } + } +} + + +//////////////////////////////////////////////////////////////////////////////// +// LDC Atomics Implementation +//////////////////////////////////////////////////////////////////////////////// + + +else version( LDC ) +{ + import ldc.intrinsics; + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Load + //////////////////////////////////////////////////////////////////////////// + + + template atomicLoad( msync ms = msync.seq, T ) + { + T atomicLoad(ref T val) + { + llvm_memory_barrier( + ms == msync.hlb || ms == msync.acq || ms == msync.seq, + ms == msync.hsb || ms == msync.acq || ms == msync.seq, + ms == msync.slb || ms == msync.rel || ms == msync.seq, + ms == msync.ssb || ms == msync.rel || ms == msync.seq, + false); + static if (isPointerType!(T)) + { + return cast(T)llvm_atomic_load_add!(size_t)(cast(size_t*)&val, 0); + } + else static if (is(T == bool)) + { + return llvm_atomic_load_add!(ubyte)(cast(ubyte*)&val, cast(ubyte)0) ? 1 : 0; + } + else + { + return llvm_atomic_load_add!(T)(&val, cast(T)0); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Store + //////////////////////////////////////////////////////////////////////////// + + + template atomicStore( msync ms = msync.seq, T ) + { + void atomicStore( ref T val, T newval ) + { + llvm_memory_barrier( + ms == msync.hlb || ms == msync.acq || ms == msync.seq, + ms == msync.hsb || ms == msync.acq || ms == msync.seq, + ms == msync.slb || ms == msync.rel || ms == msync.seq, + ms == msync.ssb || ms == msync.rel || ms == msync.seq, + false); + static if (isPointerType!(T)) + { + llvm_atomic_swap!(size_t)(cast(size_t*)&val, cast(size_t)newval); + } + else static if (is(T == bool)) + { + llvm_atomic_swap!(ubyte)(cast(ubyte*)&val, newval?1:0); + } + else + { + llvm_atomic_swap!(T)(&val, newval); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Store If + //////////////////////////////////////////////////////////////////////////// + + + template atomicStoreIf( msync ms = msync.seq, T ) + { + bool atomicStoreIf( ref T val, T newval, T equalTo ) + { + llvm_memory_barrier( + ms == msync.hlb || ms == msync.acq || ms == msync.seq, + ms == msync.hsb || ms == msync.acq || ms == msync.seq, + ms == msync.slb || ms == msync.rel || ms == msync.seq, + ms == msync.ssb || ms == msync.rel || ms == msync.seq, + false); + T oldval = void; + static if (isPointerType!(T)) + { + oldval = cast(T)llvm_atomic_cmp_swap!(size_t)(cast(size_t*)&val, cast(size_t)equalTo, cast(size_t)newval); + } + else static if (is(T == bool)) + { + oldval = llvm_atomic_cmp_swap!(ubyte)(cast(ubyte*)&val, equalTo?1:0, newval?1:0)?0:1; + } + else + { + oldval = llvm_atomic_cmp_swap!(T)(&val, equalTo, newval); + } + return oldval == equalTo; + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Increment + //////////////////////////////////////////////////////////////////////////// + + + template atomicIncrement( msync ms = msync.seq, T ) + { + // + // NOTE: This operation is only valid for integer or pointer types + // + static assert( isValidNumericType!(T) ); + + + T atomicIncrement( ref T val ) + { + static if (isPointerType!(T)) + { + llvm_atomic_load_add!(size_t)(cast(size_t*)&val, 1); + } + else + { + llvm_atomic_load_add!(T)(&val, cast(T)1); + } + return val; + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Decrement + //////////////////////////////////////////////////////////////////////////// + + + template atomicDecrement( msync ms = msync.seq, T ) + { + // + // NOTE: This operation is only valid for integer or pointer types + // + static assert( isValidNumericType!(T) ); + + + T atomicDecrement( ref T val ) + { + static if (isPointerType!(T)) + { + llvm_atomic_load_sub!(size_t)(cast(size_t*)&val, 1); + } + else + { + llvm_atomic_load_sub!(T)(&val, cast(T)1); + } + return val; + } + } +} + +//////////////////////////////////////////////////////////////////////////////// +// x86 Atomic Function Implementation +//////////////////////////////////////////////////////////////////////////////// + + +else version( D_InlineAsm_X86 ) +{ + version( X86 ) + { + version( BuildInfo ) + { + pragma( msg, "tango.core.Atomic: using IA-32 inline asm" ); + } + + version(darwin){ + extern(C) bool OSAtomicCompareAndSwap64(long oldValue, long newValue, long *theValue); + extern(C) bool OSAtomicCompareAndSwap64Barrier(long oldValue, long newValue, long *theValue); + } + version = Has64BitCAS; + version = Has32BitOps; + } + version( X86_64 ) + { + version( BuildInfo ) + { + pragma( msg, "tango.core.Atomic: using AMD64 inline asm" ); + } + + version = Has64BitOps; + } + + private + { + //////////////////////////////////////////////////////////////////////// + // x86 Value Requirements + //////////////////////////////////////////////////////////////////////// + + + // NOTE: Strictly speaking, the x86 supports atomic operations on + // unaligned values. However, this is far slower than the + // common case, so such behavior should be prohibited. + template atomicValueIsProperlyAligned( T ) + { + bool atomicValueIsProperlyAligned( size_t addr ) + { + return addr % T.sizeof == 0; + } + } + + + //////////////////////////////////////////////////////////////////////// + // x86 Synchronization Requirements + //////////////////////////////////////////////////////////////////////// + + + // NOTE: While x86 loads have acquire semantics for stores, it appears + // that independent loads may be reordered by some processors + // (notably the AMD64). This implies that the hoist-load barrier + // op requires an ordering instruction, which also extends this + // requirement to acquire ops (though hoist-store should not need + // one if support is added for this later). However, since no + // modern architectures will reorder dependent loads to occur + // before the load they depend on (except the Alpha), raw loads + // are actually a possible means of ordering specific sequences + // of loads in some instances. The original atomic<> + // implementation provides a 'ddhlb' ordering specifier for + // data-dependent loads to handle this situation, but as there + // are no plans to support the Alpha there is no reason to add + // that option here. + // + // For reference, the old behavior (acquire semantics for loads) + // required a memory barrier if: ms == msync.seq || isSinkOp!(ms) + template needsLoadBarrier( msync ms ) + { + const bool needsLoadBarrier = ms != msync.raw; + } + + + // NOTE: x86 stores implicitly have release semantics so a membar is only + // necessary on acquires. + template needsStoreBarrier( msync ms ) + { + const bool needsStoreBarrier = ms == msync.seq || isHoistOp!(ms); + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Load + //////////////////////////////////////////////////////////////////////////// + + + template atomicLoad( msync ms = msync.seq, T ) + { + T atomicLoad( ref T val ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof == byte.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 1 Byte Load + //////////////////////////////////////////////////////////////// + + + static if( needsLoadBarrier!(ms) ) + { + asm + { + mov DL, 42; + mov AL, 42; + mov ECX, val; + lock; + cmpxchg [ECX], DL; + } + } + else + { + synchronized + { + return val; + } + } + } + else static if( T.sizeof == short.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 2 Byte Load + //////////////////////////////////////////////////////////////// + + static if( needsLoadBarrier!(ms) ) + { + asm + { + mov DX, 42; + mov AX, 42; + mov ECX, val; + lock; + cmpxchg [ECX], DX; + } + } + else + { + synchronized + { + return val; + } + } + } + else static if( T.sizeof == int.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 4 Byte Load + //////////////////////////////////////////////////////////////// + + + static if( needsLoadBarrier!(ms) ) + { + asm + { + mov EDX, 42; + mov EAX, 42; + mov ECX, val; + lock; + cmpxchg [ECX], EDX; + } + } + else + { + synchronized + { + return val; + } + } + } + else static if( T.sizeof == long.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 8 Byte Load + //////////////////////////////////////////////////////////////// + + + version( Has64BitOps ) + { + //////////////////////////////////////////////////////////// + // 8 Byte Load on 64-Bit Processor + //////////////////////////////////////////////////////////// + + + static if( needsLoadBarrier!(ms) ) + { + asm + { + mov RAX, val; + lock; + mov RAX, [RAX]; + } + } + else + { + synchronized + { + return val; + } + } + } + else + { + //////////////////////////////////////////////////////////// + // 8 Byte Load on 32-Bit Processor + //////////////////////////////////////////////////////////// + + + pragma( msg, "This operation is only available on 64-bit platforms." ); + static assert( false ); + } + } + else + { + //////////////////////////////////////////////////////////////// + // Not a 1, 2, 4, or 8 Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Store + //////////////////////////////////////////////////////////////////////////// + + + template atomicStore( msync ms = msync.seq, T ) + { + void atomicStore( ref T val, T newval ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof == byte.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 1 Byte Store + //////////////////////////////////////////////////////////////// + + + static if( needsStoreBarrier!(ms) ) + { + asm + { + mov EAX, val; + mov DL, newval; + lock; + xchg [EAX], DL; + } + } + else + { + asm + { + mov EAX, val; + mov DL, newval; + mov [EAX], DL; + } + } + } + else static if( T.sizeof == short.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 2 Byte Store + //////////////////////////////////////////////////////////////// + + + static if( needsStoreBarrier!(ms) ) + { + asm + { + mov EAX, val; + mov DX, newval; + lock; + xchg [EAX], DX; + } + } + else + { + asm + { + mov EAX, val; + mov DX, newval; + mov [EAX], DX; + } + } + } + else static if( T.sizeof == int.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 4 Byte Store + //////////////////////////////////////////////////////////////// + + + static if( needsStoreBarrier!(ms) ) + { + asm + { + mov EAX, val; + mov EDX, newval; + lock; + xchg [EAX], EDX; + } + } + else + { + asm + { + mov EAX, val; + mov EDX, newval; + mov [EAX], EDX; + } + } + } + else static if( T.sizeof == long.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 8 Byte Store + //////////////////////////////////////////////////////////////// + + + version( Has64BitOps ) + { + //////////////////////////////////////////////////////////// + // 8 Byte Store on 64-Bit Processor + //////////////////////////////////////////////////////////// + + + static if( needsStoreBarrier!(ms) ) + { + asm + { + mov RAX, val; + mov RDX, newval; + lock; + xchg [RAX], RDX; + } + } + else + { + asm + { + mov RAX, val; + mov RDX, newval; + mov [RAX], RDX; + } + } + } + else + { + //////////////////////////////////////////////////////////// + // 8 Byte Store on 32-Bit Processor + //////////////////////////////////////////////////////////// + + + pragma( msg, "This operation is only available on 64-bit platforms." ); + static assert( false ); + } + } + else + { + //////////////////////////////////////////////////////////////// + // Not a 1, 2, 4, or 8 Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Store If + //////////////////////////////////////////////////////////////////////////// + + + template atomicStoreIf( msync ms = msync.seq, T ) + { + bool atomicStoreIf( ref T val, T newval, T equalTo ) + in + { + // NOTE: 32 bit x86 systems support 8 byte CAS, which only requires + // 4 byte alignment, so use size_t as the align type here. + static if( T.sizeof > size_t.sizeof ) + assert( atomicValueIsProperlyAligned!(size_t)( cast(size_t) &val ) ); + else + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof == byte.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 1 Byte StoreIf + //////////////////////////////////////////////////////////////// + + + asm + { + mov DL, newval; + mov AL, equalTo; + mov ECX, val; + lock; // lock always needed to make this op atomic + cmpxchg [ECX], DL; + setz AL; + } + } + else static if( T.sizeof == short.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 2 Byte StoreIf + //////////////////////////////////////////////////////////////// + + + asm + { + mov DX, newval; + mov AX, equalTo; + mov ECX, val; + lock; // lock always needed to make this op atomic + cmpxchg [ECX], DX; + setz AL; + } + } + else static if( T.sizeof == int.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 4 Byte StoreIf + //////////////////////////////////////////////////////////////// + + + asm + { + mov EDX, newval; + mov EAX, equalTo; + mov ECX, val; + lock; // lock always needed to make this op atomic + cmpxchg [ECX], EDX; + setz AL; + } + } + else static if( T.sizeof == long.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 8 Byte StoreIf + //////////////////////////////////////////////////////////////// + + + version( Has64BitOps ) + { + //////////////////////////////////////////////////////////// + // 8 Byte StoreIf on 64-Bit Processor + //////////////////////////////////////////////////////////// + + + asm + { + mov RDX, newval; + mov RAX, equalTo; + mov RCX, val; + lock; // lock always needed to make this op atomic + cmpxchg [RCX], RDX; + setz AL; + } + } + else version( Has64BitCAS ) + { + //////////////////////////////////////////////////////////// + // 8 Byte StoreIf on 32-Bit Processor + //////////////////////////////////////////////////////////// + version(darwin){ + static if(ms==msync.raw){ + return OSAtomicCompareAndSwap64(cast(long)equalTo, cast(long)newval, cast(long*)&val); + } else { + return OSAtomicCompareAndSwap64Barrier(cast(long)equalTo, cast(long)newval, cast(long*)&val); + } + } else { + asm + { + push EDI; + push EBX; + lea EDI, newval; + mov EBX, [EDI]; + mov ECX, 4[EDI]; + lea EDI, equalTo; + mov EAX, [EDI]; + mov EDX, 4[EDI]; + mov EDI, val; + lock; // lock always needed to make this op atomic + cmpxch8b [EDI]; + setz AL; + pop EBX; + pop EDI; + } + } + } + } + else + { + //////////////////////////////////////////////////////////////// + // Not a 1, 2, 4, or 8 Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Increment + //////////////////////////////////////////////////////////////////////////// + + + template atomicIncrement( msync ms = msync.seq, T ) + { + // + // NOTE: This operation is only valid for integer or pointer types + // + static assert( isValidNumericType!(T) ); + + + T atomicIncrement( ref T val ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof == byte.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 1 Byte Increment + //////////////////////////////////////////////////////////////// + + + asm + { + mov EAX, val; + lock; // lock always needed to make this op atomic + inc [EAX]; + mov AL, [EAX]; + } + } + else static if( T.sizeof == short.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 2 Byte Increment + //////////////////////////////////////////////////////////////// + + + asm + { + mov EAX, val; + lock; // lock always needed to make this op atomic + inc short ptr [EAX]; + mov AX, [EAX]; + } + } + else static if( T.sizeof == int.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 4 Byte Increment + //////////////////////////////////////////////////////////////// + + + asm + { + mov EAX, val; + lock; // lock always needed to make this op atomic + inc int ptr [EAX]; + mov EAX, [EAX]; + } + } + else static if( T.sizeof == long.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 8 Byte Increment + //////////////////////////////////////////////////////////////// + + + version( Has64BitOps ) + { + //////////////////////////////////////////////////////////// + // 8 Byte Increment on 64-Bit Processor + //////////////////////////////////////////////////////////// + + + asm + { + mov RAX, val; + lock; // lock always needed to make this op atomic + inc qword ptr [RAX]; + mov RAX, [RAX]; + } + } + else + { + //////////////////////////////////////////////////////////// + // 8 Byte Increment on 32-Bit Processor + //////////////////////////////////////////////////////////// + + + pragma( msg, "This operation is only available on 64-bit platforms." ); + static assert( false ); + } + } + else + { + //////////////////////////////////////////////////////////////// + // Not a 1, 2, 4, or 8 Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Decrement + //////////////////////////////////////////////////////////////////////////// + + + template atomicDecrement( msync ms = msync.seq, T ) + { + // + // NOTE: This operation is only valid for integer or pointer types + // + static assert( isValidNumericType!(T) ); + + + T atomicDecrement( ref T val ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof == byte.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 1 Byte Decrement + //////////////////////////////////////////////////////////////// + + + asm + { + mov EAX, val; + lock; // lock always needed to make this op atomic + dec [EAX]; + mov AL, [EAX]; + } + } + else static if( T.sizeof == short.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 2 Byte Decrement + //////////////////////////////////////////////////////////////// + + + asm + { + mov EAX, val; + lock; // lock always needed to make this op atomic + dec short ptr [EAX]; + mov AX, [EAX]; + } + } + else static if( T.sizeof == int.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 4 Byte Decrement + //////////////////////////////////////////////////////////////// + + + asm + { + mov EAX, val; + lock; // lock always needed to make this op atomic + dec int ptr [EAX]; + mov EAX, [EAX]; + } + } + else static if( T.sizeof == long.sizeof ) + { + //////////////////////////////////////////////////////////////// + // 8 Byte Decrement + //////////////////////////////////////////////////////////////// + + + version( Has64BitOps ) + { + //////////////////////////////////////////////////////////// + // 8 Byte Decrement on 64-Bit Processor + //////////////////////////////////////////////////////////// + + + asm + { + mov RAX, val; + lock; // lock always needed to make this op atomic + dec qword ptr [RAX]; + mov RAX, [RAX]; + } + } + else + { + //////////////////////////////////////////////////////////// + // 8 Byte Decrement on 32-Bit Processor + //////////////////////////////////////////////////////////// + + + pragma( msg, "This operation is only available on 64-bit platforms." ); + static assert( false ); + } + } + else + { + //////////////////////////////////////////////////////////////// + // Not a 1, 2, 4, or 8 Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } +} +else +{ + version( BuildInfo ) + { + pragma( msg, "tango.core.Atomic: using synchronized ops" ); + } + + private + { + //////////////////////////////////////////////////////////////////////// + // Default Value Requirements + //////////////////////////////////////////////////////////////////////// + + + template atomicValueIsProperlyAligned( T ) + { + bool atomicValueIsProperlyAligned( size_t addr ) + { + return addr % T.sizeof == 0; + } + } + + + //////////////////////////////////////////////////////////////////////// + // Default Synchronization Requirements + //////////////////////////////////////////////////////////////////////// + + + template needsLoadBarrier( msync ms ) + { + const bool needsLoadBarrier = ms != msync.raw; + } + + + template needsStoreBarrier( msync ms ) + { + const bool needsStoreBarrier = ms != msync.raw; + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Load + //////////////////////////////////////////////////////////////////////////// + + + template atomicLoad( msync ms = msync.seq, T ) + { + T atomicLoad( ref T val ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof <= (void*).sizeof ) + { + //////////////////////////////////////////////////////////////// + // <= (void*).sizeof Byte Load + //////////////////////////////////////////////////////////////// + + + static if( needsLoadBarrier!(ms) ) + { + synchronized + { + return val; + } + } + else + { + synchronized + { + return val; + } + } + } + else + { + //////////////////////////////////////////////////////////////// + // > (void*).sizeof Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Store + //////////////////////////////////////////////////////////////////////////// + + + template atomicStore( msync ms = msync.seq, T ) + { + void atomicStore( ref T val, T newval ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof <= (void*).sizeof ) + { + //////////////////////////////////////////////////////////////// + // <= (void*).sizeof Byte Store + //////////////////////////////////////////////////////////////// + + + static if( needsStoreBarrier!(ms) ) + { + synchronized + { + val = newval; + } + } + else + { + synchronized + { + val = newval; + } + } + } + else + { + //////////////////////////////////////////////////////////////// + // > (void*).sizeof Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Store If + //////////////////////////////////////////////////////////////////////////// + + + template atomicStoreIf( msync ms = msync.seq, T ) + { + bool atomicStoreIf( ref T val, T newval, T equalTo ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof <= (void*).sizeof ) + { + //////////////////////////////////////////////////////////////// + // <= (void*).sizeof Byte StoreIf + //////////////////////////////////////////////////////////////// + + + synchronized + { + if( val == equalTo ) + { + val = newval; + return true; + } + return false; + } + } + else + { + //////////////////////////////////////////////////////////////// + // > (void*).sizeof Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } + + + ///////////////////////////////////////////////////////////////////////////// + // Atomic Increment + //////////////////////////////////////////////////////////////////////////// + + + template atomicIncrement( msync ms = msync.seq, T ) + { + // + // NOTE: This operation is only valid for integer or pointer types + // + static assert( isValidNumericType!(T) ); + + + T atomicIncrement( ref T val ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof <= (void*).sizeof ) + { + //////////////////////////////////////////////////////////////// + // <= (void*).sizeof Byte Increment + //////////////////////////////////////////////////////////////// + + + synchronized + { + return ++val; + } + } + else + { + //////////////////////////////////////////////////////////////// + // > (void*).sizeof Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Decrement + //////////////////////////////////////////////////////////////////////////// + + + template atomicDecrement( msync ms = msync.seq, T ) + { + // + // NOTE: This operation is only valid for integer or pointer types + // + static assert( isValidNumericType!(T) ); + + + T atomicDecrement( ref T val ) + in + { + assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); + } + body + { + static if( T.sizeof <= (void*).sizeof ) + { + //////////////////////////////////////////////////////////////// + // <= (void*).sizeof Byte Decrement + //////////////////////////////////////////////////////////////// + + + synchronized + { + return --val; + } + } + else + { + //////////////////////////////////////////////////////////////// + // > (void*).sizeof Byte Type + //////////////////////////////////////////////////////////////// + + + pragma( msg, "Invalid template type specified." ); + static assert( false ); + } + } + } +} + + +//////////////////////////////////////////////////////////////////////////////// +// Atomic +//////////////////////////////////////////////////////////////////////////////// + + +/** + * This struct represents a value which will be subject to competing access. + * All accesses to this value will be synchronized with main memory, and + * various memory barriers may be employed for instruction ordering. Any + * primitive type of size equal to or smaller than the memory bus size is + * allowed, so 32-bit machines may use values with size <= int.sizeof and + * 64-bit machines may use values with size <= long.sizeof. The one exception + * to this rule is that architectures that support DCAS will allow double-wide + * storeIf operations. The 32-bit x86 architecture, for example, supports + * 64-bit storeIf operations. + */ +struct Atomic( T ) +{ + //////////////////////////////////////////////////////////////////////////// + // Atomic Load + //////////////////////////////////////////////////////////////////////////// + + + template load( msync ms = msync.seq ) + { + static assert( ms == msync.raw || ms == msync.hlb || + ms == msync.acq || ms == msync.seq, + "ms must be one of: msync.raw, msync.hlb, msync.acq, msync.seq" ); + + /** + * Refreshes the contents of this value from main memory. This + * operation is both lock-free and atomic. + * + * Returns: + * The loaded value. + */ + T load() + { + return atomicLoad!(ms,T)( m_val ); + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic Store + //////////////////////////////////////////////////////////////////////////// + + + template store( msync ms = msync.seq ) + { + static assert( ms == msync.raw || ms == msync.ssb || + ms == msync.acq || ms == msync.rel || + ms == msync.seq, + "ms must be one of: msync.raw, msync.ssb, msync.acq, msync.rel, msync.seq" ); + + /** + * Stores 'newval' to the memory referenced by this value. This + * operation is both lock-free and atomic. + * + * Params: + * newval = The value to store. + */ + void store( T newval ) + { + atomicStore!(ms,T)( m_val, newval ); + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Atomic StoreIf + //////////////////////////////////////////////////////////////////////////// + + + template storeIf( msync ms = msync.seq ) + { + static assert( ms == msync.raw || ms == msync.ssb || + ms == msync.acq || ms == msync.rel || + ms == msync.seq, + "ms must be one of: msync.raw, msync.ssb, msync.acq, msync.rel, msync.seq" ); + + /** + * Stores 'newval' to the memory referenced by this value if val is + * equal to 'equalTo'. This operation is both lock-free and atomic. + * + * Params: + * newval = The value to store. + * equalTo = The comparison value. + * + * Returns: + * true if the store occurred, false if not. + */ + bool storeIf( T newval, T equalTo ) + { + return atomicStoreIf!(ms,T)( m_val, newval, equalTo ); + } + } + + + //////////////////////////////////////////////////////////////////////////// + // Numeric Functions + //////////////////////////////////////////////////////////////////////////// + + + /** + * The following additional functions are available for integer types. + */ + static if( isValidNumericType!(T) ) + { + //////////////////////////////////////////////////////////////////////// + // Atomic Increment + //////////////////////////////////////////////////////////////////////// + + + template increment( msync ms = msync.seq ) + { + static assert( ms == msync.raw || ms == msync.ssb || + ms == msync.acq || ms == msync.rel || + ms == msync.seq, + "ms must be one of: msync.raw, msync.ssb, msync.acq, msync.rel, msync.seq" ); + + /** + * This operation is only legal for built-in value and pointer + * types, and is equivalent to an atomic "val = val + 1" operation. + * This function exists to facilitate use of the optimized + * increment instructions provided by some architecures. If no + * such instruction exists on the target platform then the + * behavior will perform the operation using more traditional + * means. This operation is both lock-free and atomic. + * + * Returns: + * The result of an atomicLoad of val immediately following the + * increment operation. This value is not required to be equal to + * the newly stored value. Thus, competing writes are allowed to + * occur between the increment and successive load operation. + */ + T increment() + { + return atomicIncrement!(ms,T)( m_val ); + } + } + + + //////////////////////////////////////////////////////////////////////// + // Atomic Decrement + //////////////////////////////////////////////////////////////////////// + + + template decrement( msync ms = msync.seq ) + { + static assert( ms == msync.raw || ms == msync.ssb || + ms == msync.acq || ms == msync.rel || + ms == msync.seq, + "ms must be one of: msync.raw, msync.ssb, msync.acq, msync.rel, msync.seq" ); + + /** + * This operation is only legal for built-in value and pointer + * types, and is equivalent to an atomic "val = val - 1" operation. + * This function exists to facilitate use of the optimized + * decrement instructions provided by some architecures. If no + * such instruction exists on the target platform then the behavior + * will perform the operation using more traditional means. This + * operation is both lock-free and atomic. + * + * Returns: + * The result of an atomicLoad of val immediately following the + * increment operation. This value is not required to be equal to + * the newly stored value. Thus, competing writes are allowed to + * occur between the increment and successive load operation. + */ + T decrement() + { + return atomicDecrement!(ms,T)( m_val ); + } + } + } + +private: + T m_val; +} + + +//////////////////////////////////////////////////////////////////////////////// +// Support Code for Unit Tests +//////////////////////////////////////////////////////////////////////////////// + + +private +{ + version( D_Ddoc ) {} else + { + template testLoad( msync ms, T ) + { + void testLoad( T val = T.init + 1 ) + { + T base; + Atomic!(T) atom; + + assert( atom.load!(ms)() == base ); + base = val; + atom.m_val = val; + assert( atom.load!(ms)() == base ); + } + } + + + template testStore( msync ms, T ) + { + void testStore( T val = T.init + 1 ) + { + T base; + Atomic!(T) atom; + + assert( atom.m_val == base ); + base = val; + atom.store!(ms)( base ); + assert( atom.m_val == base ); + } + } + + + template testStoreIf( msync ms, T ) + { + void testStoreIf( T val = T.init + 1 ) + { + T base; + Atomic!(T) atom; + + assert( atom.m_val == base ); + base = val; + atom.storeIf!(ms)( base, val ); + assert( atom.m_val != base ); + atom.storeIf!(ms)( base, T.init ); + assert( atom.m_val == base ); + } + } + + + template testIncrement( msync ms, T ) + { + void testIncrement( T val = T.init + 1 ) + { + T base = val; + T incr = val; + Atomic!(T) atom; + + atom.m_val = val; + assert( atom.m_val == base && incr == base ); + base = cast(T)( base + 1 ); + incr = atom.increment!(ms)(); + assert( atom.m_val == base && incr == base ); + } + } + + + template testDecrement( msync ms, T ) + { + void testDecrement( T val = T.init + 1 ) + { + T base = val; + T decr = val; + Atomic!(T) atom; + + atom.m_val = val; + assert( atom.m_val == base && decr == base ); + base = cast(T)( base - 1 ); + decr = atom.decrement!(ms)(); + assert( atom.m_val == base && decr == base ); + } + } + + + template testType( T ) + { + void testType( T val = T.init +1 ) + { + testLoad!(msync.raw, T)( val ); + testLoad!(msync.hlb, T)( val ); + testLoad!(msync.acq, T)( val ); + testLoad!(msync.seq, T)( val ); + + testStore!(msync.raw, T)( val ); + testStore!(msync.ssb, T)( val ); + testStore!(msync.acq, T)( val ); + testStore!(msync.rel, T)( val ); + testStore!(msync.seq, T)( val ); + + testStoreIf!(msync.raw, T)( val ); + testStoreIf!(msync.ssb, T)( val ); + testStoreIf!(msync.acq, T)( val ); + testStoreIf!(msync.rel, T)( val ); + testStoreIf!(msync.seq, T)( val ); + + static if( isValidNumericType!(T) ) + { + testIncrement!(msync.raw, T)( val ); + testIncrement!(msync.ssb, T)( val ); + testIncrement!(msync.acq, T)( val ); + testIncrement!(msync.rel, T)( val ); + testIncrement!(msync.seq, T)( val ); + + testDecrement!(msync.raw, T)( val ); + testDecrement!(msync.ssb, T)( val ); + testDecrement!(msync.acq, T)( val ); + testDecrement!(msync.rel, T)( val ); + testDecrement!(msync.seq, T)( val ); + } + } + } + } +} + + +//////////////////////////////////////////////////////////////////////////////// +// Unit Tests +//////////////////////////////////////////////////////////////////////////////// + + +debug( UnitTest ) +{ + unittest + { + testType!(bool)(); + + testType!(byte)(); + testType!(ubyte)(); + + testType!(short)(); + testType!(ushort)(); + + testType!(int)(); + testType!(uint)(); + + int x; + testType!(void*)( &x ); + + version( Has64BitOps ) + { + testType!(long)(); + testType!(ulong)(); + } + else version( Has64BitCAS ) + { + testStoreIf!(msync.raw, long)(); + testStoreIf!(msync.ssb, long)(); + testStoreIf!(msync.acq, long)(); + testStoreIf!(msync.rel, long)(); + testStoreIf!(msync.seq, long)(); + + testStoreIf!(msync.raw, ulong)(); + testStoreIf!(msync.ssb, ulong)(); + testStoreIf!(msync.acq, ulong)(); + testStoreIf!(msync.rel, ulong)(); + testStoreIf!(msync.seq, ulong)(); + } + } +} diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qtd/CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qtd/CMakeLists.txt Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,3 @@ +set(QT_QTD_SRCS_D +Str.d +) diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qtd/MOC.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qtd/MOC.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,560 @@ +module qtd.MOC; + +import std.typetuple; + +import qt.QGlobal; +import qtd.Signal; +import qtd.MetaMarshall; +import qtd.Meta; +import qtd.ctfe.Format; + +public import qt.core.QString; + +public import std.traits; +/** + Utils. + */ + +bool is_digit_char(const char s) +{ + return (s >= '0' && s <= '9'); +} + +bool is_octal_char(const char s) +{ + return (s >= '0' && s <= '7'); +} + +bool is_hex_char(const char s) +{ + return ((s >= 'a' && s <= 'f') + || (s >= 'A' && s <= 'F') + || (s >= '0' && s <= '9') + ); +} + +int lastIndexOf(T)(T[] haystack, T[] needle, int from = -1) +{ + auto l = haystack.length; + auto ol = needle.length; + int delta = l - ol; + if (from < 0) + from = delta; + if (from < 0 || from > l) + return -1; + if (from > delta) + from = delta; + + while(from >= 0) + { + if (haystack[from..from+ol] == needle) + return from; + from--; + } + return -1; +} + + +T[] newArray(T)(size_t len, T[] from = []) +{ + if (len == from.length) + return from; + + if (!from.length) + from = [T.init]; + + if (from.length < len) + return newArray!T(len, from ~ from); + + return from[0..len]; +} + +string replicate(int n, char value) +{ + char[] ret = "".dup; + if (n > 0) + { +// ret = newArray!char(n); + for(int i = 0; i < n; i++) + ret ~= value; + } + return cast(string)ret; +} + +/** + CTFE MOC port. + */ + +enum MethodFlags { + AccessPrivate = 0x00, + AccessProtected = 0x01, + AccessPublic = 0x02, + MethodMethod = 0x00, + MethodSignal = 0x04, + MethodSlot = 0x08, + MethodConstructor = 0x0c, + MethodCompatibility = 0x10, + MethodCloned = 0x20, + MethodScriptable = 0x40 +} + +enum Access { Private, Protected, Public } + +struct FunctionDef +{ +/* FunctionDef(): returnTypeIsVolatile(false), access(Private), isConst(false), isVirtual(false), + inlineCode(false), wasCloned(false), isCompat(false), isInvokable(false), + isScriptable(false), isSlot(false), isSignal(false), + isConstructor(false), isDestructor(false), isAbstract(false) {} + */ +// Type type; +// string normalizedType; +// string tag; +// string name; + string sig; + string arguments; + Access access; +/* bool returnTypeIsVolatile; + + QList arguments; + + enum Access { Private, Protected, Public }; + bool isConst; + bool isVirtual; + bool inlineCode; + bool wasCloned; + + QByteArray inPrivateClass; + bool isCompat; + bool isInvokable; + bool isScriptable; + bool isSlot; + bool isSignal; + bool isConstructor; + bool isDestructor; + bool isAbstract; + */ +} + +FunctionDef newSlot(string sig, string args) +{ + return FunctionDef(sig, args, Access.Public); +} + +FunctionDef newSignal(string sig, string args) +{ + return FunctionDef(sig, args, Access.Protected); +} + +struct Generator +{ + string output; + string[] strings; +// QByteArray purestSuperClass; +// QList metaTypes; +} + +int lengthOfEscapeSequence(string s, uint i) +{ + if (s[i] != '\\' || i >= s.length - 1) + return 1; + const int startPos = i; + ++i; + auto ch = s[i]; + if (ch == 'x') { + ++i; + while (i < s.length && is_hex_char(s[i])) + ++i; + } else if (is_octal_char(ch)) { + while (i < startPos + 4 + && i < s.length + && is_octal_char(s[i])) { + ++i; + } + } else { // single character escape sequence + i = qMin(i + 1, s.length); + } + return i - startPos; +} + +int strreg(ref Generator gen, string s) +{ + int idx = 0; + foreach (str; gen.strings) { + if (str == s) + return idx; + idx += str.length + 1; + foreach (i, c; str) { + if (c == '\\') { + int cnt = lengthOfEscapeSequence(str, i) - 1; + idx -= cnt; + i += cnt; + } + } + } + gen.strings ~= s; + return idx; +} + +void generateFunctions(ref Generator gen, FunctionDef[] list, string functype, byte type) +{ + if (!list.length) + return; + gen.output ~= format_ctfe("\n // ${}s: signature, parameters, type, tag, flags\n", functype); + + foreach (i, f; list) { + byte flags = type; + + if (f.access == Access.Private) + flags |= MethodFlags.AccessPrivate; + else if (f.access == Access.Public) + flags |= MethodFlags.AccessPublic; + else if (f.access == Access.Protected) + flags |= MethodFlags.AccessProtected; + + gen.output ~= format_ctfe(" ${}, ${}, ${}, ${}, 0x${:x},\n", strreg(gen, f.sig), + strreg(gen, f.arguments), strreg(gen, ""/*f.normalizedType*/), strreg(gen, ""/*f.tag*/), flags); + } +} + +string generateCode(string className, FunctionDef[] signalList, FunctionDef[] slotList) +{ + auto gen = Generator("", []); + +/* bool isQt = (cdef->classname == "Qt"); + bool isQObject = (cdef->classname == "QObject"); + bool isConstructible = !cdef->constructorList.isEmpty(); + +// +// build the data array +// + int i = 0; + + + // filter out undeclared enumerators and sets + { + QList enumList; + for (i = 0; i < cdef->enumList.count(); ++i) { + EnumDef def = cdef->enumList.at(i); + if (cdef->enumDeclarations.contains(def.name)) { + enumList += def; + } + QByteArray alias = cdef->flagAliases.value(def.name); + if (cdef->enumDeclarations.contains(alias)) { + def.name = alias; + enumList += def; + } + } + cdef->enumList = enumList; + } + + + QByteArray qualifiedClassNameIdentifier = cdef->qualified; + qualifiedClassNameIdentifier.replace(':', '_'); +*/ + bool isConstructible = false; + + FunctionDef[] propertyList, enumList, constructorList; + int index = 12; + gen.output ~= format_ctfe("static const uint[] qt_meta_data_${} = [\n", className); + gen.output ~= format_ctfe("\n // content:\n"); + gen.output ~= format_ctfe(" ${}, // revision\n", 2); + gen.output ~= format_ctfe(" ${}, // classname\n", strreg(gen, className)); + gen.output ~= format_ctfe(" ${}, ${}, // classinfo\n", 0, 0); +// index += cdef->classInfoList.count() * 2; + + int methodCount = signalList.length + slotList.length;// + cdef->methodList.count(); + gen.output ~= format_ctfe(" ${}, ${}, // methods\n", methodCount, methodCount ? index : 0); + index += methodCount * 5; + gen.output ~= format_ctfe(" ${}, ${}, // properties\n", propertyList.length, propertyList.length ? index : 0); + index += propertyList.length * 3; +// if(cdef->notifyableProperties) +// index += cdef->propertyList.count(); + gen.output ~= format_ctfe(" ${}, ${}, // enums/sets\n", enumList.length, enumList.length ? index : 0); + +// int enumsIndex = index; +// for (i = 0; i < cdef->enumList.count(); ++i) +// index += 4 + (cdef->enumList.at(i).values.count() * 2); + gen.output ~= format_ctfe(" ${}, ${}, // constructors\n", isConstructible ? constructorList.length : 0, + isConstructible ? index : 0); + +// +// Build classinfo array +// +// generateClassInfos(); + +// +// Build signals array first, otherwise the signal indices would be wrong +// + generateFunctions(gen, signalList, "signal", MethodFlags.MethodSignal); + +// +// Build slots array +// + generateFunctions(gen, slotList, "slot", MethodFlags.MethodSlot); + +// +// Build method array +// +// generateFunctions(cdef->methodList, "method", MethodMethod); + + +// +// Build property array +// +// generateProperties(); + +// +// Build enums array +// +// generateEnums(enumsIndex); + +// +// Build constructors array +// +// if (isConstructible) +// generateFunctions(cdef->constructorList, "constructor", MethodConstructor); + +// +// Terminate data array +// + gen.output ~= format_ctfe("\n 0 // eod\n];\n\n"); + +// +// Build stringdata array +// + gen.output ~= format_ctfe("static const string qt_meta_stringdata_${} = \n", className); + gen.output ~= format_ctfe(" \""); + int col = 0; + int len = 0; + foreach (i, s; gen.strings) { + len = s.length; + if (col && col + len >= 72) { + gen.output ~= format_ctfe("\"\n \""); + col = 0; + } else if (len && s[0] >= '0' && s[0] <= '9') { + gen.output ~= format_ctfe("\"\""); + len += 2; + } + int idx = 0; + while (idx < s.length) { + if (idx > 0) { + col = 0; + gen.output ~= format_ctfe("\"\n \""); + } + int spanLen = qMin(cast(uint)70, s.length - idx); + // don't cut escape sequences at the end of a line + int backSlashPos = s.lastIndexOf("\\", idx + spanLen - 1); + if (backSlashPos >= idx) { + int escapeLen = lengthOfEscapeSequence(s, backSlashPos); + spanLen = qBound(spanLen, backSlashPos + escapeLen - idx, cast(int)(s.length - idx)); + } + gen.output ~= s[idx..idx+spanLen]; + idx += spanLen; + col += spanLen; + } + + gen.output ~= "\\0"; + col += len + 2; + } + gen.output ~= "\";\n\n"; + + return gen.output; +} + +string metaCallArgs(Args...)() +{ + string res; + foreach(i, _; Args) { + if (i > 0) + res ~= ","; + res ~= metaCallArgument!(Args[i])("_a[" ~ __toString(i+1) ~ "]"); + } + return res; +} + +string qtDeclArgs(Args...)() +{ + string ret; + foreach(i, _; Args) + { + if(i > 0) + ret ~= ","; + ret ~= qtDeclArg!(Args[i]); + } + return ret; +} + +string generate_qt_metacall(alias Signals, alias Slots)() +{ + string res = " +protected int qt_metacall(QMetaObject.Call _c, int _id, void **_a) + { + _id = super.qt_metacall(_c, _id, _a); + if (_id < 0) + return _id;\n"; + + alias TypeTuple!(Signals.at, Slots.at) Methods; + enum methodCount = Methods.length; + if(methodCount) + { + res ~= " + if (_c == QMetaObject.Call.InvokeMetaMethod) { + switch (_id) {"; + foreach(i, _; Repeat!(void, methodCount)) { + res ~= " + case " ~ __toString(i) ~ ": " ~ MetaEntryName!(Methods[i].at) ~ "(" ~ metaCallArgs!(MetaEntryArgs!(Methods[i].at))() ~ "); break;"; + } + res ~= "\n default: ;\n }\n"; + res ~= " _id -= " ~ __toString(methodCount) ~ ";"; + res ~= "\n }"; + } + + res ~= "\n return _id; + }"; + return res; +} + +string dDeclArgs(Args...)() +{ + string ret; + foreach(i, _; Args) + { + if (i > 0) + ret ~= ", "; + ret ~= fullDName!(Args[i]); + } + return ret; +} +string genMetaMethodsConstr(alias Funcs)(string className) +{ + string res; + enum funcsCount = Funcs.at.length; + foreach(i, bogus; Repeat!(void, funcsCount)) + { + res ~= " index++;\n" ~ + " _staticMetaObject.addMethod(new " ~ className ~ "(signature!(" ~ dDeclArgs!(MetaEntryArgs!(Funcs.at[i].at))()~ ")(\"" ~ MetaEntryName!(Funcs.at[i].at) ~ "\"), index));\n\n"; + } + return res; +} +string generateMetaObjectConstruction(alias Signals, alias Slots)() +{ + string res; + res ~= "\n + private static void _populateMetaInfo() { + alias BaseClassesTuple!(typeof(this))[0] BaseClass; + int index = BaseClass.staticMetaObject().methodCount() - 1;\n\n"; + + res ~= genMetaMethodsConstr!(Signals)("QMetaSignal"); + res ~= genMetaMethodsConstr!(Slots)("QMetaSlot"); + + res ~= " + }\n"; + return res; +} + +string generateQMetaObject(string className) +{ + string res; + res ~= " + public QMetaObject metaObject() { return staticMetaObject(); } + private static __gshared QMetaObject _staticMetaObject; + private static __gshared QMetaObjectNative _nativeStaticMetaObject; + public static QMetaObject staticMetaObject() + { + if(!_staticMetaObject) + createStaticMetaObject(); + return _staticMetaObject; + } + protected static void createStaticMetaObject() { + assert(!_staticMetaObject); + alias BaseClassesTuple!(typeof(this))[0] BaseClass; + if (!BaseClass._staticMetaObject) + BaseClass.createStaticMetaObject; + auto base = BaseClass._staticMetaObject; + _nativeStaticMetaObject = QMetaObjectNative(base.nativeId, qt_meta_stringdata_" ~ className ~ ".ptr, + qt_meta_data_" ~ className ~ ".ptr, null ); + + _staticMetaObject = new QMetaObject(&_nativeStaticMetaObject, base); +// _staticMetaObject.construct!(typeof(this)); + _populateMetaInfo(); + }\n\n"; + return res; +} + +size_t commaCount(int argCount) +{ + size_t ret = 0; + if(argCount > 1) + ret = argCount - 1; + return ret; +} + +FunctionDef[] genFuncDefs(alias Funcs, alias newFunc)() +{ + typeof(return) res; + enum funcsCount = Funcs.at.length; + foreach(i, bogus; Repeat!(void, funcsCount)) + { + string args = replicate(commaCount((MetaEntryArgs!(Funcs.at[i].at)).length), ','); + string funcSig = MetaEntryName!(Funcs.at[i].at) ~ "(" ~ qtDeclArgs!(MetaEntryArgs!(Funcs.at[i].at))() ~ ")"; + res ~= newFunc(funcSig, args); + } + return res; +} + +template Q_OBJECT_BIND() +{ +} + +// ------------------------------------------------------------------------------------------ + +string generateSignalEmitters(alias Funcs)() +{ + string res; + enum funcsCount = Funcs.at.length; + foreach(i, bogus; Repeat!(void, funcsCount)) + { + res ~= SignalEmitter!(MetaEntryArgs!(Funcs.at[i].at))(SignalType.NewSignal, MetaEntryName!(Funcs.at[i].at), cast(string[])[], i); + } + return res; +} + +string generateSlotAliases(alias Funcs)() +{ + string res; + enum funcsCount = Funcs.at.length; + foreach(i, bogus; Repeat!(void, funcsCount)) + { + string name = MetaEntryName!(Funcs.at[i].at); + res ~= format_ctfe(" alias slot_${} ${};\n", name, name); + } + return res; +} + + +string generateMetaInfo(T, alias Signals, alias Slots)() +{ + string res = ""; + auto signalList = genFuncDefs!(Signals, newSignal)(); + auto slotList = genFuncDefs!(Slots, newSlot)(); + res ~= generateSignalEmitters!(Signals)(); + res ~= generateSlotAliases!(Slots)(); + res ~= generateCode(T.stringof, signalList, slotList); + res ~= generate_qt_metacall!(Signals, Slots); + res ~= generateMetaObjectConstruction!(Signals, Slots); + res ~= generateQMetaObject(T.stringof); + return res; +} + +template Q_OBJECT() +{ + alias findSignals!(typeof(this)) SignalFuncs; + alias toMetaEntries!(SignalFuncs) SignalMetaEntries; + alias findSlots!(typeof(this)) SlotFuncs; + alias toMetaEntries!(SlotFuncs) SlotMetaEntries; + + mixin(generateMetaInfo!(typeof(this), SignalMetaEntries, SlotMetaEntries)()); + // debug output +// pragma(msg, generateMetaInfo!(typeof(this), SignalMetaEntries, SlotMetaEntries)()); +} diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qtd/Meta.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qtd/Meta.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,113 @@ +module qtd.Meta; + +import std.traits; +import std.typetuple; +import std.string; + +// Various compile time utilities + +public bool ctfeStartsWith(T)(T[] source, T[] pattern) +{ + return source.length >= pattern.length && source[0 .. pattern.length] == pattern[]; +} + +// compile-time toString, maybe to!string is already working in CT +string __toString(long v) +{ + if (v == 0) + return "0"; + + string ret; + + bool neg; + if (v < 0) + { + neg = true; + v = -v; + } + + while (v != 0) + { + ret = cast(char)(v % 10 + '0') ~ ret; + v = cast(long)(v / 10); + } + + if (neg) + ret = "-" ~ ret; + + return ret; +} + +// returns the type of a template parameter if there is one +template templateParam(U : V!(U), alias V) +{ + alias U templateParam; +} + +// to workaround buggy foreach, returns a tuple of Ts of size I +template Repeat(T, int I) +{ + static if (!I) alias TypeTuple!() Repeat; + else alias TypeTuple!(T, Repeat!(T, I - 1)) Repeat; +} + +//returns number of required function arguments, optional arguments excluded +int requiredArgCount(alias fn)() { + alias ParameterTypeTuple!(typeof(&fn)) P; + P p; + static if (P.length == 0) + return 0; + + foreach(i, _; P) + { + static if (!__traits(compiles, fn(p[0..$-i-1]))) + { + return p.length - i; + } + } + return 0; +} + +template isDg(Dg) +{ + enum isDg = is(Dg == delegate); +} + +template isFn(Fn) +{ + enum isFn = is(typeof(*Fn.init) == function); +} + +template isFnOrDg(Dg) +{ + enum isFnOrDg = isFn!(Dg) || isDg!(Dg); +} + +uint isModule(string str) +{ + return startsWith(str, "module "); +} + +template qualifiedCppName(T) +{ + static if(!isModule(__traits(parent, T).stringof)) + enum qualifiedCppName = qualifiedCppName!(__traits(parent, T)) ~ "::" ~ T.stringof; + else + enum qualifiedCppName = T.stringof; +} + +template qualifiedDName(T) +{ + static if (!isModule(__traits(parent, T).stringof)) + enum qualifiedDName = qualifiedDName!(__traits(parent, T)) ~ "." ~ T.stringof; + else + enum qualifiedDName = T.stringof; +} + +template fullDName(T) +{ + static if (is(T == enum)) + enum fullDName = qualifiedDName!T; + else + enum fullDName = T.stringof; +} diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qtd/MetaMarshall.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qtd/MetaMarshall.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,129 @@ +module qtd.MetaMarshall; + +import std.traits; + +import qtd.Meta; + +template isQObjectType(T) // is a QObject type that belongs to the library +{ + enum isQObjectType = is(T.__isQObjectType); +} + +template isObjectType(T) // is a Qt Object type that belongs to the library +{ + enum isObjectType = is(T.__isObjectType); +} + +template isValueType(T) // is a Qt Value type that belongs to the library +{ + enum isValueType = is(T.__isValueType); +} + +template isQtType(T) +{ + mixin ("enum isQtType = is(T.__isQtType_" ~ T.stringof ~ ");"); +} +/* +template isQtType(T) +{ + enum isQtType = isQObjectType!(T) || isObjectType!(T) || isValueType!(T) || is(T.__isQtType); +} +*/ +template isNativeType(T) // type that doesn't require conversion i.e. is the same in C++ and D +{ + enum isNativeType = isNumeric!T || is(T == bool) || is(T == struct); +} + +template isStringType(T) // string type +{ + enum isStringType = is(T == string); +} + +template isQList(T) +{ + enum isQList = ctfeStartsWith(Unqual!(T).stringof, "QList!"); +} + +// returns full name of enum: +// for Qt enum it is in the form of QPaintDevice::PaintDeviceMetric +// for pure D enums it is Foo.Bar +template enumFullName(T) +{ + static if(!isModule(__traits(parent, T).stringof)) + { + static if(isQtType!(__traits(parent, T))) + enum enumFullName = qualifiedCppName!T; + else + enum enumFullName = qualifiedDName!T; + } + else + enum enumFullName = qualifiedDName!T; + +} + +// converts an argumnent from C++ to D in qt_metacall +string metaCallArgument(T)(string ptr) +{ + static if (isQObjectType!T || isObjectType!T) + return T.stringof ~ ".__getObject(*cast(void**)(" ~ ptr ~ "))"; + else static if (isValueType!T) + return "new " ~ T.stringof ~ "(" ~ T.stringof ~ ".__constructNativeCopy(" ~ ptr ~ "))"; + else static if (isNativeType!T) + return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")"; + else static if (isStringType!T) + return "QStringUtil.toNativeString(" ~ ptr ~ ")"; + else static if (is(T == enum)) + return "*(cast(" ~ qualifiedDName!T ~ "*)" ~ ptr ~ ")"; + else + return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")"; + //res = T.stringof; +} + +// converts a D argument type to C++ for registering in Qt meta system +string qtDeclArg(T)() +{ + static if (isQObjectType!T || isObjectType!T) + return T.stringof ~ "*"; + else static if (isValueType!T) + return T.stringof; + else static if (isStringType!T) + return "QString"; + else static if (isQList!T) + { + alias templateParam!T ElementType; + static if (is(ElementType == string)) + return "QStringList"; + else + return "QList<" ~ qtDeclArg!(templateParam!T)() ~ ">"; + } + else static if (is(T == enum)) + return enumFullName!T; + else static if (isNativeType!T) + return Unqual!T.stringof; + else + return T.stringof; +} + +// converts an argument from D to C++ in a signal emitter +string convertSignalArgument(T)(string arg) +{ + static if (isQObjectType!T || isObjectType!T) + return arg ~ " ? " "&" ~ arg ~ ".__nativeId : cast(void**) &" ~ arg; // since it is a pointer type check arg for null + else static if (isValueType!T) + return arg ~ ".__nativeId"; + else static if (isStringType!T) + return "&_qt" ~ arg; + else static if (isNativeType!T) + return "&" ~ arg; + else + return "&" ~ arg; +} + +string prepareSignalArguments(Args...)() +{ + string res; + foreach(i, _; Args) + static if (isStringType!(Args[i])) + res ~= "auto _qt_t" ~ __toString(i) ~ " = QString(_t" ~ __toString(i) ~ ");\n"; + return res; +} diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qtd/QtdObject.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qtd/QtdObject.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,62 @@ +/** +* +* Copyright: Copyright QtD Team, 2008-2009 +* License: Boost License 1.0 + * + * Copyright QtD Team, 2008-2009 + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file boost-license-1.0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + * + */ +module qtd.Signal; + +public import qt.QGlobal; +import qtd.MetaMarshall; +import qtd.Meta; + +import core.stdc.stdlib : crealloc = realloc, cfree = free; +import core.stdc.string : memmove; +import + core.thread, + core.exception, + std.algorithm; + +public import + std.typetuple, + std.traits, + std.conv, + std.metastrings; + +public import std.string : strip, toStringz; + +/** The beast that takes string representation of function arguments + * and returns an array of default values it doesn't check if arguments + * without default values follow the arguments with default values for + * simplicity. It is done by mixing in an delegate alias. + */ +string[] defaultValues(string signature) +{ + int braces = 0; + bool inDefaultValue = false; + bool inStringLiteral = false; + string[] res; + int startValue = 0; + + if(strip(signature).length == 0) + return res; + + foreach (i,c; signature) + { + if(!inStringLiteral) + { + if(c == '{' || c =='(') + braces++; + else if(c == '}' || c ==')') + braces--; + } + + if(c == '\"' || c == '\'') + { + if (inStringLiteral) + { + if(signature[i-1] != '\\') + inStringLiteral = false; + } + else + { + inStringLiteral = true; + } + } + + if (!inStringLiteral && braces == 0) + { + if(c == '=') // found default value + { + inDefaultValue = true; + startValue = i+1; + } + else if(c == ',') // next function argument + { + if (inDefaultValue) + { + res ~= signature[startValue..i]; + inDefaultValue = false; + } + } + } + } + + if (inDefaultValue) + res ~= signature[startValue..$]; + + return res; +} + +int defaultValuesLength(string[] defVals) +{ + return defVals.length; +} + + +// templates for extracting data from static meta-information of signals, slots or properties +// public alias TypeTuple!("name", index, OwnerClass, ArgTypes) __signal +template MetaEntryName(source...) +{ + enum MetaEntryName = source[0]; // name of the metaentry is the first element +} + +template MetaEntryOwner(source...) +{ + alias TupleWrapper!(source[2]).at[0] MetaEntryOwner; // class that owns the property is the third + // Compiler #BUG 3092 - evaluates MetaEntryOwner as a Tuple with one element +} + +template MetaEntryArgs(source...) +{ + alias ParameterTypeTuple!(source[1]) MetaEntryArgs; // arguments-tuple starts from the fourth position +} + +template TupleWrapper(A...) { alias A at; } + +string convertSignalArguments(Args...)() +{ +// void *_a[] = { 0, const_cast(reinterpret_cast(&_t1)) }; + // at least for string argument need to construct a QString value + string res = prepareSignalArguments!(Args); + + res ~= "void*[" ~ __toString(Args.length+1) ~ "] _a = [null"; + foreach(i, _; Args) + res ~= ", " ~ "cast(void*) (" ~ convertSignalArgument!(Args[i])("_t" ~ __toString(i)) ~ ")"; + res ~= "];\n"; + return res; +} + +public string SignalEmitter(A...)(SignalType signalType, string name, string[] defVals, int localIndex) +{ + string fullArgs, args; + int defValsLength = defVals.length; + string argsConversion = ""; + string argsPtr = "null"; + static if (A.length) + { + while(A.length != defVals.length) + defVals = "" ~ defVals; + + fullArgs = A[0].stringof ~ " _t0"; + if (defVals[0].length) + fullArgs ~= " = " ~ defVals[0]; + args = "_t0"; + foreach(i, _; A[1..$]) + { + fullArgs ~= ", " ~ A[i+1].stringof ~ " _t" ~ __toString(i+1); + if (defVals[i+1].length) + fullArgs ~= " = " ~ defVals[i+1]; + args ~= ", _t" ~ __toString(i+1); + } + // build up conversion of signal args from D to C++ + argsPtr = "_a.ptr"; + argsConversion = convertSignalArguments!(A)(); + } + string attribute; + string sigName = name; + if (signalType == SignalType.BindQtSignal) + name ~= "_emit"; + else + attribute = "protected "; + + string indexArgs = __toString(localIndex); + if(defValsLength > 0) + indexArgs ~= ", " ~ __toString(localIndex+defValsLength); + string str = attribute ~ "final void " ~ name ~ "(" ~ fullArgs ~ ") {\n" ~ argsConversion ~ "\n" + ~ " QMetaObject.activate(this, typeof(this).staticMetaObject, " ~ indexArgs ~ ", " ~ argsPtr ~ ");\n" + ~ "}\n"; // ~ + return str; +} +/** ---------------- */ + + +const string signalPrefix = "__signal"; +const string slotPrefix = "__slot"; + +enum SignalType +{ + BindQtSignal, + NewSignal, + NewSlot +} + +string signature(T...)(string name) +{ + string res = name ~ "("; + foreach(i, _; T) + { + if(i > 0) + res ~= ","; + static if (isNativeType!(T[i])) + res ~= Unqual!(T[i]).stringof; + else + res ~= T[i].stringof; + } + res ~= ")"; + return res; +} + +// ------------------------------------------------------------------ + +string[] getSymbols(C)(string prefix) +{ + string[] result; + auto allSymbols = __traits(derivedMembers, C); + foreach(s; allSymbols) + if(ctfeStartsWith(s, prefix)) + result ~= s; + return result; +} + +string removePrefix(string source) +{ + foreach (i, c; source) + if (c == '_') + return source[i+1..$]; + return source; +} + +template Alias(T...) +{ + alias T Alias; +} + +// recursive search in the static meta-information +template findSymbolsImpl2(C, alias signals, int id) +{ + alias Alias!(__traits(getOverloads, C, signals[id])) current; + static if (signals.length - id - 1 > 0) + alias TypeTuple!(current, findSymbolsImpl2!(C, signals, id + 1).result) result; + else + alias current result; +} + +template findSymbols2(C, string prefix) +{ + enum signals = getSymbols!(C)(prefix); + static if (signals) + alias findSymbolsImpl2!(C, signals, 0).result result; + else + alias TypeTuple!() result; +} + +template findSignals(C) +{ + alias findSymbols2!(C, "signal_").result findSignals; +} + +template findSlots(C) +{ + alias findSymbols2!(C, "slot_").result findSlots; +} + +/* commented out for future when we will implement default arguments +template metaMethods(alias func, int index, int defValsCount) +{ + static if(defValsCount >= 0) { + alias TupleWrapper!(func, index) current; +// pragma(msg, __traits(identifier, (current.at)[0]) ~ " " ~ typeof(&(current.at)[0]).stringof); + alias metaMethods!(func, index+1, defValsCount-1).result next; + alias TypeTuple!(current, next) result; + } + else + { + alias TypeTuple!() result; + } +} +*/ + +template toMetaEntriesImpl(int id, Methods...) +{ + static if (Methods.length > id) + { + alias typeof(&Methods[id]) Fn; +// commented out for future when we will implement default arguments +// enum defValsLength = 0; //ParameterTypeTuple!(Fn).length - requiredArgCount!(Methods[id])(); +// pragma(msg, __traits(identifier, Methods[id]) ~ " " ~ typeof(&Methods[id]).stringof); +// alias metaMethods!(Methods[id], 0, defValsLength).result subres; + alias TupleWrapper!(removePrefix(__traits(identifier, Methods[id])), typeof(&Methods[id])) subres; + alias TypeTuple!(subres, toMetaEntriesImpl!(id+1, Methods).result) result; + } + else + { + alias TypeTuple!() result; + } +} + +template toMetaEntries(Methods...) +{ + alias TupleWrapper!(toMetaEntriesImpl!(0, Methods).result) toMetaEntries; +} diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qtd/Str.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qtd/Str.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,55 @@ +/** + * + * Copyright: Copyright QtD Team, 2008-2009 + * License: 0 ) + { + bool inExp = false; + + // Look for a $ + foreach( i,c ; tmpl ) + { + if (c == '$') + { + inExp = true; + r ~= tmpl[0..i]; + tmpl = tmpl[i+1..$]; + break; + } + } + + // If we didn't find a $, it's because we hit the end of the template. + if( !inExp ) + { + r ~= tmpl; + break; + } + + // So we're in an expansion/substitution. + + debug(gb_Format_verbose) r ~= "{in exp}"; + + if( tmpl.length == 0 ) + { + r ~= "{unterminated substitution}"; + break; + } + + // c is the next character, whilst tmpl is everything left in the + // template string. + char c = tmpl[0]; + tmpl = tmpl[1..$]; + + // $$ - escaped $. + if( c == '$' ) + { + debug(gb_Format_verbose) r ~= "{escaped $}"; + r ~= '$'; + continue; + } + + // $n - shortcut for ${n}. + if( '0' <= c && c <= '9' ) + { + debug(gb_Format_verbose) r ~= "{shorthand index}"; + r ~= stringify(c-'0', 0, "", args); + continue; + } + + // $* - shortcut for ${} + if( c == '*' ) + { + debug(gb_Format_verbose) r ~= "{shorthand next}"; + r ~= stringify(argPos++, 0, "", args); + continue; + } + + // This means we got a $ followed by something unexpected. + if( c != '{' ) + { + r ~= "{malformed substitution}"; + break; + } + + if( tmpl.length == 0 ) + { + r ~= "{unterminated substitution}"; + break; + } + + debug(gb_Format_verbose) + { + r ~= "{parse complex at '"; + r ~= c; + r ~= "':\"" ~ tmpl ~ "\"}"; + } + + // NOTE: We haven't updated c and tmpl yet. + + { + // arg will contain the index of the argument the user wanted + // substituted. + size_t arg = size_t.max; + // fmt will contain any additional formatting options. + string fmt = ""; + + // If we didn't get a : or }, that means we expect an index. + if( !( tmpl[0] == ':' || tmpl[0] == '}' ) ) + { + // So parse it. + auto used = Integer.parse_ctfe!(size_t)(tmpl, true); + + if( used == 0 ) + { + debug(gb_Format_verbose) r ~= "{used zero of \""~tmpl~"\"}"; + r ~= "{invalid argument index}"; + break; + } + + arg = Integer.parse_ctfe!(size_t)(tmpl); + tmpl = tmpl[used..$]; + + if( tmpl.length == 0 ) + { + r ~= "{unterminated substitution}"; + break; + } + } + else + { + // Otherwise, the index was elided, which means we want to use + // the index of the "next" argument. + arg = argPos; + ++ argPos; + } + + c = tmpl[0]; + tmpl = tmpl[1..$]; + + debug(gb_Format_verbose) + r ~= "{index " ~ Integer.format_ctfe(arg) ~ "}"; + + // If c is :, then we've got formatting options to parse + + if( c == ':' ) + { + debug(gb_Format_verbose) r ~= "{fmt string}"; + + // Look for the closing }. + size_t len = 0; + foreach( i,d ; tmpl ) + { + if( d == '}' ) + { + len = i; + break; + } + } + if( len == 0 ) + { + r ~= "{malformed format}"; + break; + } + fmt = tmpl[0..len]; + tmpl = tmpl[len..$]; + + if( tmpl.length == 0 ) + { + r ~= "{unterminated substitution}"; + break; + } + + c = tmpl[0]; + tmpl = tmpl[1..$]; + } + + // At this point, we should have the closing }. If not, someone's + // screwed up. + if( c != '}' ) + { + debug(gb_Format_verbose) + { + r ~= "{expected closing; got '"; + r ~= c; + r ~= "':\"" ~ tmpl ~ "\"}"; + } + r ~= "{malformed substitution}"; + break; + } + + // Stringify that bugger. + r ~= stringify(arg, 0, fmt, args); + + // When we fall off the end here, we'll continue with the + // remainder of tmpl, unless it's empty in which case we're + // finished. + } + } + + return r; +} + +version( Unittest ) +{ + static assert(format_ctfe("A: $$", "foo"[]) == "A: $"); + static assert(format_ctfe("B: a $$ c", "b"[]) == "B: a $ c"); + + static assert(format_ctfe("C: ${}", "foo"[]) == "C: foo"); + static assert(format_ctfe("D: a ${} c", "b"[]) == "D: a b c"); + + static assert(format_ctfe("E: $0", "foo"[]) == "E: foo"); + static assert(format_ctfe("F: a $0 c", "b"[]) == "F: a b c"); + + static assert(format_ctfe("G: $*", "foo"[]) == "G: foo"); + static assert(format_ctfe("H: a $* c", "b"[]) == "H: a b c"); + + static assert(format_ctfe("I: ${0}", "foo"[]) == "I: foo"); + static assert(format_ctfe("J: a ${0} c", "b"[]) == "J: a b c"); + + static assert(format_ctfe("K: ${} ${} ${}", 1, -2, "c"[]) == "K: 1 -2 c"); + static assert(format_ctfe("L: $* $* $*", 1, -2, "c"[]) == "L: 1 -2 c"); + static assert(format_ctfe("M: $0 $1 $2", 1, -2, "c"[]) == "M: 1 -2 c"); + static assert(format_ctfe("N: ${0} ${1} ${2}", 1, -2, "c"[]) == "N: 1 -2 c"); + + static assert(format_ctfe("O: ${2} ${0} ${1}", 1, -2, "c"[]) == "O: c 1 -2"); + + static assert(format_ctfe("P: ${:x} ${0:x} ${0:o} ${0:b}", 42) == "P: 2a 2a 52 101010"); + + static assert(format_ctfe("Q: ${0} ${0:q} ${0:x}", "abc"[]) == "Q: abc \"abc\" 616263"); + static assert(format_ctfe("R: ${0} ${0:q}", ["a","b","c"][]) == "R: [a, b, c] [\"a\", \"b\", \"c\"]"); + + const TORTURE_TMPL = ` + struct $*Enum + { + const Name = ${0:q}; + const string[${:l}] Members = ${1:q}; + + ${2} value() + { + return ${3:xx}; + } + } + `[]; + + const TORTURE_EXPECTED = ` + struct FooEnum + { + const Name = "Foo"; + const string[3] Members = ["bar", "quxx", "zyzzy"]; + + int value() + { + return 0x42; + } + } + `[]; + + const TORTURE_ACTUAL = format_ctfe(TORTURE_TMPL, + "Foo"[], ["bar"[],"quxx","zyzzy"][], + "int"[], 0x42); + + static assert( TORTURE_EXPECTED == TORTURE_ACTUAL ); +} + +private +{ + size_t findIndexByName(Args...)(string name, Args args) + { + foreach( i ; Tuple.Sequence!(0, Args.length, 2) ) + { + static if( !is( Args[i] : string ) ) + { + static assert(false, "expected string for argument " + ~ Integer.format_ctfe(i) ~ " in " ~ Args.stringof + ~ " not " ~ Args[i].stringof); + } + if( name == args[i][] ) + return i+1; + } + return size_t.max; + } + + version( Unittest ) + { + static assert( findIndexByName("a", "a", 0, "b", 1) == 1 ); + static assert( findIndexByName("b", "a", 0, "b", 1) == 3 ); + static assert( findIndexByName("c", "a", 0, "b", 1) == size_t.max ); + } +} + +/// ditto + +string formatNamed_ctfe(Args...)(string tmpl, Args args) +{ + string r = ""; + int argPos = 0; + + while( tmpl.length > 0 ) + { + bool inExp = false; + + // Look for a $ + foreach( i,c ; tmpl ) + { + if (c == '$') + { + inExp = true; + r ~= tmpl[0..i]; + tmpl = tmpl[i+1..$]; + break; + } + } + + // If we didn't find a $, it's because we hit the end of the template. + if( !inExp ) + { + r ~= tmpl; + break; + } + + // So we're in an expansion/substitution. + + debug(gb_Format_verbose) r ~= "{in exp}"; + + if( tmpl.length == 0 ) + { + r ~= "{unterminated substitution}"; + break; + } + + // c is the next character, whilst tmpl is everything left in the + // template string. + char c = tmpl[0]; + tmpl = tmpl[1..$]; + + // $$ - escaped $. + if( c == '$' ) + { + debug(gb_Format_verbose) r ~= "{escaped $}"; + r ~= '$'; + continue; + } + + // $a... - shortcut for $a... + if( String.isIdentStartChar_ctfe(c) ) + { + debug(gb_Format_verbose) r ~= "{shorthand name}"; + size_t i = 0; + while( i < tmpl.length ) + { + if( !String.isIdentChar_ctfe(tmpl[i]) ) + break; + ++ i; + } + string name = c ~ tmpl[0..i]; + tmpl = tmpl[i..$]; + r ~= stringify(findIndexByName(name, args), 0, "", args); + continue; + } + + // This means we got a $ followed by something unexpected. + if( c != '{' ) + { + r ~= "{malformed substitution}"; + break; + } + + if( tmpl.length == 0 ) + { + r ~= "{unterminated substitution}"; + break; + } + + debug(gb_Format_verbose) + { + r ~= "{parse complex at '"; + r ~= c; + r ~= "':\"" ~ tmpl ~ "\"}"; + } + + // NOTE: We haven't updated c and tmpl yet. + + { + // arg will contain the index of the argument the user wanted + // substituted. + size_t arg = size_t.max; + // fmt will contain any additional formatting options. + string fmt = ""; + + // If we didn't get a : or }, that means we expect a name. + if( !( tmpl[0] == ':' || tmpl[0] == '}' ) ) + { + // So parse it. + size_t i = 0; + while( i < tmpl.length ) + { + if( !String.isIdentChar_ctfe(tmpl[i]) ) + break; + ++ i; + } + string name = tmpl[0..i]; + tmpl = tmpl[i..$]; + + arg = findIndexByName(name, args); + + if( tmpl.length == 0 ) + { + r ~= "{unterminated substitution}"; + break; + } + } + else + { + // Otherwise, the name was elided. Kaboom! + r ~= "{substitution missing name}"; + break; + } + + c = tmpl[0]; + tmpl = tmpl[1..$]; + + debug(gb_Format_verbose) + r ~= "{index " ~ Integer.format_ctfe(arg) ~ "}"; + + // If c is :, then we've got formatting options to parse + + if( c == ':' ) + { + debug(gb_Format_verbose) r ~= "{fmt string}"; + + // Look for the closing }. + size_t len = 0; + foreach( i,d ; tmpl ) + { + if( d == '}' ) + { + len = i; + break; + } + } + if( len == 0 ) + { + r ~= "{malformed format}"; + break; + } + fmt = tmpl[0..len]; + tmpl = tmpl[len..$]; + + debug(gb_Format_verbose) r ~= "{fmt:"~fmt~"}"; + + if( tmpl.length == 0 ) + { + r ~= "{unterminated substitution}"; + break; + } + + c = tmpl[0]; + tmpl = tmpl[1..$]; + } + + // At this point, we should have the closing }. If not, someone's + // screwed up. + if( c != '}' ) + { + debug(gb_Format_verbose) + { + r ~= "{expected closing; got '"; + r ~= c; + r ~= "':\"" ~ tmpl ~ "\"}"; + } + r ~= "{malformed substitution}"; + break; + } + + // Stringify that bugger. + r ~= stringify(arg, 0, fmt, args); + + // When we fall off the end here, we'll continue with the + // remainder of tmpl, unless it's empty in which case we're + // finished. + } + } + + return r; +} + +version( Unittest ) +{ + static assert( formatNamed_ctfe("A: $$", "a"[], 0, "b"[], 1) == "A: $" ); + static assert( formatNamed_ctfe("B: $a", "a"[], 0, "b"[], 1) == "B: 0" ); + static assert( formatNamed_ctfe("C: $b", "a"[], 0, "b"[], 1) == "C: 1" ); + + static assert( formatNamed_ctfe("D: ${a}", "a"[], 0, "b"[], 1) == "D: 0" ); + static assert( formatNamed_ctfe("E: ${b}", "a"[], 0, "b"[], 1) == "E: 1" ); + + static assert( formatNamed_ctfe("F: $foo$bar", "foo"[], 0, "bar"[], 1) == "F: 01" ); + static assert( formatNamed_ctfe("G: ${foo}${bar}", "foo"[], 0, "bar"[], 1) == "G: 01" ); + + static assert( formatNamed_ctfe("H: ${foo:x}${bar:xx}", "foo"[], 0, "bar"[], 1) == "H: 00x1" ); + + const TORTURE_NAMED_TMPL = ` + struct ${name}Enum + { + const Name = ${name:q}; + const string[${members:l}] Members = ${members:q}; + + ${retType} value() + { + return ${value:xx}; + } + } + `[]; + + const TORTURE_NAMED_EXPECTED = ` + struct FooEnum + { + const Name = "Foo"; + const string[3] Members = ["bar", "quxx", "zyzzy"]; + + int value() + { + return 0x42; + } + } + `[]; + + const TORTURE_NAMED_ACTUAL = formatNamed_ctfe(TORTURE_NAMED_TMPL, + "name"[], "Foo"[], + "members"[], ["bar"[],"quxx","zyzzy"][], + "retType"[], "int"[], + "value"[], 0x42); + + static assert( TORTURE_NAMED_EXPECTED == TORTURE_NAMED_ACTUAL ); +} + diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qtd/ctfe/Integer.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qtd/ctfe/Integer.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,169 @@ +/** + * CTFE Integer routines. + * + * Authors: Daniel Keep + * Copyright: See LICENSE. + */ +module qtd.ctfe.Integer; + +/** + * Formats an integer as a string. You can optionally specify a different + * base; any value between 2 and 16 inclusive is supported. + * + * Params: + * v = value to format. + * base = base to use; defaults to 10. + * Returns: + * integer formatted as a string. + */ + +string format_ctfe(intT)(intT v, int base = 10) +{ + static if( !is( intT == ulong ) ) + { + return (v < 0) + ? "-" ~ format_ctfe(cast(ulong) -v, base) + : format_ctfe(cast(ulong) v, base); + } + else + { + assert( 2 <= base && base <= 16, + "base must be between 2 and 16; got " ~ format_ctfe(base, 10) ); + + string r = ""; + do + { + r = INT_CHARS[cast(size_t)(v % base)] ~ r; + v /= base; + } + while( v > 0 ); + return r; + } +} + +/** + * Parses an integer value from a string. You can optionally specify a + * different base; any value between 2 and 16 inclusive is supported. + * + * Note that this does not fail if it cannot consume the entire string; + * use returnUsed to determine the number of characters consumed. + * + * Params: + * str = string to parse. + * returnUsed = defaults to false; if set to true, returns the number of + * characters consumed from the string instead of the + * parsed value. + * base = base to use; defaults to 10. + * Returns: + * either the parsed integer or the number of characters consumed, + * depending on the value of returnUsed. + */ + +intT parse_ctfe(intT)(string str, bool returnUsed = false, int base = 10) +{ + auto origStr = str; + + assert( 2 <= base && base <= 16, + "base must be between 2 and 16; got " ~ format_ctfe(base, 10) ); + + bool neg = false; + if( str.length > 0 && str[0] == '-' ) + { + neg = true; + str = str[1..$]; + } + + if( intT.min == 0 && neg ) + assert(false, "underwhile while parsing \"" ~ origStr + ~ "\" as a " ~ intT.stringof ~ ": cannot represent negative " + ~ "values"); + + intT r = 0; + size_t used = 0; + + foreach( c ; str ) + { + int cv = -1; + + if( '0' <= c && c <= '9' ) + cv = c - '0'; + + else if( 'A' <= c && c <= 'Z' ) + cv = 10 + c - 'A'; + + else if( 'a' <= c && c <= 'z' ) + cv = 10 + c - 'a'; + + if( cv >= base || cv < 0 ) + break; + + auto oldR = r; + r = r*base + cast(intT) cv; + ++ used; + + if( r < oldR ) + assert(false, "overflow while parsing \"" ~ origStr + ~ "\" as a " ~ intT.stringof); + } + + if( neg ) + { + r = -r; + ++used; + } + + if( returnUsed ) + { + assert( used < intT.max, "overflow attempting to return " + ~ "number of characters consumed in a " ~ intT.stringof ); + + return used; + } + else + return r; +} + +/** + * Like parse_ctfe, except it will raise an error if the provided string + * cannot be parsed in its entirety. + * + * Params: + * str = the string to parse. + * base = base to use; defaults to 10. + * Returns: + * the parsed integer. + */ + +intT parseAll_ctfe(intT)(string str, int base = 10) +{ + auto used = parse_ctfe!(intT)(str, true, base); + assert( used == str.length, "could not parse entire string \"" ~ str + ~ "\"" ); + return parse_ctfe!(int)(str, false, base); +} + +private +{ + const INT_CHARS = "0123456789abcdef"; +} + +version( Unittest ) +{ + static assert( format_ctfe(0) == "0", "got: " ~ format_ctfe(0) ); + static assert( format_ctfe(1) == "1" ); + static assert( format_ctfe(-1) == "-1" ); + static assert( format_ctfe(42) == "42" ); + static assert( format_ctfe(0xf00, 16) == "f00" ); + static assert( format_ctfe(0123, 8) == "123" ); + + static assert( parse_ctfe!(long)("0") == 0 ); + static assert( parse_ctfe!(long)("1") == 1 ); + static assert( parse_ctfe!(long)("-1") == -1 ); + static assert( parse_ctfe!(long)("42") == 42 ); + static assert( parse_ctfe!(long)("f00", false, 16) == 0xf00 ); + static assert( parse_ctfe!(long)("123", false, 8) == 0123 ); + static assert( parse_ctfe!(long)("123ax", true) == 3 ); + static assert( parse_ctfe!(long)("123ax", true, 16) == 4 ); + + static assert( parseAll_ctfe!(long)("123") == 123 ); +} diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qtd/ctfe/String.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qtd/ctfe/String.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,317 @@ +/** + * CTFE String routines. + * + * Authors: Daniel Keep + * Copyright: See LICENSE. + */ +module qtd.ctfe.String; + +import Integer = qtd.ctfe.Integer; + +private +{ + const HEX_CHARS = "0123456789abcdef"; +} + +/** + * Escapes a string into an equivalent string literal. + * + * Params: + * str = string to escape. + * aggressive = if set, the function will escape all non-printing + * characters, non-space whitespace and newlines. Defaults + * to true. + * Returns: + * Escaped string literal. + */ +string escape_ctfe(string str, bool aggressive=true) +{ + string head = ""; + + foreach( i,c ; str ) + { + if( c == '"' || c == '\\' || c == '\0' ) + { + head = "\""~str[0..i]; + str = str[i..$]; + break; + } + + if( aggressive ) + { + if( c < 0x20 || c == 0x7f ) + { + head = "\""~str[0..i]; + str = str[i..$]; + break; + } + } + } + + if( head.length == 0 ) + return "\"" ~ str ~ "\""; + + string tail = ""; + + foreach( c ; str ) + { + if( c == '"' ) + tail ~= `\"`; + + else if( c == '\\' ) + tail ~= "\\\\"; + + else if( c == '\0' ) + tail ~= `\0`; + + else if( aggressive ) + { + switch( c ) + { + case '\?': + tail ~= `\?`; + break; + + case '\a': + tail ~= `\a`; + break; + + case '\b': + tail ~= `\b`; + break; + + case '\f': + tail ~= `\f`; + break; + + case '\n': + tail ~= `\n`; + break; + + case '\r': + tail ~= `\r`; + break; + + case '\t': + tail ~= `\t`; + break; + + case '\v': + tail ~= `\v`; + break; + + default: + if( c < 0x20 || c == 0x75 ) + { + tail ~= `\x`; + tail ~= HEX_CHARS[c/0xf]; + tail ~= HEX_CHARS[c&0xf]; + } + else + tail ~= c; + } + } + else + tail ~= c; + } + + return head ~ tail ~ "\""; +} + +version( Unittest ) +{ + static assert( escape_ctfe("abc") == "\"abc\"" ); + static assert( escape_ctfe("a\"c") == "\"a\\\"c\"" ); +} + +/** + * Turns an array of bytes into a hexadecimal string. + * + * Params: + * arr = array to hexify. + * grouping = if non-zero, specifies after how many bytes to insert a + * space. + * Returns: + * String of hex bytes. + */ + +string hexify_ctfe(ubyte[] arr, int grouping = 0) +{ + string r = ""; + int bytes = grouping; + foreach( b ; arr ) + { + if( bytes == 0 && grouping > 0 ) + { + r ~= ' '; + bytes = grouping; + } + + auto bh = b/16; + auto bl = b&15; + + assert( bh < 16 ); + assert( bl < 16 ); + + r ~= HEX_CHARS[bh]; + r ~= HEX_CHARS[bl]; + + if( grouping > 0 ) + -- bytes; + } + return r; +} + +/// ditto + +string hexify_ctfe(string arr, int grouping = 0) +{ + string r = ""; + int bytes = grouping; + foreach( b ; arr ) + { + if( bytes == 0 && grouping > 0 ) + { + r ~= ' '; + bytes = grouping; + } + + auto bh = b/16; + auto bl = b&15; + + assert( bh < 16 ); + assert( bl < 16 ); + + r ~= HEX_CHARS[bh]; + r ~= HEX_CHARS[bl]; + + if( grouping > 0 ) + -- bytes; + } + return r; +} + +version( Unittest ) +{ + static const ubyte[] DATA_1 = [0x00,0x01,0x02,0x03]; + static const ubyte[] DATA_2 = [0x0f,0x10,0xef,0xf0]; + + static assert( hexify_ctfe(DATA_1) == "00010203" ); + static assert( hexify_ctfe(DATA_2) == "0f10eff0" ); + + static assert( hexify_ctfe(DATA_1, 1) == "00 01 02 03" ); + static assert( hexify_ctfe(DATA_2, 1) == "0f 10 ef f0" ); + + static assert( hexify_ctfe(DATA_1, 2) == "0001 0203" ); + static assert( hexify_ctfe(DATA_2, 2) == "0f10 eff0" ); + + static assert( hexify_ctfe(DATA_1, 4) == "00010203" ); + static assert( hexify_ctfe(DATA_2, 4) == "0f10eff0" ); +} + +/** + * Pads a string. padl adds padding to the left, padr adds it to the right. + * Params: + * str = string to pad. + * len = length to pad to. + * padding = character to use for padding. Defaults to space. + * Returns: + * padded string. + */ + +string padl_ctfe(string str, int len, char padding = ' ') +{ + while( str.length < len ) + str = padding ~ str; + return str; +} + +/// ditto + +string padr_ctfe(string str, int len, char padding = ' ') +{ + while( str.length < len ) + str ~= padding; + return str; +} + +version( Unittest ) +{ + static assert( padl_ctfe("abc", 2) == "abc" ); + static assert( padl_ctfe("abc", 3) == "abc" ); + static assert( padl_ctfe("abc", 4) == " abc" ); + static assert( padl_ctfe("abc", 4, 'x') == "xabc" ); + + static assert( padr_ctfe("abc", 2) == "abc" ); + static assert( padr_ctfe("abc", 3) == "abc" ); + static assert( padr_ctfe("abc", 4) == "abc " ); + static assert( padr_ctfe("abc", 4, 'x') == "abcx" ); +} + +/** + * Returns the tail of a string after a given splitting character. The Rev + * variant returns the tail after the last instance of the splitting + * character. + */ + +string tail_ctfe(string str, char split) +{ + foreach( i,c ; str ) + { + if( c == split ) + return str[i+1..$]; + } + return str; +} + +/// ditto + +string tailRev_ctfe(string str, char split) +{ + foreach_reverse( i,c ; str ) + { + if( c == split ) + return str[i+1..$]; + } + return str; +} + +/** + * Determines whether a character is valid in an identifier in a + * non-initial position. + * + * Does not support the full range of valid D identifier characters. + */ + +bool isIdentChar_ctfe(char c) +{ + return ('a' <= c && c <= 'z') + || ('A' <= c && c <= 'Z') + || ('0' <= c && c <= '9') + || (c == '_'); +} + +/** + * Determines whether a character is valid in an identifier in an + * initial position. + * + * Does not support the full range of valid D identifier characters. + */ + +bool isIdentStartChar_ctfe(char c) +{ + return ('a' <= c && c <= 'z') + || ('A' <= c && c <= 'Z') + || (c == '_'); +} + +/** + * Returns a line spec suitable for mixing in. This can be used with string + * mixins to ensure compile errors appear on the "correct" line in the source. + */ + +string linespec_ctfe(string file, long line) +{ + return "#line "~Integer.format_ctfe(line)~" \"" ~ file ~ "\"\n"; +} + diff -r 552647ec0f82 -r 96a75b1e5b26 d2/qtd/util/Tuple.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qtd/util/Tuple.d Fri May 14 12:14:37 2010 +0300 @@ -0,0 +1,64 @@ +/** + * Tuple-related stuff. + * + * Authors: Daniel Keep + * Copyright: See LICENSE. + */ +module qtd.util.Tuple; + +import std.typetuple; + +/** + * Sequence can be used to generate a tuple of integer values. It can be + * used in one of three forms: + * + * ----- + * Sequence!(6) // ==> (0, 1, 2, 3, 4, 5) + * Sequence!(1,6) // ==> (1, 2, 3, 4, 5) + * Sequence!(1,6,2) // ==> (1, 3, 5) + * ----- + */ + +template Sequence(int max) +{ + static if( max <= 0 ) + alias TypeTuple!() Sequence; + else + alias TypeTuple!(Sequence!(max-1), max-1) Sequence; +} + +/// ditto + +template Sequence(int min, int max) +{ + static if( max <= min ) + alias TypeTuple!() Sequence; + else + alias TypeTuple!(Sequence!(min, max-1), max-1) Sequence; +} + +/// ditto + +template Sequence(int min, int max, int stride) +{ + static if( min >= max ) + alias TypeTuple!() Sequence; + else + alias TypeTuple!(min, Sequence!(min+stride, max, stride)) Sequence; +} + +version( Unittest ) +{ + static assert( Sequence!(3)[0] == 0 ); + static assert( Sequence!(3)[1] == 1 ); + static assert( Sequence!(3)[2] == 2 ); + static assert( Sequence!(3).length == 3 ); + + static assert( Sequence!(1, 3)[0] == 1 ); + static assert( Sequence!(1, 3)[1] == 2 ); + static assert( Sequence!(1, 3).length == 2 ); + + static assert( Sequence!(1, 5, 2)[0] == 1 ); + static assert( Sequence!(1, 5, 2)[1] == 3 ); + static assert( Sequence!(1, 5, 2).length == 2 ); +} diff -r 552647ec0f82 -r 96a75b1e5b26 demos/shared/hoverpoints.d --- a/demos/shared/hoverpoints.d Thu May 13 21:01:24 2010 +0300 +++ b/demos/shared/hoverpoints.d Fri May 14 12:14:37 2010 +0300 @@ -49,7 +49,7 @@ import qt.gui.QWidget, - qt.qtd.Array, + qtd.Array, arthurwidgets; final class HoverPoints : QObject diff -r 552647ec0f82 -r 96a75b1e5b26 generator/dgenerator.cpp --- a/generator/dgenerator.cpp Thu May 13 21:01:24 2010 +0300 +++ b/generator/dgenerator.cpp Fri May 14 12:14:37 2010 +0300 @@ -1949,15 +1949,15 @@ if (!m_isRecursive) { s << "public import qt.QGlobal;" << endl << "public import qt.core.Qt;" << endl - << "private import qt.QtdObject;" << endl + << "private import qtd.QtdObject;" << endl << "private import qt.core.QString;" << endl - << "private import qt.qtd.Array;" << endl + << "private import qtd.Array;" << endl << "private import qt.core.QList;" << endl; if (d_class->isQObject()) { - s << "public import qt.Signal;" << endl - << "public import qt.qtd.MOC;" << endl - << "public import qt.core.QMetaObject;" << endl - << "public import qt.qtd.Traits;" << endl; + s << "public import qtd.Signal;" << endl + << "public import qtd.MOC;" << endl + << "public import qtd.Traits;" << endl + << "public import qt.core.QMetaObject;" << endl; if (d_class->name() != "QObject") s << "public import qt.core.QObject;" << endl; diff -r 552647ec0f82 -r 96a75b1e5b26 generator/typesystem_core.xml --- a/generator/typesystem_core.xml Thu May 13 21:01:24 2010 +0300 +++ b/generator/typesystem_core.xml Fri May 14 12:14:37 2010 +0300 @@ -2510,7 +2510,7 @@ - + diff -r 552647ec0f82 -r 96a75b1e5b26 generator/typesystem_gui-java.java --- a/generator/typesystem_gui-java.java Thu May 13 21:01:24 2010 +0300 +++ b/generator/typesystem_gui-java.java Fri May 14 12:14:37 2010 +0300 @@ -291,7 +291,7 @@ }// class class QImage___ extends QImage { - private import qt.qtd.Str; + private import qtd.Str; public this(string[] xpm) { this(toStringzArray(xpm)); @@ -477,7 +477,7 @@ class QPixmap___ extends QPixmap { - private import qt.qtd.Str; + private import qtd.Str; public this(string[] xpm) { this(toStringzArray(xpm)); diff -r 552647ec0f82 -r 96a75b1e5b26 generator/typesystem_gui.xml --- a/generator/typesystem_gui.xml Thu May 13 21:01:24 2010 +0300 +++ b/generator/typesystem_gui.xml Fri May 14 12:14:37 2010 +0300 @@ -5824,9 +5824,8 @@ - + - @@ -7524,7 +7523,7 @@ - + diff -r 552647ec0f82 -r 96a75b1e5b26 generator/typesystem_sql.xml --- a/generator/typesystem_sql.xml Thu May 13 21:01:24 2010 +0300 +++ b/generator/typesystem_sql.xml Fri May 14 12:14:37 2010 +0300 @@ -1,5 +1,5 @@ - + qt.Utilities.loadQtLibrary("QtSql"); diff -r 552647ec0f82 -r 96a75b1e5b26 qt/CMakeLists.txt --- a/qt/CMakeLists.txt Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -project (qt_d D) - -set(QT_SRCS_D -QtdObject.d -QGlobal.d - -core/QChildEvent.d -core/QCoreApplication.d -core/QEvent.d -core/QEventLoop.d -core/QObject.d -core/QTimerEvent.d -core/QTranslator.d -core/Qt.d - -qtd/Str.d -) - -#add_subdirectory(core) -#add_subdirectory(qtd) - -#add_library(qt_d STATIC ${QT_CORE_SRCS_D} ${QT_QTD_SRCS_D} ${QT_SRCS_D}) -add_library(qt_d STATIC ${QT_SRCS_D}) diff -r 552647ec0f82 -r 96a75b1e5b26 qt/QDefines.d --- a/qt/QDefines.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -module qt.QDefines; - -const char[] QT_VERSION_STR = "4.5.2"; -const int QT_VERSION = 263426; diff -r 552647ec0f82 -r 96a75b1e5b26 qt/QDefines.d.inc --- a/qt/QDefines.d.inc Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -module qt.QDefines; - -const char[] QT_VERSION_STR = "@QTD_VERSION_STR@"; -const int QT_VERSION = @QTD_VERSION@; \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 qt/QGlobal.d --- a/qt/QGlobal.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,746 +0,0 @@ -module qt.QGlobal; - -public import qt.qtd.Str; -public import qt.QDefines; - -version (Tango) -{ - import tango.io.Stdout; - void writeln(string s) - { - Stdout(s).newline; - } - package import tango.stdc.stdlib, - tango.core.Memory; -} -else -{ - import std.stdio; - package import std.c.stdlib, - core.memory; -} - -T static_cast(T, U)(U obj) -{ - return cast(T)cast(void*)obj; -} - -template QT_BEGIN_NAMESPACE() { -} - -template QT_END_NAMESPACE() { -} - -template QT_BEGIN_HEADER() { -} - -template QT_END_HEADER() { -} - -mixin QT_BEGIN_HEADER; -mixin QT_BEGIN_NAMESPACE; - -//TODO: this sucks -extern(C) void qtd_dummy() {} -// Defined in QObject.d -extern(C) void qtd_delete_d_qobject(void* dPtr); - -version(cpp_shared) -{ - extern (C) void qtd_core_initCallBacks(void* toUtf8, void* dummy); - static this() { - qtd_core_initCallBacks(&qtd_toUtf8, &qtd_dummy); - } - - extern (C) void qtd_QObjectEntity_initCallBacks(void* del_d_obj); - static this() { - qtd_QObjectEntity_initCallBacks(&qtd_delete_d_qobject); - } -} - -string tr(string arg) { - return arg; -} - -/* - can be used like #if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0)) -*/ -bool QT_VERSION_CHECK( ushort major, ushort minor, ushort patch ) -{ - return cast(bool)((major<<16)|(minor<<8)|(patch)); -} -//TODO(katrina) get this from the C++ side -const char[] QT_PACKAGEDATE_STR = "2008-09-27"; -//TODO(katrina) get this from the C++ side -const char[] QT_PACKAGE_TAG = "gc9953de622c6a0f655322e0d9f5bd6dc2803b470"; - -/* - Size-dependent types (architechture-dependent byte order) - - Make sure to update QMetaType when changing these typedefs -*/ - -alias char qint8; /* 8 bit signed */ -alias char quint8; /* 8 bit unsigned */ -alias short qint16; /* 16 bit signed */ -alias ushort quint16; /* 16 bit unsigned */ -alias int qint32; /* 32 bit signed */ -alias uint quint32; /* 32 bit unsigned */ -alias long qint64; /* 64 bit signed */ -alias ulong quint64; /* 64 bit unsigned */ - -version (X86) -{ - alias quint32 quintptr; - alias qint32 qptrdiff; -} -else version (X86_64) -{ - alias quint64 quintptr; - alias qint64 qptrdiff; -} - -const byte QT_POINTER_SIZE = 8; - -alias int QNoImplicitBoolCast; - -alias double qreal; - - -/* - Utility macros and inline functions - TODO(katrina) see if we need to do anything to make these - able to be evaluated at compile time -*/ - -T qAbs(T)(T t) { return t >= 0 ? t : -t; } - -int qRound(qreal d) -{ return d >= 0.0 ? cast(int)(d + 0.5) : cast(int)(d - cast(int)(d-1) + 0.5) + cast(int)(d-1); } - -qint64 qRound64(qreal d) -{ return d >= 0.0 ? cast(qint64)(d + 0.5) : cast(qint64)(d - cast(qint64)(d-1) + 0.5) + cast(qint64)(d-1); } - -T qMin(T)(T a,T b) { if (a < b) return a; return b; } -T qMax(T)(T a, T b) { if (a < b) return b; return a; } -T qBound(T)(T min, T val,T max) { return qMax(min, qMin(max, val)); } - -/* - Data stream functions are provided by many classes (defined in qdatastream.h) -*/ - -//class QDataStream; - -/* - System information -*/ - -class QSysInfo { -public: - enum Sizes { - WordSize = ((void *).sizeof<<3) - }; - - enum Endian { - BigEndian, - LittleEndian, - ByteOrder = BigEndian - }; - /* needed to bootstrap qmake */ - static const int ByteOrder; - - enum WinVersion { - WV_32s = 0x0001, - WV_95 = 0x0002, - WV_98 = 0x0003, - WV_Me = 0x0004, - WV_DOS_based= 0x000f, - - WV_NT = 0x0010, - WV_2000 = 0x0020, - WV_XP = 0x0030, - WV_2003 = 0x0040, - WV_VISTA = 0x0080, - WV_NT_based = 0x00f0, - - WV_CE = 0x0100, - WV_CENET = 0x0200, - WV_CE_5 = 0x0300, - WV_CE_6 = 0x0400, - WV_CE_based = 0x0f00 - }; - static const WinVersion WindowsVersion; - static WinVersion windowsVersion(); - - enum MacVersion { - MV_Unknown = 0x0000, - - /* version */ - MV_9 = 0x0001, - MV_10_0 = 0x0002, - MV_10_1 = 0x0003, - MV_10_2 = 0x0004, - MV_10_3 = 0x0005, - MV_10_4 = 0x0006, - MV_10_5 = 0x0007, - - /* codenames */ - MV_CHEETAH = MV_10_0, - MV_PUMA = MV_10_1, - MV_JAGUAR = MV_10_2, - MV_PANTHER = MV_10_3, - MV_TIGER = MV_10_4, - MV_LEOPARD = MV_10_5 - }; - static const MacVersion MacintoshVersion; -}; - - -extern(C) stringz qtd_qVersion(); -/// -string qVersion() -{ - return fromStringz(qtd_qVersion); -} - -extern(C) bool qtd_qSharedBuild(); -/// -bool qSharedBuild() -{ - return qtd_qSharedBuild; -} - -/// -int qMacVersion() { return QSysInfo.MacintoshVersion; } - -/// -void qUnused(T)(T x) { cast(void) x; } -/// -void Q_UNUSED(T)(T x) { qUnused(x); } - -/* - Debugging and error handling -*/ - -//class QString; -//char[] qPrintable(QString string) { string.toLocal8Bit().constData(); } -//TODO(katrina) These should probably actually call into the c++ functions -void qFatal(string str) -{ - throw new Exception(str); -} - -void qDebug( char[] str ) /* print debug message */ -{ writeln(str); } - -extern (C) void Qt_qWarning( char * ); - -void qWarning(char[] str) /* print warning message */ -{ writeln(str); } - -//QString qt_error_string(int errorCode = -1); -void qCritical(char[] str) /* print critical message */ -{ writeln(str); } - -/* - Forward declarations only. - - In order to use the qDebug() stream, you must #include -*/ -//class QDebug; -//class QNoDebug; -//QDebug qDebug(); -//QDebug qWarning(); -//QDebug qCritical(); - -void qt_noop() {} -//TODO(katrina) Implement these -void qt_assert(char[] assertion, char[] file, int line); - -void qt_assert_x(char[] where, char[] what, char[] file, int line); - -void qt_check_pointer(char[], int); - -enum QtMsgType { QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg, QtSystemMsg = QtCriticalMsg }; - -void qt_message_output(QtMsgType, char[] buf); -//class QtMsgHandler; -//QtMsgHandler qInstallMsgHandler(QtMsgHandler); - -// forward declaration, since qatomic.h needs qglobal.h -class QBasicAtomicPointer(T); - -// POD for Q_GLOBAL_STATIC -class QGlobalStatic(T) -{ -public: - QBasicAtomicPointer!(T) pointer; - bool destroyed; -}; - -// Created as a function-local static to delete a QGlobalStatic -class QGlobalStaticDeleter(T) -{ -public: - QGlobalStatic!(T) globalStatic; - this(QGlobalStatic!(T) _globalStatic) { - globalStatic(_globalStatic); - } - - ~this() - { - delete globalStatic.pointer; - globalStatic.pointer = 0; - globalStatic.destroyed = true; - } -}; - -class QBool -{ - bool b; - -public: - this(bool B) { b = B; } -// void *() const -// { return b ? static_cast(this) : static_cast(0); } -} - -bool qFuzzyCompare(double p1, double p2) -{ - return (qAbs(p1 - p2) <= 0.000000000001 * qMin(qAbs(p1), qAbs(p2))); -} - -bool qFuzzyCompare(float p1, float p2) -{ - return (qAbs(p1 - p2) <= 0.00001f * qMin(qAbs(p1), qAbs(p2))); -} - -/* - This function tests a double for a null value. It doesn't - check whether the actual value is 0 or close to 0, but whether - it is binary 0. -*/ -bool qIsNull(double d) -{ - union U { - double d; - quint64 u; - }; - U val; - val.d = d; - return val.u == cast(quint64)(0); -} - -/* - This function tests a float for a null value. It doesn't - check whether the actual value is 0 or close to 0, but whether - it is binary 0. -*/ -bool qIsNull(float f) -{ - union U { - float f; - quint32 u; - }; - U val; - val.f = f; - return val.u == 0u; -} - -/* - Compilers which follow outdated template instantiation rules - require a class to have a comparison operator to exist when - a QList of this type is instantiated. It's not actually - used in the list, though. Hence the dummy implementation. - Just in case other code relies on it we better trigger a warning - mandating a real implementation. -*/ - - -/* - QTypeInfo - type trait functionality - qIsDetached - data sharing functionality -*/ - -/* - The catch-all template. -*/ -/* -bool qIsDetached(T)(T) { return true; } - -class QTypeInfossss(T) -{ -public: - enum { - isPointer = false, - isComplex = true, - isStatic = true, - isLarge = ((T).sizeof>(void*).sizeof), - isDummy = false - }; -}; - -class QTypeInfo(T) -{ -public: - enum { - isPointer = true, - isComplex = false, - isStatic = false, - isLarge = false, - isDummy = false - }; -}; -*/ - -/* - Specialize a specific type with: - - Q_DECLARE_TYPEINFO(type, flags); - - where 'type' is the name of the type to specialize and 'flags' is - logically-OR'ed combination of the flags below. -*/ -enum { /* TYPEINFO flags */ - Q_COMPLEX_TYPE = 0, - Q_PRIMITIVE_TYPE = 0x1, - Q_STATIC_TYPE = 0, - Q_MOVABLE_TYPE = 0x2, - Q_DUMMY_TYPE = 0x4 -}; - -/* - Specialize a shared type with: - - Q_DECLARE_SHARED(type); - - where 'type' is the name of the type to specialize. NOTE: shared - types must declare a 'bool isDetached(void) const;' member for this - to work. -*/ -void qSwap_helper(T)(ref T value1, ref T value2, T*) -{ - T t = value1; - value1 = value2; - value2 = t; -} -bool qIsDetached(T)(ref T t) { return t.isDetached(); } -void qSwap_helper(T)(ref T value1, ref T value2, T*) -{ - const T.DataPtr t = value1.data_ptr(); - value1.data_ptr() = value2.data_ptr(); - value2.data_ptr() = t; -} - -void qSwap(T)(ref T value1, ref T value2) -{ - T t = value1; - value1 = value2; - value2 = t; -} - -/* - QTypeInfo primitive specializations - TODO(katrina) Find out what we need to do here -*/ -/* -Q_DECLARE_TYPEINFO(bool, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(char, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(signed char, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(uchar, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(short, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(ushort, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(int, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(uint, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(long, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(ulong, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(qint64, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(quint64, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(float, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(double, Q_PRIMITIVE_TYPE); -#ifndef Q_OS_DARWIN -Q_DECLARE_TYPEINFO(long double, Q_PRIMITIVE_TYPE); -#endif -*/ -/* - These functions make it possible to use standard C++ functions with - a similar name from Qt header files (especially template classes). - TODO(katrina) Implement these -*/ -void * qMalloc(size_t size); -void qFree(void * ptr); -void * qRealloc(void * ptr, size_t size); -void * qMemCopy(void * dest, void * src, size_t n); -void * qMemSet(void * dest, int c, size_t n); - -struct QFlags(Enum) -{ -private: - alias void **Zero; - int i; - -public: - alias Enum enum_type; - - public static QFlags!(Enum) opCall(Enum)(QFlags f) { - QFlags!(Enum) res; - res.i = f.i; - return res; - } - - public static QFlags opCall(Enum)(Enum f) { - QFlags!(Enum) res; - res.i = f; - return res; - } - - public static QFlags opCall(Enum)(int f) { - QFlags!(Enum) res; - res.i = cast(Enum) f; - return res; - } - -// this(Zero = 0) : i(0) {} -// this(QFlag f) : i(f) {} - -// QFlags!(Enum) opAssign(QFlags f) { i = f.i; return *this; } - QFlags!(Enum) opAssign(int f) { i = f; return *this; } - QFlags!(Enum) opAndAssign(int mask) { i &= mask; return *this; } - QFlags!(Enum) opAndAssign(uint mask) { i &= mask; return *this; } - QFlags!(Enum) opOrAssign(QFlags f) { i |= f.i; return *this; } - QFlags!(Enum) opOrAssign(Enum f) { i |= f; return *this; } - QFlags!(Enum) opXorAssign(QFlags f) { i ^= f.i; return *this; } - QFlags!(Enum) opXorAssign(Enum f) { i ^= f; return *this; } - - int toInt() { return i; } - - QFlags!(Enum) opOr(QFlags f) { QFlags g; g.i = i | f.i; return g; } - QFlags!(Enum) opOr(Enum f) { QFlags g; g.i = i | f; return g; } - QFlags!(Enum) opXor(QFlags f) { QFlags g; g.i = i ^ f.i; return g; } - QFlags!(Enum) opXor(Enum f) { QFlags g; g.i = i ^ f; return g; } - QFlags!(Enum) opAnd(int mask) { QFlags g; g.i = i & mask; return g; } - QFlags!(Enum) opAnd(uint mask) { QFlags g; g.i = i & mask; return g; } - QFlags!(Enum) opAnd(Enum f) { QFlags g; g.i = i & f; return g; } - QFlags!(Enum) opCom() { QFlags g; g.i = ~i; return g; } - -// bool operator!() { return !i; } - -// bool testFlag(Enum f) { return i & f; } -} - -/* TODO typesafety -#define Q_DECLARE_FLAGS(Flags, Enum)\ -typedef QFlags Flags; -#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags) \ -QFlags operator|(Flags::enum_type f1, Flags::enum_type f2) \ -{ return QFlags(f1) | f2; } \ -QFlags operator|(Flags::enum_type f1, QFlags f2) \ -{ return f2 | f1; } -*/ - -char[] QT_TR_NOOP(char[] x) { return x; } -char[] QT_TRANSLATE_NOOP(char[] s, char[] x) { return x; } -char[] QT_TRANSLATE_NOOP3(char[] s, char[] x, char[] comment) { return x; } - -//class QByteArray; -//QByteArray qgetenv(char[] varName); -//bool qputenv(char[] varName, QByteArray value); - -int qIntCast(double f) { return cast(int)(f); } -int qIntCast(float f) { return cast(int)(f); } - -/* - Reentrant versions of basic rand() functions for random number generation -*/ -void qsrand(uint seed); -int qrand(); - - -/* - This gives us the possibility to check which modules the user can - use. These are purely compile time checks and will generate no code. -*/ - -/* Qt modules */ - -const ushort QT_MODULE_CORE = 0x0001; -const ushort QT_MODULE_GUI = 0x0002; -const ushort QT_MODULE_NETWORK = 0x0004; -const ushort QT_MODULE_OPENGL = 0x0008; -const ushort QT_MODULE_SQL = 0x0010; -const ushort QT_MODULE_XML = 0x0020; -const ushort QT_MODULE_QT3SUPPORTLIGHT = 0x0040; -const ushort QT_MODULE_QT3SUPPORT = 0x0080; -const ushort QT_MODULE_SVG = 0x0100; -const ushort QT_MODULE_ACTIVEQT = 0x0200; -const ushort QT_MODULE_GRAPHICSVIEW = 0x0400; -const ushort QT_MODULE_SCRIPT = 0x0800; -const ushort QT_MODULE_XMLPATTERNS = 0x1000; -const ushort QT_MODULE_HELP = 0x2000; -const ushort QT_MODULE_TEST = 0x4000; -const ushort QT_MODULE_DBUS = 0x8000; - -/* Qt editions */ - -const ushort QT_EDITION_CONSOLE = (QT_MODULE_CORE - | QT_MODULE_NETWORK - | QT_MODULE_SQL - | QT_MODULE_SCRIPT - | QT_MODULE_XML - | QT_MODULE_XMLPATTERNS - | QT_MODULE_TEST - | QT_MODULE_DBUS); -const ushort QT_EDITION_DESKTOPLIGHT = (QT_MODULE_CORE - | QT_MODULE_GUI - | QT_MODULE_QT3SUPPORTLIGHT - | QT_MODULE_TEST - | QT_MODULE_DBUS); -const ushort QT_EDITION_OPENSOURCE = (QT_MODULE_CORE - | QT_MODULE_GUI - | QT_MODULE_NETWORK - | QT_MODULE_OPENGL - | QT_MODULE_SQL - | QT_MODULE_XML - | QT_MODULE_XMLPATTERNS - | QT_MODULE_SCRIPT - | QT_MODULE_QT3SUPPORTLIGHT - | QT_MODULE_QT3SUPPORT - | QT_MODULE_SVG - | QT_MODULE_GRAPHICSVIEW - | QT_MODULE_HELP - | QT_MODULE_TEST - | QT_MODULE_DBUS); -const ushort QT_EDITION_DESKTOP = (QT_EDITION_OPENSOURCE - | QT_MODULE_ACTIVEQT); -const ushort QT_EDITION_UNIVERSAL = QT_EDITION_DESKTOP; -const ushort QT_EDITION_ACADEMIC = QT_EDITION_DESKTOP; -const ushort QT_EDITION_EDUCATIONAL = QT_EDITION_DESKTOP; -const ushort QT_EDITION_EVALUATION = QT_EDITION_DESKTOP; - -mixin QT_END_NAMESPACE; - -private -struct Align -{ - ubyte a; - void* b; -} - -private -const PTR_ALIGN = Align.tupleof[1].alignof; - -private -template AlignPad(size_t base, size_t aligned) -{ - static if( aligned == 0 ) - const AlignPad = base; - else - const AlignPad = ((base+PTR_ALIGN-1)/PTR_ALIGN)*PTR_ALIGN - + aligned; -} - -template InstanceSize(T) -{ - static if( is( T == Object ) ) - const InstanceSize = 2*(void*).sizeof; - else - const InstanceSize = Max!( - AlignPad!( - InstanceSize!(Super!(T)), - InterfaceCount!(T)*(void*).sizeof), - - AlignPad!( - InstanceSizeImpl!(T, 0), - + InterfaceCount!(T)*(void*).sizeof)); -} - -private -template Super(T) -{ - static if( is( T S == super ) ) - alias First!(S) Super; - else - static assert(false, "Can't get super of "~T.mangleof); -} - -private -template First(T) -{ - alias T First; -} - -private -template First(T, Ts...) -{ - alias T First; -} - -private -template InstanceSizeImpl(T, size_t i) -{ - static if( i < T.tupleof.length ) - const InstanceSizeImpl = Max!( - T.tupleof[i].offsetof + T.tupleof[i].sizeof, - InstanceSizeImpl!(T, i+1)); - else - // This is necessary to account for classes without member - // variables. - const InstanceSizeImpl = 2*(void*).sizeof; -} - -private -template Max(size_t a, size_t b) -{ - static if( a > b ) - const Max = a; - else - const Max = b; -} - -private -template InterfaceCount(T) -{ - static if( is( T == Object ) ) - const InterfaceCount = 0u; - else static if( is( T S == super ) ) - const InterfaceCount = InterfaceCountImpl!(S); -} - -private -template InterfaceCountImpl(TBase, TInterfaces...) -{ - const InterfaceCountImpl = TInterfaces.length; -} - -/+ -scope class StackObject(C) -{ - byte[InstanceSize!(C)] data; - bool constructed; - - C opCall(A...)(A args) - { - assert(!constructed); - - auto r = new(&data)C(args); - r.__stackAllocated = true; - constructed = true; - - return r; - } - - ~this() - { - if (constructed) - { - auto obj = cast(C)&data; - delete obj; - } - } -} -+/ - -alias void DArray; - -mixin QT_END_HEADER; - diff -r 552647ec0f82 -r 96a75b1e5b26 qt/QObjectDefs.d --- a/qt/QObjectDefs.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,262 +0,0 @@ -module qt.QObjectDefs; - -//import qt.core.QGlobal; -//import qt.core.Qt; -import QGlobal; - -const byte Q_MOC_OUTPUT_REVISION = 59; - -template QT_TR_FUNCTIONS_NOUTF8() -{ - static QString tr(char[] s, char[] c = null) - { return staticMetaObject.tr(s, c); } - static QString tr(char[] s, char[] c, int n) - { return staticMetaObject.tr(s, c, n); } -} - -template QT_TR_FUNCTIONS_UTF8() -{ - static QString trUtf8(char[] s, char[] c = null) - { return staticMetaObject.trUtf8(s, c); } - static QString trUtf8(char[] s, char[] c, int n) - { return staticMetaObject.trUtf8(s, c, n); } -} - -template QT_TR_FUNCTIONS() -{ - mixin QT_TR_FUNCTIONS_NOUTF8; - mixin QT_TR_FUNCTIONS_UTF8; -} - -template Q_OBJECT_CHECK() -{ - void qt_check_for_QOBJECT_macro(T)(T _q_argument) const - { int i = qYouForgotTheQ_OBJECT_Macro(this, _q_argument); i = i; } -} - -int qYouForgotTheQ_OBJECT_Macro(T)(T, T) { return 0; } - -void qYouForgotTheQ_OBJECT_Macro(T1,T2)(T1, T2) {} - -template Q_OBJECT() -{ - public mixin Q_OBJECT_CHECK; - public static const QMetaObject staticMetaObject; - public const QMetaObject *metaObject() const{} - public void *qt_metacast(const char *){} - public mixin QT_TR_FUNCTIONS; - public int qt_metacall(QMetaObject.Call, int, void **){} -} - -template Q_OBJECT_FAKE() -{ - mixin Q_OBJECT; -} - -template Q_GADGET() -{ - public static const QMetaObject staticMetaObject; -} - -char[] METHOD( char[] a ) { return "0"~a; } -char[] SLOT( char[] a ) { return "1"~a; } -char[] SIGNAL( char[] a ) { return "2"~a; } - -version(QT3_SUPPORT) { - const byte METHOD_CODE = 0; // member type codes - const byte SLOT_CODE = 1; - const byte SIGNAL_CODE = 2; -} - -const byte QMETHOD_CODE = 0; // member type codes -const byte QSLOT_CODE = 1; -const byte QSIGNAL_CODE = 2; - -QArgument!(T) Q_ARG(T)(char [] type, T data) - { return QArgument!(T)(type, data); } - -QReturnArgument!(T) Q_RETURN_ARG(T)(char [] type, T data) - { return QReturnArgument!(T)(type, data); } - -class QGenericArgument -{ -public: - this(char[] aName = null, const void *aData = null) - { _data = aData; _name = aName; } - void *data() const { return cast(void *)(_data); } - char[] name() { return _name; } - -private: - const void *_data; - char[] _name; -}; - -class QGenericReturnArgument : QGenericArgument -{ -}; - -class QArgument(T) : QGenericArgument -{ -public: - this(char[] aName, T aData) - { this(aName, cast(void *)aData); } -}; - -class QReturnArgument(T) : QGenericReturnArgument -{ -public: - this(char[] aName, T aData) - { this(aName, cast(void *)aData); } -}; - -//TODO(katrina) enable this when all the classes it uses are available -/*struct QMetaObject -{ - char[] className() const; - const QMetaObject *superClass() const; - - //TODO(katrina) enable QObject cast(QObject obj) const; - - // ### Qt 4: Merge overloads - QString tr(const char *s, const char *c) const; - QString trUtf8(const char *s, const char *c) const; - QString tr(const char *s, const char *c, int n) const; - QString trUtf8(const char *s, const char *c, int n) const; - - int methodOffset() const; - int enumeratorOffset() const; - int propertyOffset() const; - int classInfoOffset() const; - - int methodCount() const; - int enumeratorCount() const; - int propertyCount() const; - int classInfoCount() const; - - int indexOfMethod(const char *method) const; - int indexOfSignal(const char *signal) const; - int indexOfSlot(const char *slot) const; - int indexOfEnumerator(const char *name) const; - int indexOfProperty(const char *name) const; - int indexOfClassInfo(const char *name) const; - - QMetaMethod method(int index) const; - QMetaEnum enumerator(int index) const; - QMetaProperty property(int index) const; - QMetaClassInfo classInfo(int index) const; - QMetaProperty userProperty() const; - - static bool checkConnectArgs(const char *signal, const char *method); - static QByteArray normalizedSignature(const char *method); - static QByteArray normalizedType(const char *type); - - // internal index-based connect - static bool connect(const QObject *sender, int signal_index, - const QObject *receiver, int method_index, - int type = 0, int *types = 0); - // internal index-based disconnect - static bool disconnect(const QObject *sender, int signal_index, - const QObject *receiver, int method_index); - // internal slot-name based connect - static void connectSlotsByName(QObject *o); - - // internal index-based signal activation - static void activate(QObject *sender, int signal_index, void **argv); - static void activate(QObject *sender, int from_signal_index, int to_signal_index, void **argv); - static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv); - static void activate(QObject *sender, const QMetaObject *, int from_local_signal_index, int to_local_signal_index, void **argv); - // internal guarded pointers - static void addGuard(QObject **ptr); - static void removeGuard(QObject **ptr); - static void changeGuard(QObject **ptr, QObject *o); - - static bool invokeMethod(QObject *obj, const char *member, - qt.core.Qt.ConnectionType, - QGenericReturnArgument ret, - QGenericArgument val0 = QGenericArgument(0), - QGenericArgument val1 = QGenericArgument(), - QGenericArgument val2 = QGenericArgument(), - QGenericArgument val3 = QGenericArgument(), - QGenericArgument val4 = QGenericArgument(), - QGenericArgument val5 = QGenericArgument(), - QGenericArgument val6 = QGenericArgument(), - QGenericArgument val7 = QGenericArgument(), - QGenericArgument val8 = QGenericArgument(), - QGenericArgument val9 = QGenericArgument()); - - static bool invokeMethod(QObject *obj, const char *member, - QGenericReturnArgument ret, - QGenericArgument val0 = QGenericArgument(0), - QGenericArgument val1 = QGenericArgument(), - QGenericArgument val2 = QGenericArgument(), - QGenericArgument val3 = QGenericArgument(), - QGenericArgument val4 = QGenericArgument(), - QGenericArgument val5 = QGenericArgument(), - QGenericArgument val6 = QGenericArgument(), - QGenericArgument val7 = QGenericArgument(), - QGenericArgument val8 = QGenericArgument(), - QGenericArgument val9 = QGenericArgument()) - { - return invokeMethod(obj, member, qt.core.Qt.AutoConnection, ret, val0, val1, val2, val3, - val4, val5, val6, val7, val8, val9); - } - - static bool invokeMethod(QObject *obj, const char *member, - qt.core.Qt.ConnectionType type, - QGenericArgument val0 = QGenericArgument(0), - QGenericArgument val1 = QGenericArgument(), - QGenericArgument val2 = QGenericArgument(), - QGenericArgument val3 = QGenericArgument(), - QGenericArgument val4 = QGenericArgument(), - QGenericArgument val5 = QGenericArgument(), - QGenericArgument val6 = QGenericArgument(), - QGenericArgument val7 = QGenericArgument(), - QGenericArgument val8 = QGenericArgument(), - QGenericArgument val9 = QGenericArgument()) - { - return invokeMethod(obj, member, type, QGenericReturnArgument(), val0, val1, val2, - val3, val4, val5, val6, val7, val8, val9); - } - - - static bool invokeMethod(QObject *obj, const char *member, - QGenericArgument val0 = QGenericArgument(0), - QGenericArgument val1 = QGenericArgument(), - QGenericArgument val2 = QGenericArgument(), - QGenericArgument val3 = QGenericArgument(), - QGenericArgument val4 = QGenericArgument(), - QGenericArgument val5 = QGenericArgument(), - QGenericArgument val6 = QGenericArgument(), - QGenericArgument val7 = QGenericArgument(), - QGenericArgument val8 = QGenericArgument(), - QGenericArgument val9 = QGenericArgument()) - { - return invokeMethod(obj, member, qt.core.Qt.AutoConnection, QGenericReturnArgument(), val0, - val1, val2, val3, val4, val5, val6, val7, val8, val9); - } - - enum Call { - InvokeMetaMethod, - ReadProperty, - WriteProperty, - ResetProperty, - QueryPropertyDesignable, - QueryPropertyScriptable, - QueryPropertyStored, - QueryPropertyEditable, - QueryPropertyUser - }; - -version(QT3_SUPPORT) { - const char *superClassName() const; -} - - struct d_struct{ // private data - const QMetaObject *superdata; - const char *stringdata; - const uint *data; - const QMetaObject **extradata; - }; - d_struct d; -}; -*/ diff -r 552647ec0f82 -r 96a75b1e5b26 qt/boost-license-1.0.txt --- a/qt/boost-license-1.0.txt Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -Boost Software License - Version 1.0 - August 17th, 2003 - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff -r 552647ec0f82 -r 96a75b1e5b26 qt/core/CMakeLists.txt --- a/qt/core/CMakeLists.txt Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -set(QT_CORE_SRCS_D -Qt.d -QChildEvent.d -QCoreApplication.d -QEvent.d -QEventLoop.d -QObject.d -QTimerEvent.d -QTranslator.d -) diff -r 552647ec0f82 -r 96a75b1e5b26 qt/core/QList.d --- a/qt/core/QList.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,627 +0,0 @@ -module qt.core.QList; - -import qt.QGlobal; -import qt.QtdObject; -import qt.qtd.Atomic; -import qt.qtd.MetaMarshall; -import qt.core.QTypeInfo; -import qt.core.QString; - -import core.stdc.stdlib : qRealloc = realloc, qFree = free, qMalloc = malloc; -import core.stdc.string : memcpy, memmove; - -import std.traits; - -enum INT_MAX = int.max; - -bool isComplex(T)() - if (is(T.QTypeInfo)) -{ - return T.QTypeInfo.isComplex; -} - -bool isStatic(T)() - if (is(T.QTypeInfo)) -{ - return T.QTypeInfo.isStatic; -} - -bool isLarge(T)() - if (is(T.QTypeInfo)) -{ - return T.QTypeInfo.isLarge; -} - -template isQtReference(T) -{ - enum isQtReference = isQObjectType!T || isObjectType!T || isValueType!T || is(T == string); -} - -int qAllocMore(int alloc, int extra) -{ - if (alloc == 0 && extra == 0) - return 0; - const int page = 1 << 12; - int nalloc; - alloc += extra; - if (alloc < 1<<6) { - nalloc = (1<<3) + ((alloc >>3) << 3); - } else { - // don't do anything if the loop will overflow signed int. - if (alloc >= INT_MAX/2) - return INT_MAX; - nalloc = (alloc < page) ? 1 << 3 : page; - while (nalloc < alloc) { - if (nalloc <= 0) - return INT_MAX; - nalloc *= 2; - } - } - return nalloc - extra; -} - -void q_new_at(T)(T* ptr, const ref T t) -{ - memcpy(ptr, &t, T.sizeof); -/* static if (__traits(compiles, ptr.__postblit())) DMD bug #3539 - ptr.__postblit();*/ -} - -T* q_new(T)(const ref T t) -{ - T* ptr = cast(T*) qMalloc(T.sizeof); - q_new_at!T(ptr, t); - return ptr; -} - -void q_delete(T)(T* t) -{ - static if (__traits(compiles, t.__dtor())) - t.__dtor(); - qFree(t); -} - -private int grow(int size) -{ - // dear compiler: don't optimize me out. -// synchronized { - int x = qAllocMore(size * (void*).sizeof, QListData.DataHeaderSize) / (void*).sizeof; - return x; -// } -} - -struct QListData { -private: - struct Data { - Atomic!int ref_; - int alloc, begin, end; - uint sharable; - void*[1] array; - } - - enum { DataHeaderSize = Data.sizeof - (void*).sizeof } - - static Data shared_null; - Data *d; - - static this() - { - shared_null = Data(Atomic!int(1), 0, 0, 0, true, [null]); - } - - -// Data *detach(); // remove in 5.0 - - Data* detach2() - { - Data* x = d; - d = cast(Data*)(qMalloc(DataHeaderSize + x.alloc * (void*).sizeof)); - if (!d) - qFatal("QList: Out of memory"); - - memcpy(d, x, DataHeaderSize + x.alloc * (void*).sizeof); - d.alloc = x.alloc; - d.ref_.store(1); - d.sharable = true; - if (!d.alloc) - d.begin = d.end = 0; - - return x; - } - - void realloc(int alloc) - { -// assert(d.ref_ == 1); - Data* x = cast(Data*)(qRealloc(d, DataHeaderSize + alloc * (void*).sizeof)); - if (!x) - qFatal("QList: Out of memory"); - - d = x; - d.alloc = alloc; - if (!alloc) - d.begin = d.end = 0; - } - - void** append() - { -// #TODO Q_ASSERT(d.ref_ == 1); - if (d.end == d.alloc) { - int n = d.end - d.begin; - if (d.begin > 2 * d.alloc / 3) { - memcpy(d.array.ptr + n, d.array.ptr + d.begin, n * (void*).sizeof); - d.begin = n; - d.end = n * 2; - } else { - realloc(grow(d.alloc + 1)); - } - } - return d.array.ptr + d.end++; - } - - void **append(const ref QListData l) - { -// Q_ASSERT(d.ref_ == 1); - int e = d.end; - int n = l.d.end - l.d.begin; - if (n) { - if (e + n > d.alloc) - realloc(grow(e + l.d.end - l.d.begin)); - memcpy(d.array.ptr + d.end, l.d.array.ptr + l.d.begin, n * (void*).sizeof); - d.end += n; - } - return d.array.ptr + e; - } - - void **prepend() - { -// Q_ASSERT(d.ref_ == 1); - if (d.begin == 0) { - if (d.end >= d.alloc / 3) - realloc(grow(d.alloc + 1)); - - if (d.end < d.alloc / 3) - d.begin = d.alloc - 2 * d.end; - else - d.begin = d.alloc - d.end; - - memmove(d.array.ptr + d.begin, d.array.ptr, d.end * (void*).sizeof); - d.end += d.begin; - } - return d.array.ptr + --d.begin; - } - - void **insert(int i) - { -// Q_ASSERT(d.ref_ == 1); - if (i <= 0) - return prepend(); - if (i >= d.end - d.begin) - return append(); - - bool leftward = false; - int size = d.end - d.begin; - - if (d.begin == 0) { - if (d.end == d.alloc) { - // If the array is full, we expand it and move some items rightward - realloc(grow(d.alloc + 1)); - } else { - // If there is free space at the end of the array, we move some items rightward - } - } else { - if (d.end == d.alloc) { - // If there is free space at the beginning of the array, we move some items leftward - leftward = true; - } else { - // If there is free space at both ends, we move as few items as possible - leftward = (i < size - i); - } - } - - if (leftward) { - --d.begin; - memmove(d.array.ptr + d.begin, d.array.ptr + d.begin + 1, i * (void*).sizeof); - } else { - memmove(d.array.ptr + d.begin + i + 1, d.array.ptr + d.begin + i, - (size - i) * (void*).sizeof); - ++d.end; - } - return d.array.ptr + d.begin + i; - } - - void remove(int i) - { -// Q_ASSERT(d.ref_ == 1); - i += d.begin; - if (i - d.begin < d.end - i) { - if (int offset = i - d.begin) - memmove(d.array.ptr + d.begin + 1, d.array.ptr + d.begin, offset * (void*).sizeof); - d.begin++; - } else { - if (int offset = d.end - i - 1) - memmove(d.array.ptr + i, d.array.ptr + i + 1, offset * (void*).sizeof); - d.end--; - } - } - - void remove(int i, int n) - { -// Q_ASSERT(d.ref_ == 1); - i += d.begin; - int middle = i + n/2; - if (middle - d.begin < d.end - middle) { - memmove(d.array.ptr + d.begin + n, d.array.ptr + d.begin, - (i - d.begin) * (void*).sizeof); - d.begin += n; - } else { - memmove(d.array.ptr + i, d.array.ptr + i + n, - (d.end - i - n) * (void*).sizeof); - d.end -= n; - } - } - - void move(int from, int to) - { -// Q_ASSERT(d.ref_ == 1); - if (from == to) - return; - - from += d.begin; - to += d.begin; - void *t = d.array.ptr[from]; - - if (from < to) { - if (d.end == d.alloc || 3 * (to - from) < 2 * (d.end - d.begin)) { - memmove(d.array.ptr + from, d.array.ptr + from + 1, (to - from) * (void*).sizeof); - } else { - // optimization - if (int offset = from - d.begin) - memmove(d.array.ptr + d.begin + 1, d.array.ptr + d.begin, offset * (void*).sizeof); - if (int offset = d.end - (to + 1)) - memmove(d.array.ptr + to + 2, d.array.ptr + to + 1, offset * (void*).sizeof); - ++d.begin; - ++d.end; - ++to; - } - } else { - if (d.begin == 0 || 3 * (from - to) < 2 * (d.end - d.begin)) { - memmove(d.array.ptr + to + 1, d.array.ptr + to, (from - to) * (void*).sizeof); - } else { - // optimization - if (int offset = to - d.begin) - memmove(d.array.ptr + d.begin - 1, d.array.ptr + d.begin, offset * (void*).sizeof); - if (int offset = d.end - (from + 1)) - memmove(d.array.ptr + from, d.array.ptr + from + 1, offset * (void*).sizeof); - --d.begin; - --d.end; - --to; - } - } - d.array.ptr[to] = t; - } - - void **erase(void **xi) - { -// Q_ASSERT(d.ref_ == 1); - int i = xi - (d.array.ptr + d.begin); - remove(i); - return d.array.ptr + d.begin + i; - } - - int size() const { return d.end - d.begin; } - bool isEmpty() const { return d.end == d.begin; } - const (void*)* at(int i) const { return d.array.ptr + d.begin + i; } - const (void*)* begin() const { return d.array.ptr + d.begin; } - const (void*)* end() const { return d.array.ptr + d.end; } -} - -import std.stdio; -import std.conv; - -alias void Dummy; // DMD bug #3538 - -struct QList(T, alias Default = Dummy) -{ - static if (is(Default == Dummy)) - alias QTypeInfo!T TI; - else - alias Default TI; - - struct Node - { - void *v; - - static if (isQObjectType!T || isObjectType!T || isValueType!T || is(T == string)) // binded Qt types - { - T t() - { - static if(is(T == string)) - { - void* ptr = cast(void*)(TI.isLarge || TI.isStatic ? v : &this); - return QStringUtil.toNativeString(ptr); - } - else static if (isValueType!T) - { - void* ptr = cast(void*)(isLarge!T() || isStatic!T() ? v : &this); - return new T(ptr, QtdObjectFlags.nativeOwnership); - } - else - { - return T.__getObject( *cast(void**)(&this) ); - } - } - } - else // native types - { - ref T t() - { - static if(TI.isLarge || TI.isStatic) - return *cast(T*)(this.v); - else - return *cast(T*)(&this); - } - } - } - - union { - QListData p; - QListData.Data* d; - } - -public: - /* - void output() - { - writeln("QList atomic ", d.ref_.load()); - } - */ - - static QList!T opCall() - { - QList!T res; -// writeln("QList opCall"); - - res.d = &QListData.shared_null; - res.d.ref_.increment(); - - return res; - } - - this(this) - { -// writeln("QList postblit"); - d.ref_.increment(); - if (!d.sharable) - detach_helper(); - } - - ~this() - { -// writeln("QList ~this"); - if (d && !d.ref_.decrement()) - free(d); - } - - ref QList!T opAssign(const ref QList!T l) - { -// writeln("QList opAssign"); - if (d != l.d) { - QListData.Data* nd = cast(QListData.Data*)l.d; - nd.ref_.increment(); - if (!d.ref_.decrement()) - free(d); - d = nd; - if (!d.sharable) - detach_helper(); - } - return this; - } - - int length() const { return p.size(); } - int size() const { return length; } - - void detach() { if (d.ref_.load() != 1) detach_helper(); } - - private void detach_helper() - { - Node *n = cast(Node*)(p.begin()); - QListData.Data* x = p.detach2(); - node_copy(cast(Node*)(p.begin()), cast(Node*)(p.end()), n); - if (!x.ref_.decrement()) - free(x); - } - - void append(const T t) // fix to const ref for complex types TODO - { - detach(); - static if (isQObjectType!T || isObjectType!T || isValueType!T) - { - node_construct(cast(Node*)(p.append()), t); - } - else - { - const T cpy = t; - node_construct(cast(Node*)(p.append()), cpy); - } - } - - alias append opCatAssign; - - static if (isQObjectType!T || isObjectType!T || isValueType!T || is(T == string)) - { - T at(int i) const - { - assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); - return (cast(Node*)(p.at(i))).t(); - } - T opIndex(int i) - { - assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); - return (cast(Node*)(p.at(i))).t(); - } - } - else - { - const (T) at(int i) const // DMD BUG - { - assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); - return (cast(Node*)(p.at(i))).t(); - } - ref T opIndex(int i) - { - assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); - return (cast(Node*)(p.at(i))).t(); - } - } - - static if (isQObjectType!T || isObjectType!T || isValueType!T) //binded types - void node_construct(Node *n, const T t) - { - static if (isValueType!T) - { - if (isLarge!T() || isStatic!T()) // TODO should be static if - n.v = T.__constructNativeCopy(t.__nativeId); // n.v = new T(t); - else if (isComplex!T()) - T.__constructPlacedNativeCopy(t.__nativeId, n); // new (n) T(t); - else - T.__constructPlacedNativeCopy(t.__nativeId, n); // TODO should be *cast(T*)(n) = cast(T)(t); as it is a primitive type. fix when they are implemented with structs - } - else // in case of QObject or Object Qt types we place a pointer to a native object in the node - n = cast(Node*) t.__nativeId; - } - else static if (is(T == string)) - { - void node_construct(Node *n, T t) - { - QString.__constructPlacedQString(n, t); - } - } - else // native types - void node_construct(Node *n, const ref T t) - { - static if (TI.isLarge || TI.isStatic) - n.v = q_new!T(t); // n.v = new T(t); - else static if (TI.isComplex) - q_new_at(n, t); // new (n) T(t); - else - *cast(T*)(n) = cast(T)(t); - } - - void node_copy(Node *from, Node *to, Node *src) - { -// writeln("QList node_copy"); - static if (isQObjectType!T || isObjectType!T) - {} // ensure to do nothing. copying only a pointer - else static if(is(T == string)) - { - while(from != to) // TODO when porting to Qt 5 ensure that QTypeInfo.isLarge and .isStatic == false - QString.__constructPlacedNativeCopy(src++, from++); // new (from++) T(*reinterpret_cast(src++)); - } - else static if (isValueType!T) - { - if (TI.isLarge || TI.isStatic) // TODO should be static if - while(from != to) - (from++).v = T.__constructNativeCopy((src++).v); // (from++)->v = new T(*reinterpret_cast((src++)->v)); - else if (TI.isComplex) - while(from != to) - T.__constructPlacedNativeCopy(src++, from++); // new (from++) T(*reinterpret_cast(src++)); - } - else static if (TI.isLarge || TI.isStatic) - while(from != to) - (from++).v = q_new!T(*cast(T*)((src++).v)); - else static if (TI.isComplex) - while(from != to) - q_new_at(from++, *cast(T*)(src++)); - } - - T[] toArray() - { - T[] res; - res.length = this.length; - for(int i = 0; i < res.length; ++i) - { - static if (isValueType!T) - res[i] = new T(T.__constructNativeCopy(this.at(i).__nativeId)); // Node should probably provide a ptr method to directly extract pointer to the native value stored in the list to avoid creating a dummy D object in t() - else - res[i] = this.opIndex(i); - } - return res; - } - - void free(QListData.Data* data) - { -// writeln("QList data destroyed"); - node_destruct(cast(Node*)(data.array.ptr + data.begin), - cast(Node*)(data.array.ptr + data.end)); - if (data.ref_.load() == 0) - qFree(data); - } - - void node_destruct(Node *from, Node *to) - { - static if (isQObjectType!T || isObjectType!T) //binded types - {} // removing just pointers, do nothing - else static if (is(T == string)) - { - while (from != to) - --to, QString.__callNativeDestructor(to); - } - else static if (isValueType!T) //binded value types - { - if (isLarge!T() || isStatic!T()) // TODO should be static if - while (from != to) - --to, T.__deleteNativeObject(to.v); - else if (isComplex!T()) - while (from != to) - --to, T.__callNativeDestructor(to); - } - else - { - static if (TI.isLarge || TI.isStatic) - while (from != to) --to, q_delete(cast(T*)(to.v)); - else static if (TI.isComplex) - while (from != to) --to, cast(T*)(to).__dtor(); - } - } - - //iteration support - int opApply(int delegate(ref T) dg) - { - int result = 0; - int sz = this.length; - for (int i = 0; i < sz; i++) - { - static if (isQtReference!T) - { - T t = this[i]; // hack to avoid "is not an lvalue" error, since dg accepts ref T - result = dg(t); - } - else - result = dg(this[i]); - - if (result) - break; - } - return result; - } -} - -alias QList!string QStringList; - -QList!T toQList(T)(T[] src) -{ - auto res = QList!T.opCall(); - foreach(elem; src) - res.append(elem); - return res; -} - -QList!T qList(T)() -{ - return QList!T.opCall(); -} - -extern(C) void qtd_create_QList(void *nativeId); -extern(C) void qtd_create_QList_double(void *nativeId); - -extern(C) void qtd_create_QList_QObject(void *nativeId); diff -r 552647ec0f82 -r 96a75b1e5b26 qt/core/QMetaObject.d --- a/qt/core/QMetaObject.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,390 +0,0 @@ -module qt.core.QMetaObject; - -import qt.QGlobal; -import qt.core.QObject; -import qt.QtdObject; - -import std.algorithm; -import std.string; -import std.stdio; - -class Meta -{ - string name; -} - -class MetaType : Meta -{ - this() - { - } -} - -class MetaVariable : Meta -{ - MetaType type; -} - -class MetaCallable : Meta { } - -class MetaMethod : Meta { } - -class QMetaArgument : MetaVariable { } - -class QMetaMethod : MetaMethod -{ -// QMetaArgument[] arguments; - string signature; - int indexOfMethod; - - this(string signature_, int indexOfMethod_) - { - signature = signature_; - indexOfMethod = indexOfMethod_; - } - - string args() const - { - int openBracket = indexOf(signature, '('); - if(signature.length - openBracket - 2 > 0) - return signature[openBracket + 1 .. $-1]; - else - return ""; - } - - string name() const - { - int openBracket = indexOf(signature, '('); - return signature[0..openBracket]; - } -} - -class QMetaSignal : QMetaMethod -{ - this(string signature_, int indexOfMethod_) - { - super(signature_, indexOfMethod_); - } -} - -class QMetaSlot : QMetaMethod -{ - this(string signature_, int indexOfMethod_) - { - super(signature_, indexOfMethod_); - } -} - -class MetaObject : MetaType -{ - MetaObject _base; -} - -struct QMetaObjectNative -{ - QMetaObjectNative *superdata; - immutable(char) *stringdata; - const(uint) *data; - void *extradata; -} - -class QMetaException : Exception { this(string msg) { super(msg); } } - -final class QMetaObject -{ - enum Call - { - InvokeMetaMethod, - ReadProperty, - WriteProperty, - ResetProperty, - QueryPropertyDesignable, - QueryPropertyScriptable, - QueryPropertyStored, - QueryPropertyEditable, - QueryPropertyUser, - CreateInstance - } - - private - { - QMetaObjectNative* _nativeId; - QMetaObject _base; // super class - QMetaObject _firstDerived; // head of the linked list of derived classes - QMetaObject _next; // next sibling on this derivation level - QMetaMethod[] _methods; - ClassInfo _classInfo; - - QObject function(void* nativeId) _createWrapper; - } - - private void addDerived(QMetaObject mo) - { - mo._next = _firstDerived; - _firstDerived = mo; - } - - // NOTE: construction is split between this non-templated constructor and 'construct' function below. - this(QMetaObjectNative* nativeId, QMetaObject base) - { - _nativeId = nativeId; - if (base) - { - base.addDerived(this); - _base = base; - } - } - - // TODO: remove when D acquires templated constructors - void construct(T : QObject, Concrete = T)() - { - _classInfo = T.classinfo; - - _createWrapper = function QObject(void* nativeId) { - // COMPILER BUG: cast is should not be needed - auto obj = new Concrete(nativeId, cast(QtdObjectFlags)(QtdObjectFlags.nativeOwnership | QtdObjectFlags.dynamicEntity)); - // TODO: Probably this should be a virtual call from T's constructor - T.__createEntity(nativeId, cast(void*)obj); - return obj; - }; - } - - /++ - +/ - QMetaObject base() - { - return _base; - } - - /++ - +/ - QMetaObjectNative* nativeId() - { - return _nativeId; - } - - /++ - +/ - ClassInfo classInfo() - { - return _classInfo; - } - - const (QMetaMethod[]) methods() - { - return _methods; - } - - void addMethod(QMetaMethod method_) - { - _methods ~= method_; - } - - QMetaMethod lookUpMethod(string slot) - { - foreach (method; _methods) - if (method.signature == slot) - return method; - if (_base) - return _base.lookUpMethod(slot); - else - return null; - } - - QMetaSignal lookUpSignal(string signal) - { - foreach (method; _methods) - if (method.signature == signal && cast(QMetaSignal)method) - return cast(QMetaSignal)method; - if (_base) - return _base.lookUpSignal(signal); - else - return null; - } - - QMetaMethod[] lookUpMethodOverloads(string methodName) - { - typeof(return) result; - foreach (method; _methods) - if (method.name == methodName) - result ~= method; - if (_base) - result ~= _base.lookUpMethodOverloads(methodName); - return result; - } - - QMetaSignal[] lookUpSignalOverloads(string signalName) - { - typeof(return) result; - foreach (method; _methods) - if (method.name == signalName && cast(QMetaSignal)method) - result ~= cast(QMetaSignal)method; - if (_base) - result ~= _base.lookUpSignalOverloads(signalName); - return result; - } - - private QMetaObject lookupDerived(void*[] moIds) - { - assert (moIds.length >= 1); - - for (auto mo = _firstDerived; mo !is null; mo = mo._next) - { - if (mo._nativeId == moIds[0]) - { - if (moIds.length == 1) // exact match found - return mo; - else // look deeper - return mo.lookupDerived(moIds[1..$]); - } - } - - // no initialized wrapper that matches the native object. - // use the base class wrapper - return this; - } - - QObject getObject(void* nativeObjId) - { - QObject result; - - if (nativeObjId) - { - result = cast(QObject)qtd_get_d_qobject(nativeObjId); - if (!result) - { - auto moId = qtd_QObject_metaObject(nativeObjId); - if (_nativeId == moId) - result = _createWrapper(nativeObjId); - else - { - // get native metaobjects for the entire derivation lattice - // up to, but not including, the current metaobject. - size_t moCount = 1; - - for (void* tmp = moId;;) - { - tmp = qtd_QMetaObject_superClass(tmp); - assert(tmp); - if (tmp == _nativeId) - break; - moCount++; - } - - void*[] moIds = (cast(void**)alloca(moCount * (void*).sizeof))[0..moCount]; - - moIds[--moCount] = moId; - while (moCount > 0) - moIds[--moCount] = moId = qtd_QMetaObject_superClass(moId); - - result = lookupDerived(moIds)._createWrapper(nativeObjId); - } - } - } - - return result; - } - - static void activate(QObject sender, QMetaObject m, int local_signal_index, void **argv) - { - qtd_QMetaObject_activate_3(sender.__nativeId, m.nativeId, local_signal_index, argv); - } - - static void activate(QObject sender, QMetaObject m, int from_local_signal_index, int to_local_signal_index, void **argv) - { - qtd_QMetaObject_activate_4(sender.__nativeId, m.nativeId, from_local_signal_index, to_local_signal_index, argv); - } - - static bool connect(const QObject sender, int signal_index, - const QObject receiver, int method_index, - int type = 0, int *types = null) - { - return qtd_QMetaObject_connect(sender.__nativeId, signal_index, receiver.__nativeId, method_index, type, types); - } - - int indexOfMethod_Cpp(string method) - { - return qtd_QMetaObject_indexOfMethod(_nativeId, toStringz(method)); - } - - int methodCount() - { - return qtd_QMetaObject_methodCount(_nativeId); - } - - static void connectImpl(QObject sender, string signalString, QObject receiver, string methodString, int type) - { - QMetaSignal[] signals; - QMetaMethod[] methods; - QMetaSignal signal; - QMetaMethod method; - - if(indexOf(signalString, '(') > 0) - signal = sender.metaObject.lookUpSignal(signalString); - else - signals = sender.metaObject.lookUpSignalOverloads(signalString); // parameters not specified. Looking for a match - - if(indexOf(methodString, '(') > 0) - method = receiver.metaObject.lookUpMethod(methodString); - else - methods = receiver.metaObject.lookUpMethodOverloads(methodString); // parameters not specified. Looking for a match - - if(!signal && !method) - { - Top: - foreach(sig; signals) - foreach(meth; methods) - if(startsWith(sig.args, meth.args)) - { - signal = sig; - method = meth; - break Top; - } - } - else if (!signal) - { - foreach(sig; signals) - if(startsWith(sig.args, method.args)) - { - signal = sig; - break; - } - } - else if (!method) - { - foreach(meth; methods) - if(startsWith(signal.args, meth.args)) - { - method = meth; - break; - } - } - - bool success = false; - - if(!signal && !method) - { - success = false; - } - else - { - int signalIndex = signal.indexOfMethod; - int methodIndex = method.indexOfMethod; - success = QMetaObject.connect(sender, signalIndex, receiver, methodIndex, type); - } - - if(!success) - throw new QMetaException("QMetaObject: Signal " ~ signalString ~ " and slot " ~ methodString ~ " cannot be found"); - } -} - -extern(C) void qtd_QMetaObject_activate_3(void* sender, void* m, int local_signal_index, void **argv); -extern(C) void qtd_QMetaObject_activate_4(void *sender, void* m, int from_local_signal_index, int to_local_signal_index, void **argv); -extern(C) bool qtd_QMetaObject_connect(const void* sender, int signal_index, - const void* receiver, int method_index, - int type, int *types); - -extern(C) int qtd_QMetaObject_indexOfMethod(void *nativeId, const(char) *method); -extern(C) int qtd_QMetaObject_methodCount(void *nativeId); - -extern(C) void* qtd_QMetaObject_superClass(void* nativeId); diff -r 552647ec0f82 -r 96a75b1e5b26 qt/core/QMetaType.d --- a/qt/core/QMetaType.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -module qt.core.QMetaType; -public import qt.core.Qt; -private import qt.core.QDataStream; - -version (Tango) -{ - import tango.core.Array; - import tango.stdc.stringz; - import tango.core.Traits; -} - -alias extern(C) void *function(void *copy) Ctor; -alias extern(C) void function(void *obj) Dtor; -alias extern(C) void function(void *stream, void * object) StreamOp; - -struct DArrayToC -{ - void[] array; -} - -public template MetaTypeOps(T) -{ - // TODO: - // static assert(typeof(new T), "Type " ~ T.stringof ~ " has no default constructor"); - // static assert(typeof(new T(T.init))), "Type " ~ T.stringof ~ " has no default copy constructor"); - - extern(C) void* ctor(void* copy) - { - static if (is(T == class) || is(T == interface)) - { - return cast(void*)(copy ? new T(cast(T)copy) : new T); - } - else static if (isDynamicArrayType!(T) || isStaticArrayType!(T) ) - { - auto darray = new DArrayToC; - if(copy) - darray.array = (cast(DArrayToC*)copy).array.dup; - return cast(void*)darray; - } - else - { - auto data = new T; - if(copy) - *data = *cast(T*)copy; - return cast(void*)data; - } - } - - - extern(C) void dtor(void* obj) - { - static if (is(T == class) || is(T == interface)) - { - auto tmp = cast(T)obj; - delete tmp; - } - else - { - auto tmp = cast(T*)obj; - delete tmp; - } - } -} - -public int qRegisterMetaType(T)(string name = null) -{ - if (!name.length) - name = typeid(T).toString; - - return qtd_registerType(toStringz(name), &MetaTypeOps!(T).ctor, &MetaTypeOps!(T).dtor); -} - -/* Not work.... -private class DataStreamPriv: QDataStream -{ - this(void * cobj) - { - super(cobj); - } -} -*/ -/* -public void qRegisterMetaTypeStreamOperators(T)(void function(ref QDataStream, T ) saveOp, void function (ref QDataStream, ref T) loadOp, string name = null) -{ - static void function(ref QDataStream, T ) SaveOp; - static void function (ref QDataStream, ref T) LoadOp; - SaveOp = saveOp; - LoadOp = loadOp; - - if (!name.length) - name = typeid(T).toString; - - extern(C) void saveOpC(void *stream, void *object) - { - QDataStream dstream = new DataStreamPriv(stream); - Stdout(object).newline; - static if (is(T == class) || is(T == interface)) - SaveOp(dstream, cast(T)object); - else - SaveOp(dstream, *cast(T*)object); - } - - extern(C) void loadOpC(void *stream, void *object) - { - //return stream; - } - - qtd_registerStreamOperators(toStringz(name), cast(StreamOp)&saveOpC, cast(StreamOp)&loadOpC); -} -*/ -private extern(C) void qtd_registerStreamOperators(char *typeName, StreamOp saveOp, StreamOp loadOp); -private extern(C) int qtd_registerType(in char* namePtr, Ctor ctor, Dtor dtor); -extern(C) int qtd_MetatypeId(in char *id); // TODO: wrap to D. \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 qt/core/QString.d --- a/qt/core/QString.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,112 +0,0 @@ -module qt.core.QString; - -import qt.QGlobal; - -version (Tango) -{ - public import tango.text.convert.Utf : toUTF8 = toString; -} -else -{ - public import std.utf : toUTF8; -} - -struct QString -{ - public static QString opCall() - { - QString str; - qtd_QString_placed_ctor(&str); - return str; - } - - ~this() - { - qtd_QString_call_destructor(&this); - } - - void opAssign(string str) - { - qtd_QString_assign_fromUtf8(&this, str); - } - - this(string str) - { - qtd_QString_new_fromUtf8_at(&this, str); - } - - public static void __constructPlacedQString(void* place, string source) { - qtd_QString_new_fromUtf8_at(place, source); - } - - // service stuff - static void* __constructNativeCopy(const void* orig) { - return qtd_QString_QString_QString(cast(void*)orig); - } - - static void* __constructPlacedNativeCopy(const void* orig, void* place) { - return qtd_QString_placed_copy(orig, place); - } - - public static void __deleteNativeObject(void* ptr) { - qtd_QString_destructor(ptr); - } - - public static void __callNativeDestructor(void* ptr) { - qtd_QString_call_destructor(ptr); - } - struct QTypeInfo - { - enum bool isComplex = true; - enum bool isStatic = false; - enum bool isLarge = false; - enum bool isPointer = false; - enum bool isDummy = false; - } - -private: - void *dummy; // sizeof(QString) == sizeof(void*) -} - -struct QStringUtil -{ - public static final string toNativeString(void* qstring) { - wchar* arr = qtd_QString_utf16(qstring); - int size = qtd_QString_size(qstring); - return .toUTF8(arr[0..size]); - } - - public static string fromUtf8(string source) { - return source; - } - - public static QStringUtil opCall(void* ptr, bool proxy) { - QStringUtil str; - str.__nativeId = ptr; - return str; - } - - public void* __nativeId; - - public final string toNativeString() { - return QStringUtil.toNativeString(__nativeId); - } - - public void assign(string text) { - qtd_QString_operatorAssign(__nativeId, text); - } -} -private extern(C) void* qtd_QString_placed_copy(const void* orig, void* place); - -private extern (C) void qtd_QString_destructor(void* __this_nativeId); -private extern (C) void qtd_QString_call_destructor(void *ptr); - -private extern (C) void* qtd_QString_QString_QString(void* orig); - -private extern (C) wchar* qtd_QString_utf16(void* __this_nativeId); -private extern (C) int qtd_QString_size(void* __this_nativeId); -private extern (C) void qtd_QString_operatorAssign(void* __this_nativeId, string text); -private extern (C) void* qtd_QString_new_fromUtf8_at(void* place, string text); - -private extern (C) void qtd_QString_placed_ctor(void* place); -private extern (C) void qtd_QString_assign_fromUtf8(QString *__qt_this, string text); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 qt/core/QTypeInfo.d --- a/qt/core/QTypeInfo.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,139 +0,0 @@ -module qt.core.QTypeInfo; - -//import qt.QGlobal; -//import qt.qtd.Atomic; - -/* - The catch-all template. -*/ -import std.traits; - -import qt.qtd.MetaMarshall; -import qt.core.QString; - -bool qIsDetached(T)(ref T) { return true; } - -template isBasicType(T) -{ - enum isBasicType = isNumeric!T || is(T == bool) || is(T == enum); -} - -template QTypeInfo(T) -{ - static if(is(T == string)) - { - alias QString.QTypeInfo QTypeInfo; - } - else static if(isBasicType!T) - { - public enum - { - isPointer = false, - isComplex = false, - isStatic = false, - isLarge = (T.sizeof > (void*).sizeof), - isDummy = false - } - } - else static if(is(T.QTypeInfo)) - { - alias T.QTypeInfo QTypeInfo; // alias member QTypeInfo - } - else static if ( isQObjectType!T || isObjectType!T ) - { - public enum // are pointers - { - isPointer = true, - isComplex = false, - isStatic = false, - isLarge = false, - isDummy = false - } - } - else // default parameters - { - public enum - { - isPointer = isPointer!T, - isComplex = !isPointer, - isStatic = !isPointer, - isLarge = (T.sizeof > (void*).sizeof), - isDummy = false - } - } -} - - -/* - Specialize a specific type with: - - Q_DECLARE_TYPEINFO(type, flags); - - where 'type' is the name of the type to specialize and 'flags' is - logically-OR'ed combination of the flags below. -*/ - -/* presents in QGlobal -enum { /* TYPEINFO flags - Q_COMPLEX_TYPE = 0, - Q_PRIMITIVE_TYPE = 0x1, - Q_STATIC_TYPE = 0, - Q_MOVABLE_TYPE = 0x2, - Q_DUMMY_TYPE = 0x4 -} -*/ - -/* -template QTypeInfo(alias FLAGS) -{ - template QTypeInfo(TYPE) - { - public: - enum { - isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0), - isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), - isLarge = (TYPE.sizeof > (void*).sizeof), - isPointer = false, - isDummy = (((FLAGS) & Q_DUMMY_TYPE) != 0) - } - } -} -*/ -/* - Specialize a shared type with: - - Q_DECLARE_SHARED(type); - - where 'type' is the name of the type to specialize. NOTE: shared - types must declare a 'bool isDetached(void) const;' member for this - to work. -*/ -/* -#if defined Q_CC_MSVC && _MSC_VER < 1300 -template -inline void qSwap_helper(T &value1, T &value2, T*) -{ - T t = value1; - value1 = value2; - value2 = t; -} -#define Q_DECLARE_SHARED(TYPE) \ -template <> inline bool qIsDetached(TYPE &t) { return t.isDetached(); } \ -template <> inline void qSwap_helper(TYPE &value1, TYPE &value2, TYPE*) \ -{ \ - const TYPE::DataPtr t = value1.data_ptr(); \ - value1.data_ptr() = value2.data_ptr(); \ - value2.data_ptr() = t; \ -} -#else -#define Q_DECLARE_SHARED(TYPE) \ -template <> inline bool qIsDetached(TYPE &t) { return t.isDetached(); } \ -template inline void qSwap(T &, T &); \ -template <> inline void qSwap(TYPE &value1, TYPE &value2) \ -{ \ - const TYPE::DataPtr t = value1.data_ptr(); \ - value1.data_ptr() = value2.data_ptr(); \ - value2.data_ptr() = t; \ -} -#endif -*/ \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d1/qt/QtdObject.d --- a/qt/d1/qt/QtdObject.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/** -* -* Copyright: Copyright QtD Team, 2008-2009 -* License: = connections.length) - connections.length = signalId + 1; - auto slot = connections[signalId].addSlot!(slotListId)(SlotType!(slotListId)(receiver, invoker, flags)); - - static if (slot.isDelegate) - { - if (!(flags & ConnectionFlags.NoObject)) - receivers.add(_d_toObject(receiver.context), &onReceiverDisposed); - } - - if (signalEvent && connections[signalId].slotCount == 1) - signalEvent(signalId, SignalEventId.firstSlotConnected); - - return slot; - } - - void onReceiverDisposed(Object receiver) - { - synchronized(this) - { - foreach(ref c; connections) - c.onReceiverDisposed(receiver); - receivers.removeAll(receiver); - } - } - - private void removeSlot(int slotListId)(int signalId, int slotId) - { - auto slot = connections[signalId].getSlotList!(slotListId).get(slotId); - static if (slot.isDelegate) - { - if (auto obj = slot.getObject) - receivers.remove(obj, &onReceiverDisposed); - } - - connections[signalId].removeSlot!(slotListId)(slotId); - - if (signalEvent && !connections[signalId].slotCount) - signalEvent(signalId, SignalEventId.lastSlotDisconnected); - } - - - size_t slotCount(int signalId) - { - synchronized(this) - { - auto con = getConnections(signalId); - if (con) - return con.slotCount; - return 0; - } - } - - void connect(Receiver)(int signalId, Receiver receiver, - Dg invoker, ConnectionFlags flags) - { - synchronized(this) - { - static if (is(typeof(receiver.context))) - { - Object obj; - if ((flags & ConnectionFlags.NoObject)) - { - // strong by default - if (flags & ConnectionFlags.Weak) - addSlot!(SlotListId.Weak)(signalId, receiver, invoker, flags); - else - addSlot!(SlotListId.Strong)(signalId, receiver, invoker, flags); - } - else - { - // weak by default - if (flags & ConnectionFlags.Strong) - addSlot!(SlotListId.Strong)(signalId, receiver, invoker, flags); - else - addSlot!(SlotListId.Weak)(signalId, receiver, invoker, flags); - } - } - else - { - flags |= ConnectionFlags.NoObject; - addSlot!(SlotListId.Func)(signalId, receiver, invoker, flags); - } - } - } - - void disconnect(Receiver)(int signalId, Receiver receiver) - { - synchronized(this) - { - auto cons = getConnections(signalId); - if (!cons) - return; - - // if called from a slot being executed by this signal, delay disconnection - // until all slots has been called. - if (cons.isInUse) - { - cons.addDelayedDisconnect(receiver); - return; - } - - TOP: - foreach (slotListId, e; cons.slotLists.tupleof) - { - /// COMPILER BUG: ReceiverType is evaluated to expression instead of type. - static if (is(typeof(cons.ReceiverType!(slotListId)) == Receiver)) - { - auto slotList = cons.getSlotList!(slotListId); - for (int slotId; slotId < slotList.length;) - { - auto slot = slotList.get(slotId); - static if (slot.isDelegate) - { - if (slot.isDisposed) - { - removeSlot!(slotListId)(signalId, slotId); - continue; - } - } - - if (slot.receiver == receiver) - { - removeSlot!(slotListId)(signalId, slotId); - break TOP; - } - - slotId++; - } - } - } - } - } - - void emit(A...)(size_t signalId, A args) - { - synchronized(this) - { - if (signalId >= connections.length || blocked) - return; - auto cons = &connections[signalId]; - - if (cons.hasSlots) - { - { - cons.isInUse = true; - signalSender_.val = owner; - scope(exit) - { - cons.isInUse = false; - signalSender_.val = null; - } - - // Store the lengths to avoid calling new slots - // connected in the slots being called. - // dmd bug: int[cons.slotListCount] fails - static const c = cons.slotListCount; - int[c] lengths = void; - cons.slotListLengths(lengths); - - foreach (slotListId, e; cons.slotLists.tupleof) - { - auto slotList = cons.getSlotList!(slotListId); - for (size_t slotId; slotId < lengths[slotListId];) - { - auto slot = slotList.get(slotId); - static if (slot.isDelegate) - { - if (slot.isDisposed) - { - removeSlot!(slotListId)(signalId, slotId); - lengths[slotListId]--; - continue; - } - } - - slot.invoker.call!(void)(slot.receiver, args); - ++slotId; - } - } - } - - - // process delayed disconnects if any - foreach(i, e; cons.delayedDisconnects.tupleof) - { - if (cons.delayedDisconnects.at!(i).length) - { - foreach (d; cons.delayedDisconnects.at!(i)) - disconnect(signalId, d); - cons.delayedDisconnects.at!(i).length = 0; - } - } - } - } - } - - // Adjusts signal arguments and calls the slot. S - slot signature, A - signal arguments - private void invokeSlot(S, Receiver, A...)(Receiver r, A args) - { - r.get!(S)()(args[0..ParameterTupleOf!(S).length]); - } - - void blockSignals() - { - synchronized(this) - blocked++; - } - - void unblockSignals() - { - synchronized(this) - { - if(!blocked) - throw new SignalException("Signals are not blocked"); - blocked--; - } - } - - ~this() - { - receivers.free(&onReceiverDisposed); - foreach(ref c; connections) - c.free; - } -} - -public template SignalHandlerOps() -{ - static assert (is(typeof(this.signalHandler)), - "SignalHandlerOps is already instantiated in " ~ typeof(this).stringof ~ " or one of its base classes"); - -protected: - SignalHandler signalHandler_; // manages signal-to-slot connections - - final SignalHandler signalHandler() - { - if (!signalHandler_) - { - signalHandler_ = new SignalHandler(this); - onSignalHandlerCreated(signalHandler_); - } - return signalHandler_; - } - - void onSignalHandlerCreated(ref SignalHandler sh) - { - } - -public: - final void blockSignals() - { - signalHandler.blockSignals(); - } - - final void unblockSignals() - { - signalHandler.unblockSignals(); - } - - template connect(string signalName, A...) - { - static void connect(T, Func)(T sender, Func func, ConnectionFlags flags = ConnectionFlags.None) - { - static if (isFnOrDg!(Func)) // D1 has no constraints - { - alias findSignal!(T, signalName, Func, A).result sig; - auto sh = sender.signalHandler(); - static if (isFn!(Func)) - alias Fn Callable; - else - alias Dg Callable; - auto invoker = Dg(&sh.invokeSlot!(typeof(func), Callable, sig[2..$])); - sh.connect(sig[1], Callable(func), invoker, flags); - } - else - { - static assert(false, "The slot must be a function or delegate type."); - } - } - } - - template disconnect(string signalName, A...) - { - static void connect(T, Func)(T sender, Func func, ConnectionFlags flags = ConnectionFlags.None) - { - static if (isFnOrDg!(Func)) // D1 has no constraints - { - alias findSignal!(T, signalName, Func, A).result sig; - auto sh = sender.signalHandler(); - static if (isFn!(Func)) - alias Fn Callable; - else - alias Dg Callable; - sh.disconnect(sig[1], Callable(func)); - } - else - { - static assert(false, "The slot must be a function or delegate type."); - } - } - } -/* - template slotCount(string signalName, A...) - { - debug static void slotCount(T)(T sender) - { - alias findSignal!(T, signalName, Func, A).result sig; - auto sh = sender.signalHandler(); - return sh.slotCount(sig[1]); - } - } - */ -} - -/** - New implementation. -*/ - -const string signalPrefix = "__signal"; - -template TupleWrapper(A...) { alias A at; } - -template isDg(Dg) -{ - enum { isDg = is(Dg == delegate) } -} - -template isFn(Fn) -{ - enum { isFn = is(typeof(*Fn.init) == function) } -} - -template isFnOrDg(Dg) -{ - enum { isFnOrDg = isFn!(Dg) || isDg!(Dg) } -} - -string joinArgs(A...)() -{ - string res = ""; - static if(A.length) - { - res = A[0].stringof; - foreach(k; A[1..$]) - res ~= "," ~ k.stringof; - } - return res; -} - -template SlotPred(T1, T2) -{ - enum { SlotPred = is(T1 : T2) } -} - -template CheckSlot(alias Needle, alias Source) -{ - static if(Needle.at.length <= Source.at.length) - enum { CheckSlot = CheckArgs!(Needle, Source, SlotPred, 0).value } - else - enum { CheckSlot = false } -} - -template SignalPred(T1, T2) -{ - enum { SignalPred = is(T1 == T2) } -} - -template CheckSignal(alias Needle, alias Source) -{ - static if(Needle.at.length == Source.at.length) - enum { CheckSignal = CheckArgs!(Needle, Source, SignalPred, 0).value } - else - enum { CheckSignal = false } -} - -template CheckArgs(alias Needle, alias Source, alias pred, int i) -{ - static if (i < Needle.at.length) - { - static if (pred!(Needle.at[i], Source.at[i])) - enum { value = CheckArgs!(Needle, Source, pred, i + 1).value } - else - enum { value = false } - } - else - { - enum { value = true } - } -} - -template SigByNamePred(string name, SlotArgs...) -{ - template SigByNamePred(source...) - { - static if (source[0] == name) // only instantiate CheckSlot if names match - enum { SigByNamePred = CheckSlot!(TupleWrapper!(SlotArgs), TupleWrapper!(source[2 .. $])) } - else - enum { SigByNamePred = false } - } -} - -template SigBySignPred(string name, SigArgs...) -{ - template SigBySignPred(source...) - { - static if (source[0] == name) // only instantiate CheckSignal if names match - enum { SigBySignPred = CheckSignal!(TupleWrapper!(SigArgs), TupleWrapper!(source[2 .. $])) } - else - enum { SigBySignPred = false } - } -} - -template staticSymbolName(string prefix, int id) -{ - const string staticSymbolName = prefix ~ ToString!(id); -} - -template signatureString(string name, A...) -{ - const string signatureString = name ~ "(" ~ joinArgs!(A) ~ ")"; -} - -template findSymbolImpl(string prefix, C, int id, alias pred) -{ - static if ( is(typeof(mixin("C." ~ staticSymbolName!(prefix, id)))) ) - { - mixin ("alias C." ~ staticSymbolName!(prefix, id) ~ " current;"); - static if (pred!(current)) - alias current result; - else - alias findSymbolImpl!(prefix, C, id + 1, pred).result result; - } - else - { - alias void result; - } -} - -template findSymbol(string prefix, C, alias pred) -{ - alias findSymbolImpl!(prefix, C, 0, pred).result findSymbol; -} - -template findSignal(C, string name, Receiver, SigArgs...) -{ - alias TupleWrapper!(ParameterTupleOf!(Receiver)) SlotArgsWr; - static if (SigArgs.length > 0) - { - alias findSymbol!(signalPrefix, C, SigBySignPred!(name, SigArgs)) result; - static if (is(result == void)) - static assert(0, "Signal " ~ name ~ "(" ~ joinArgs!(SigArgs)() ~ ") was not found."); - else - static if (!CheckSlot!(SlotArgsWr, TupleWrapper!(result[2 .. $]))) - static assert(0, "Signature of slot is incompatible with signal " ~ name ~ "."); - } - else - { - alias findSymbol!(signalPrefix, C, SigByNamePred!(name, SlotArgsWr.at)) result; - static if (is(result == void)) - static assert(0, "Signal " ~ name ~ " was not found."); - } -} - - -public string SignalEmitter(A...)(SignalType signalType, string name, int index) -{ - string fullArgs, args; - static if (A.length) - { - fullArgs = A[0].stringof ~ " a0"; - args = ", a0"; - foreach(i, _; A[1..$]) - { - fullArgs ~= ", " ~ A[i+1].stringof ~ " a" ~ __toString(i+1); - args ~= ", a" ~ __toString(i+1); - } - } - string attribute; - string sigName = name; - if (signalType == SignalType.BindQtSignal) - name ~= "_emit"; - else - attribute = "protected "; - string str = attribute ~ "void " ~ name ~ "(" ~ fullArgs ~ ")" ~ - "{ this.signalHandler.emit(" ~ __toString(index) ~ args ~ "); }"; - return str; -} - -/** - Examples: ----- -struct Args -{ - bool cancel; -} - -class C -{ - private int _x; - // reference parameters are not supported yet, - // so we pass arguments by pointer. - mixin Signal!("xChanging", int, Args*); - mixin Signal!("xChanged"); - - void x(int v) - { - if (v != _x) - { - Args args; - xChanging.emit(v, &args); - if (!args.cancel) - { - _x = v; - xChanged.emit; - } - } - } -} ----- -*/ - -enum SignalType -{ - BindQtSignal, - NewSignal -} - -template BindQtSignal(string name, A...) -{ - mixin SignalImpl!(0, name, SignalType.BindQtSignal, A); -} - -template Signal(string name, A...) -{ - mixin SignalImpl!(0, name, SignalType.NewSignal, A); -} - -template SignalImpl(int index, string name, SignalType signalType, A...) -{ - static if (is(typeof(mixin(typeof(this).stringof ~ ".__signal" ~ ToString!(index))))) - mixin SignalImpl!(index + 1, name, signalType, A); - else - { - // mixed-in once - static if (!is(typeof(this.signalHandler))) - mixin SignalHandlerOps; - - mixin (SignalEmitter!(A)(signalType, name, index)); - mixin("public alias Tuple!(\"" ~ name ~ "\", index, A) __signal" ~ ToString!(index) ~ ";"); - } -} - -extern(C) alias void function(void*) SlotConnector; - -debug (UnitTest) -{ - class A - { - mixin Signal!("scorched", int); - - int signalId1 = -1; - int signalId2 = -1; - - void onFirstConnect(int sId) - { - signalId1 = sId; - } - - void onLastDisconnect(int sId) - { - signalId2 = sId; - } - - this() - { - signalHandler.firstSlotConnected = &onFirstConnect; - signalHandler.lastSlotDisconnected = &onLastDisconnect; - } - } - - class B : A - { - mixin Signal!("booed", int); - - int bazSum; - void baz(int i) - { - bazSum += i; - } - } - - class C : A - { - mixin Signal!("cooked"); - } -} - -unittest -{ - static int fooSum; - static int barSum; - - static void foo(int i) - { - fooSum += i; - } - - void bar(long i) - { - barSum += i; - } - - auto a = new A; - auto b = new B; - auto c = new C; - assert(b.scorched.signalId == 0); - assert(b.booed.signalId == 1); - assert(c.cooked.signalId == 1); - - auto sh = b.signalHandler; - - b.scorched.connect(&foo); - assert(sh.connections.length == 1); - assert(b.signalId1 == 0); - auto scCons = &sh.connections[0]; - - assert(scCons.getSlotList!(SlotListId.Func).length == 1); - b.scorched.emit(1); - assert(fooSum == 1); - - b.scorched.connect(&bar, ConnectionFlags.NoObject); - assert(sh.connections.length == 1); - assert(scCons.getSlotList!(SlotListId.Strong).length == 1); - b.scorched.emit(1); - assert (fooSum == 2 && barSum == 1); - - b.scorched.connect(&b.baz); - assert(scCons.getSlotList!(SlotListId.Weak).length == 1); - b.scorched.emit(1); - assert (fooSum == 3 && barSum == 2 && b.bazSum == 1); - - b.scorched.disconnect(&bar); - assert(scCons.slotCount == 2); - b.scorched.disconnect(&b.baz); - assert(scCons.slotCount == 1); - b.scorched.disconnect(&foo); - assert(scCons.slotCount == 0); - assert(b.signalId2 == 0); - - fooSum = 0; - void connectFoo() - { - b.scorched.connect(&foo); - b.scorched.disconnect(&connectFoo); - } - - b.scorched.connect(&connectFoo, ConnectionFlags.NoObject); - b.scorched.emit(1); - assert(scCons.getSlotList!(SlotListId.Func).length == 1); - assert(scCons.getSlotList!(SlotListId.Strong).length == 0); - assert(!fooSum); - - auto r = new B(); - b.scorched.connect(&r.baz); - assert(scCons.getSlotList!(SlotListId.Weak).length == 1); - b.scorched.emit(1); - assert(r.bazSum == 1); - assert(fooSum == 1); - - delete(r); - assert(scCons.getSlotList!(SlotListId.Weak).length == 1); - b.scorched.emit(1); - assert(scCons.getSlotList!(SlotListId.Weak).length == 0); -} \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d1/qt/core/QLine.d --- a/qt/d1/qt/core/QLine.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,400 +0,0 @@ -module qt.core.QLine; - -public import qt.QGlobal; -public import qt.core.Qt; -public import qt.core.QPoint; -public import qt.core.QDataStream; - - -public struct QLine -{ - public static QLine opCall() { - QLine ln; - ln.pt1 = QPoint(); - ln.pt2 = QPoint(); - return ln; - } - - public static QLine opCall(in QPoint pt1_, in QPoint pt2_) { - QLine ln; - ln.pt1 = pt1_; - ln.pt2 = pt2_; - return ln; - } - - public static QLine opCall(int x1pos, int y1pos, int x2pos, int y2pos) { - QLine ln; - ln.pt1 = QPoint(x1pos, y1pos); - ln.pt2 = QPoint(x2pos, y2pos); - return ln; - } - - bool isNull() // const - { - return pt1 == pt2; - } - - int x1() // const - { - return pt1.x(); - } - - int y1() // const - { - return pt1.y(); - } - - int x2() // const - { - return pt2.x(); - } - - int y2() // const - { - return pt2.y(); - } - - QPoint p1() // const - { - return pt1; - } - - QPoint p2() // const - { - return pt2; - } - - int dx() // const - { - return pt2.x() - pt1.x(); - } - - int dy() // const - { - return pt2.y() - pt1.y(); - } - - void translate(in QPoint point) - { - pt1 += point; - pt2 += point; - } - - void translate(int adx, int ady) - { - translate(QPoint(adx, ady)); - } - - QLine translated(in QPoint p) // const - { - return QLine(pt1 + p, pt2 + p); - } - - QLine translated(int adx, int ady) // const - { - return translated(QPoint(adx, ady)); - } - - void p1(in QPoint aP1) - { - pt1 = aP1; - } - - void p2(in QPoint aP2) - { - pt2 = aP2; - } - - void setP1(in QPoint aP1) // for convenience - { - pt1 = aP1; - } - - void setP2(in QPoint aP2) // for convenience - { - pt2 = aP2; - } - - void setPoints(in QPoint aP1, in QPoint aP2) - { - pt1 = aP1; - pt2 = aP2; - } - - void setLine(int aX1, int aY1, int aX2, int aY2) - { - pt1 = QPoint(aX1, aY1); - pt2 = QPoint(aX2, aY2); - } - - bool opEquals(in QLine d) // const - { - return pt1 == d.pt1 && pt2 == d.pt2; - } - - public final void writeTo(QDataStream arg__1) { - qtd_QLine_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final void readFrom(QDataStream arg__1) { - qtd_QLine_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); - } - -private: - QPoint pt1, pt2; -} - - -public enum QLineF_IntersectType { - NoIntersection = 0, - BoundedIntersection = 1, - UnboundedIntersection = 2 -} - -public struct QLineF -{ - - alias QLineF_IntersectType IntersectType; - - alias QLineF_IntersectType.NoIntersection NoIntersection; - alias QLineF_IntersectType.BoundedIntersection BoundedIntersection; - alias QLineF_IntersectType.UnboundedIntersection UnboundedIntersection; - - public static QLineF opCall() { - QLineF ln; - ln.pt1 = QPointF(); - ln.pt2 = QPointF(); - return ln; - } - - public static QLineF opCall(in QPointF apt1, in QPointF apt2) { - QLineF ln; - ln.pt1 = apt1; - ln.pt2 = apt2; - return ln; - } - - public static QLineF opCall(qreal x1pos, qreal y1pos, qreal x2pos, qreal y2pos) { - QLineF ln; - ln.pt1 = QPointF(x1pos, y1pos); - ln.pt2 = QPointF(x2pos, y2pos); - return ln; - } - - public static QLineF opCall(in QLine line){ - QLineF ln; - ln.pt1 = QPointF(line.p1()); - ln.pt2 = QPointF(line.p2()); - return ln; - } - - public final bool isNull() // const - { - return qtd_QLineF_isNull(this); - } - - qreal x1() // const - { - return pt1.x(); - } - - qreal y1() // const - { - return pt1.y(); - } - - qreal x2() // const - { - return pt2.x(); - } - - qreal y2() // const - { - return pt2.y(); - } - - QPointF p1() // const - { - return pt1; - } - - QPointF p2() // const - { - return pt2; - } - - qreal dx() // const - { - return pt2.x() - pt1.x(); - } - - qreal dy() // const - { - return pt2.y() - pt1.y(); - } - - QLineF normalVector() // const - { - return QLineF(p1(), p1() + QPointF(dy(), -dx())); - } - - void translate(in QPointF point) - { - pt1 += point; - pt2 += point; - } - - void translate(qreal adx, qreal ady) - { - this.translate(QPointF(adx, ady)); - } - - QLineF translated(in QPointF p) // const - { - return QLineF(pt1 + p, pt2 + p); - } - - QLineF translated(qreal adx, qreal ady) // const - { - return translated(QPointF(adx, ady)); - } - - void setLength(qreal len) - { - if (isNull()) - return; - QLineF v = unitVector(); - pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len); - } - - void length(qreal len) - { - if (isNull()) - return; - QLineF v = unitVector(); - pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len); - } - - QPointF pointAt(qreal t) // const - { - qreal vx = pt2.x() - pt1.x(); - qreal vy = pt2.y() - pt1.y(); - return QPointF(pt1.x() + vx * t, pt1.y() + vy * t); - } - - QLine toLine() // const - { - return QLine(pt1.toPoint(), pt2.toPoint()); - } - - void setP1(in QPointF aP1) - { - pt1 = aP1; - } - - void setP2(in QPointF aP2) - { - pt2 = aP2; - } - - void p1(in QPointF aP1) - { - pt1 = aP1; - } - - void p2(in QPointF aP2) - { - pt2 = aP2; - } - - void setPoints(in QPointF aP1, in QPointF aP2) - { - pt1 = aP1; - pt2 = aP2; - } - - void setLine(qreal aX1, qreal aY1, qreal aX2, qreal aY2) - { - pt1 = QPointF(aX1, aY1); - pt2 = QPointF(aX2, aY2); - } - - bool opEquals(in QLineF d) // const - { - return pt1 == d.pt1 && pt2 == d.pt2; - } - - public final double angle() { - return qtd_QLineF_angle(this); - } - - public final double angle(in QLineF l) { - return qtd_QLineF_angle_QLineF(this, &l); - } - - public final double angleTo(in QLineF l) { - return qtd_QLineF_angleTo_QLineF(this, &l); - } - - // ### Qt 5: rename intersects() or intersection() and rename IntersectType IntersectionType - private final QLineF_IntersectType intersect(in QLineF l, QPointF* intersectionPoint) { - return cast(QLineF_IntersectType) qtd_QLineF_intersect_QLineF_nativepointerQPointF(this, &l, intersectionPoint); - } - - public final double length() { - return qtd_QLineF_length(this); - } - - public final void writeTo(QDataStream arg__1) { - qtd_QLineF_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final void readFrom(QDataStream arg__1) { - qtd_QLineF_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final void setAngle(double angle) { - qtd_QLineF_setAngle_double(this, angle); - } - - public final QLineF unitVector() { - return qtd_QLineF_unitVector(this); - } - - public static QLineF fromPolar(double length, double angle) { - return qtd_QLineF_fromPolar_double_double(length, angle); - } - - private: - QPointF pt1, pt2; -} - - -// C wrappers -// QLine -private extern(C) void qtd_QLine_writeTo_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void qtd_QLine_readFrom_QDataStream(void* __this_nativeId, - void* arg__1); - -// QLineF -private extern(C) bool qtd_QLineF_isNull(void* __this_nativeId); -private extern(C) double qtd_QLineF_angle(void* __this_nativeId); -private extern(C) double qtd_QLineF_angle_QLineF(void* __this_nativeId, - void* l0); -private extern(C) double qtd_QLineF_angleTo_QLineF(void* __this_nativeId, - void* l0); -private extern(C) int qtd_QLineF_intersect_QLineF_nativepointerQPointF(void* __this_nativeId, - void* l0, - void* intersectionPoint1); -private extern(C) double qtd_QLineF_length(void* __this_nativeId); -private extern(C) void qtd_QLineF_writeTo_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void qtd_QLineF_readFrom_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void qtd_QLineF_setAngle_double(void* __this_nativeId, - double angle0); - -private extern(C) QLineF qtd_QLineF_unitVector(void* __this_nativeId); -private extern(C) QLineF qtd_QLineF_fromPolar_double_double(double length0, - double angle1); diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d1/qt/core/QLineF.d --- a/qt/d1/qt/core/QLineF.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -module qt.core.QLineF; -/* dummy */ - -public import qt.core.QLine; \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d1/qt/core/QModelIndex.d --- a/qt/d1/qt/core/QModelIndex.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,127 +0,0 @@ -module qt.core.QModelIndex; - -public import qt.QGlobal; -private import qt.QtdObject; - -// automatic imports------------- -private import qt.core.QVariant; -private import qt.core.QAbstractItemModel; -public import qt.core.Qt; - -version (Tango) -{ - import tango.core.Array; - import tango.stdc.stringz; - import tango.text.convert.Utf; -} - - -public struct QModelIndex -{ - - public static QModelIndex opCall() { - QModelIndex mi; - mi.r = mi.c = -1; - mi.p = mi.m = null; - return mi; - } - public final QModelIndex child(int row, int column) { - return __qtd_QModelIndex_child_int_int(this, row, column); - } - - public final int column() { - return __qtd_QModelIndex_column(this); - } - - public final QVariant data(int role = 0) { - void* __qt_return_value = __qtd_QModelIndex_data_int(this, role); - return new QVariant(__qt_return_value); - } - - public final int flags() { - return __qtd_QModelIndex_flags(this); - } - - public final long internalId() { - return __qtd_QModelIndex_internalId(this); - } - - public final void* internalPointer() { - //return __qtd_QModelIndex_internalPointer(this); - return p; - } - - public final Object object() { - return cast(Object) p; - } - - public final bool isValid() { - return __qtd_QModelIndex_isValid(this); - } - - public final QAbstractItemModel model() { -// void* __qt_return_value = __qtd_QModelIndex_model(this); - void* __qt_return_value = m; - if (__qt_return_value is null) - return null; - void* d_obj = qtd_get_d_qobject(__qt_return_value); - return cast(QAbstractItemModel) d_obj; - } - - private final bool operator_less(QModelIndex other) { - return __qtd_QModelIndex_operator_less_QModelIndex(this, other); - } - - private final bool operator_equal(QModelIndex other) { - return __qtd_QModelIndex_operator_equal_QModelIndex(this, other); - } - - public final QModelIndex parent() { - return __qtd_QModelIndex_parent(this); - } - - public final int row() { - return __qtd_QModelIndex_row(this); - } - - public final QModelIndex sibling(int row, int column) { - return __qtd_QModelIndex_sibling_int_int(this, row, column); - } - -private: - int r; - int c; - void *p; - void *m; -} - -alias QModelIndex QModelIndexAccessor; - - -// C wrappers -private extern(C) void* __qtd_QModelIndex_QModelIndex_QModelIndex(QModelIndex other0); -private extern(C) QModelIndex __qtd_QModelIndex_child_int_int(void* __this_nativeId, - int row0, - int column1); -private extern(C) int __qtd_QModelIndex_column(void* __this_nativeId); -private extern(C) void* __qtd_QModelIndex_data_int(void* __this_nativeId, - int role0); -private extern(C) int __qtd_QModelIndex_flags(void* __this_nativeId); -private extern(C) long __qtd_QModelIndex_internalId(void* __this_nativeId); -private extern(C) void* __qtd_QModelIndex_internalPointer(void* __this_nativeId); -private extern(C) bool __qtd_QModelIndex_isValid(void* __this_nativeId); -private extern(C) void* __qtd_QModelIndex_model(void* __this_nativeId); -private extern(C) bool __qtd_QModelIndex_operator_less_QModelIndex(void* __this_nativeId, - QModelIndex other0); -private extern(C) bool __qtd_QModelIndex_operator_equal_QModelIndex(void* __this_nativeId, - QModelIndex other0); -private extern(C) QModelIndex __qtd_QModelIndex_parent(void* __this_nativeId); -private extern(C) int __qtd_QModelIndex_row(void* __this_nativeId); -private extern(C) QModelIndex __qtd_QModelIndex_sibling_int_int(void* __this_nativeId, - int row0, - int column1); -// Just the private functions for abstract functions implemeneted in superclasses - - - -// Virtual Dispatch functions diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d1/qt/core/QPoint.d --- a/qt/d1/qt/core/QPoint.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,234 +0,0 @@ -module qt.core.QPoint; - -public import qt.QGlobal; -public import qt.core.Qt; -public import qt.core.QDataStream; - -public struct QPoint -{ - -// Functions - public static QPoint opCall() { - QPoint pt; - pt.xp = pt.yp = 0; - return pt; - } - - public static QPoint opCall(int xpos, int ypos) { - QPoint pt; - pt.xp = xpos; - pt.yp = ypos; - return pt; - } - - bool isNull() // const - { return xp == 0 && yp == 0; } - - int x() // const - { return xp; } - - int y() // const - { return yp; } - - void x(int xpos) - { xp = xpos; } - - void y(int ypos) - { yp = ypos; } - - void setX(int xpos) // for convenience - { xp = xpos; } - - void setY(int ypos) // for convenience - { yp = ypos; } - - public final int manhattanLength() { - return qtd_QPoint_manhattanLength(this); - } -/* -inline int &rx() -{ return xp; } - -inline int &ry() -{ return yp; } -*/ - - QPoint opAddAssign(in QPoint p) - { xp+=p.xp; yp+=p.yp; return *this; } - - QPoint opSubAssign(in QPoint p) - { xp-=p.xp; yp-=p.yp; return *this; } - - QPoint opMulAssign(qreal c) - { xp = qRound(xp*c); yp = qRound(yp*c); return *this; } - - bool opEquals(in QPoint p) - { return xp == p.xp && yp == p.yp; } - - QPoint opAdd(in QPoint p) - { return QPoint(this.xp+p.xp, this.yp+p.yp); } - - QPoint opSub(in QPoint p) - { return QPoint(this.xp-p.xp, this.yp-p.yp); } - - QPoint opMul(qreal c) - { return QPoint(qRound(this.xp*c), qRound(this.yp*c)); } - - QPoint opDivAssign(qreal c) - { - xp = qRound(xp/c); - yp = qRound(yp/c); - return *this; - } - - QPoint opDiv(qreal c) - { - return QPoint(qRound(this.xp/c), qRound(this.yp/c)); - } - - public final void writeTo(QDataStream arg__1) { - qtd_QPoint_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final void readFrom(QDataStream arg__1) { - qtd_QPoint_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); - } - -private: - // ### Qt 5; remove the ifdef and just have the same order on all platforms. - version(OSX) - { - int yp; - int xp; - } - else - { - int xp; - int yp; - } -} - - -public struct QPointF -{ - public static QPointF opCall() { - QPointF pt; - pt.xp = pt.yp = 0; - return pt; - } - - public static QPointF opCall(qreal xpos, qreal ypos) { - QPointF pt; - pt.xp = xpos; - pt.yp = ypos; - return pt; - } - - public static QPointF opCall(in QPoint p) { - QPointF pt; - pt.xp = p.x(); - pt.yp = p.y(); - return pt; - } - - bool isNull() //const - { - return qIsNull(xp) && qIsNull(yp); - } - - qreal x() //const - { - return xp; - } - - qreal y() //const - { - return yp; - } - - void x(qreal xpos) - { - xp = xpos; - } - - void y(qreal ypos) - { - yp = ypos; - } -/* -inline qreal &QPointF::rx() -{ - return xp; -} - -inline qreal &QPointF::ry() -{ - return yp; -} -*/ - - QPointF opAddAssign(in QPointF p) - { xp+=p.xp; yp+=p.yp; return *this; } - - QPointF opSubAssign(in QPointF p) - { xp-=p.xp; yp-=p.yp; return *this; } - - QPointF opMulAssign(qreal c) - { xp*=c; yp*=c; return *this; } - - bool opEquals(in QPointF p) - { return qFuzzyCompare(xp, p.xp) && qFuzzyCompare(yp, p.yp); } - - QPointF opAdd(in QPointF p) - { return QPointF(this.xp+p.xp, this.yp+p.yp); } - - QPointF opSub(in QPointF p) - { return QPointF(this.xp-p.xp, this.yp-p.yp); } - - QPointF opMul(qreal c) - { return QPointF(this.xp*c, this.yp*c); } - - QPointF opDivAssign(qreal c) - { - xp/=c; - yp/=c; - return *this; - } - - QPointF opDiv(qreal c) - { - return QPointF(xp/c, yp/c); - } - - QPoint toPoint() //const - { - return QPoint(qRound(xp), qRound(yp)); - } - - public final void writeTo(QDataStream arg__1) { - qtd_QPointF_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final void readFrom(QDataStream arg__1) { - qtd_QPointF_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); - } - -private: - qreal xp; - qreal yp; -} - - -// C wrappers -// QPoint -private extern(C) int qtd_QPoint_manhattanLength(void* __this_nativeId); -private extern(C) void qtd_QPoint_writeTo_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void qtd_QPoint_readFrom_QDataStream(void* __this_nativeId, - void* arg__1); - -// QPointF -private extern(C) void qtd_QPointF_writeTo_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void qtd_QPointF_readFrom_QDataStream(void* __this_nativeId, - void* arg__1); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d1/qt/core/QPointF.d --- a/qt/d1/qt/core/QPointF.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -module qt.core.QPointF; -/* dummy */ - -public import qt.core.QPoint; diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d1/qt/core/QRect.d --- a/qt/d1/qt/core/QRect.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,382 +0,0 @@ -module qt.core.QRect; - -public import qt.QGlobal; -public import qt.core.Qt; - -public import qt.core.QDataStream; -public import qt.core.QSize; -public import qt.core.QPoint; - - -public struct QRect -{ - public static QRect opCall() { - QRect rt; - rt.x1 = rt.y1 = 0; - rt.x2 = rt.y2 = -1; - return rt; - } - - public static QRect opCall(int aleft, int atop, int awidth, int aheight) - { - QRect rt; - rt.x1 = aleft; - rt.y1 = atop; - rt.x2 = (aleft + awidth - 1); - rt.y2 = (atop + aheight - 1); - return rt; - } - - public static QRect opCall(in QPoint atopLeft, in QPoint abottomRight) - { - QRect rt; - rt.x1 = atopLeft.x(); - rt.y1 = atopLeft.y(); - rt.x2 = abottomRight.x(); - rt.y2 = abottomRight.y(); - return rt; - } - - public static QRect opCall(in QPoint atopLeft, in QSize asize) - { - QRect rt; - rt.x1 = atopLeft.x(); - rt.y1 = atopLeft.y(); - rt.x2 = (rt.x1+asize.width() - 1); - rt.y2 = (rt.y1+asize.height() - 1); - return rt; - } - - bool isNull() // const - { return x2 == x1 - 1 && y2 == y1 - 1; } - - bool isEmpty() // const - { return x1 > x2 || y1 > y2; } - - bool isValid() // const - { return x1 <= x2 && y1 <= y2; } - - int left() // const - { return x1; } - - int top() // const - { return y1; } - - int right() // const - { return x2; } - - int bottom() // const - { return y2; } - - int x() // const - { return x1; } - - int y() // const - { return y1; } - - void left(int pos) - { x1 = pos; } - - void top(int pos) - { y1 = pos; } - - void right(int pos) - { x2 = pos; } - - void bottom(int pos) - { y2 = pos; } - - void setLeft(int pos) - { x1 = pos; } - - void setTop(int pos) - { y1 = pos; } - - void setRight(int pos) - { x2 = pos; } - - void setBottom(int pos) - { y2 = pos; } - - void setTopLeft(in QPoint p) - { x1 = p.x(); y1 = p.y(); } - - void setBottomRight(in QPoint p) - { x2 = p.x(); y2 = p.y(); } - - void setTopRight(in QPoint p) - { x2 = p.x(); y1 = p.y(); } - - void setBottomLeft(in QPoint p) - { x1 = p.x(); y2 = p.y(); } - - void setX(int ax) - { x1 = ax; } - - void setY(int ay) - { y1 = ay; } - - QPoint topLeft() // const - { return QPoint(x1, y1); } - - QPoint bottomRight() // const - { return QPoint(x2, y2); } - - QPoint topRight() // const - { return QPoint(x2, y1); } - - QPoint bottomLeft() // const - { return QPoint(x1, y2); } - - QPoint center() // const - { return QPoint((x1+x2)/2, (y1+y2)/2); } - - int width() // const - { return x2 - x1 + 1; } - - int height() // const - { return y2 - y1 + 1; } - - QSize size() // const - { return QSize(width(), height()); } - - void translate(int dx, int dy) - { - x1 += dx; - y1 += dy; - x2 += dx; - y2 += dy; - } - - void translate(in QPoint p) - { - x1 += p.x(); - y1 += p.y(); - x2 += p.x(); - y2 += p.y(); - } - - QRect translated(int dx, int dy) // const - { return QRect(QPoint(x1 + dx, y1 + dy), QPoint(x2 + dx, y2 + dy)); } - - QRect translated(in QPoint p) // const - { return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); } - - void moveTo(int ax, int ay) - { - x2 += ax - x1; - y2 += ay - y1; - x1 = ax; - y1 = ay; - } - - void moveTo(in QPoint p) - { - x2 += p.x() - x1; - y2 += p.y() - y1; - x1 = p.x(); - y1 = p.y(); - } - - void moveLeft(int pos) - { x2 += (pos - x1); x1 = pos; } - - void moveTop(int pos) - { y2 += (pos - y1); y1 = pos; } - - void moveRight(int pos) - { - x1 += (pos - x2); - x2 = pos; - } - - void moveBottom(int pos) - { - y1 += (pos - y2); - y2 = pos; - } - - void moveTopLeft(in QPoint p) - { - moveLeft(p.x()); - moveTop(p.y()); - } - - void moveBottomRight(in QPoint p) - { - moveRight(p.x()); - moveBottom(p.y()); - } - - void moveTopRight(in QPoint p) - { - moveRight(p.x()); - moveTop(p.y()); - } - - void moveBottomLeft(in QPoint p) - { - moveLeft(p.x()); - moveBottom(p.y()); - } - - void getRect(int *ax, int *ay, int *aw, int *ah) // const - { - *ax = x1; - *ay = y1; - *aw = x2 - x1 + 1; - *ah = y2 - y1 + 1; - } - - void setRect(int ax, int ay, int aw, int ah) - { - x1 = ax; - y1 = ay; - x2 = (ax + aw - 1); - y2 = (ay + ah - 1); - } - - void getCoords(int *xp1, int *yp1, int *xp2, int *yp2) // const - { - *xp1 = x1; - *yp1 = y1; - *xp2 = x2; - *yp2 = y2; - } - - void setCoords(int xp1, int yp1, int xp2, int yp2) - { - x1 = xp1; - y1 = yp1; - x2 = xp2; - y2 = yp2; - } - - QRect adjusted(int xp1, int yp1, int xp2, int yp2) // const - { return QRect(QPoint(x1 + xp1, y1 + yp1), QPoint(x2 + xp2, y2 + yp2)); } - - void adjust(int dx1, int dy1, int dx2, int dy2) - { - x1 += dx1; - y1 += dy1; - x2 += dx2; - y2 += dy2; - } - - void setWidth(int w) - { x2 = (x1 + w - 1); } - - void setHeight(int h) - { y2 = (y1 + h - 1); } - - void setSize(in QSize s) - { - x2 = (s.width() + x1 - 1); - y2 = (s.height() + y1 - 1); - } - - bool contains(int ax, int ay, bool aproper) // const - { - return contains(QPoint(ax, ay), aproper); - } - - bool contains(int ax, int ay) // const - { - return contains(QPoint(ax, ay), false); - } - - QRect opOrAssign(in QRect r) - { - *this = *this | r; - return *this; - } - - QRect opAndAssign(in QRect r) - { - *this = *this & r; - return *this; - } - - QRect intersected(in QRect other) // const - { - return *this & other; - } - - QRect united(in QRect r) // const - { - return *this | r; - } - - bool opEquals(in QRect r) - { - return x1==r.x1 && x2==r.x2 && y1==r.y1 && y2==r.y2; - } - - public final void writeTo(QDataStream arg__1) { - qtd_QRect_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final void readFrom(QDataStream arg__1) { - qtd_QRect_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final QRect opAnd(in QRect r) { - return qtd_QRect_operator_and_QRect(this, &r); - } - - public final QRect opOr(in QRect r) { - return qtd_QRect_operator_or_QRect(this, &r); - } - - public final bool contains(QPoint p, bool proper = false) { - return qtd_QRect_contains_QPoint_bool(this, &p, proper); - } - - public final bool contains(QRect r, bool proper = false) { - return qtd_QRect_contains_QRect_bool(this, &r, proper); - } - - public final bool intersects(QRect r) { - return qtd_QRect_intersects_QRect(this, &r); - } - - public final QRect normalized() { - return qtd_QRect_normalized(this); - } - -private: - version(OSX) - { - int y1; - int x1; - int y2; - int x2; - } - else - { - int x1; - int y1; - int x2; - int y2; - } -} - - -// C wrappers -private extern(C) bool qtd_QRect_contains_QPoint_bool(void* __this_nativeId, - void* p0, - bool proper1); -private extern(C) bool qtd_QRect_contains_QRect_bool(void* __this_nativeId, - void* r0, - bool proper1); -private extern(C) bool qtd_QRect_intersects_QRect(void* __this_nativeId, - void* r0); -private extern(C) QRect qtd_QRect_normalized(void* __this_nativeId); -private extern(C) void qtd_QRect_writeTo_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void qtd_QRect_readFrom_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) QRect qtd_QRect_operator_and_QRect(void* __this_nativeId, - void* r0); -private extern(C) QRect qtd_QRect_operator_or_QRect(void* __this_nativeId, - void* r0); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d1/qt/core/QRectF.d --- a/qt/d1/qt/core/QRectF.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,338 +0,0 @@ -module qt.core.QRectF; - -public import qt.QGlobal; -public import qt.core.Qt; -public import qt.core.QPointF; -public import qt.core.QRect; -public import qt.core.QSizeF; -public import qt.core.QDataStream; - - -public struct QRectF -{ - - public static QRectF opCall() - { - QRectF rt; - rt.xp = rt.yp = 0.; - rt.w = rt.h = 0.; - return rt; - } - - public static QRectF opCall(qreal aleft, qreal atop, qreal awidth, qreal aheight) - { - QRectF rt; - rt.xp = aleft; - rt.yp = atop; - rt.w = awidth; - rt.h = aheight; - return rt; - } - - public static QRectF opCall(in QPointF atopLeft, in QSizeF asize) - { - QRectF rt; - rt.xp = atopLeft.x(); - rt.yp = atopLeft.y(); - rt.w = asize.width(); - rt.h = asize.height(); - return rt; - } - - public static QRectF opCall(in QPointF atopLeft, in QPointF abottomRight) - { - QRectF rt; - rt.xp = atopLeft.x(); - rt.yp = atopLeft.y(); - rt.w = abottomRight.x() - rt.xp; - rt.h = abottomRight.y() - rt.yp; - return rt; - } - - public static QRectF opCall(in QRect r) - { - QRectF rt; - rt.xp = r.x(); - rt.yp = r.y(); - rt.w = r.width(); - rt.h = r.height(); - return rt; - } - - bool isNull() // conts - { return qIsNull(w) && qIsNull(h); } - - bool isEmpty() // conts - { return w <= 0. || h <= 0.; } - - bool isValid() // conts - { return w > 0. && h > 0.; } - - qreal x() // conts - { return xp; } - - qreal y() // conts - { return yp; } - - qreal left() // const - { return xp; } - - qreal top() // const - { return yp; } - - qreal right() // const - { return xp + w; } - - qreal bottom() // const - { return yp + h; } - - QPointF topLeft() // const - { return QPointF(xp, yp); } - - QPointF bottomRight() // const - { return QPointF(xp+w, yp+h); } - - QPointF topRight() // const - { return QPointF(xp+w, yp); } - - QPointF bottomLeft() // const - { return QPointF(xp, yp+h); } - - void setLeft(qreal pos) { qreal diff = pos - xp; xp += diff; w -= diff; } - - void setRight(qreal pos) { w = pos - xp; } - - void setTop(qreal pos) { qreal diff = pos - yp; yp += diff; h -= diff; } - - void setBottom(qreal pos) { h = pos - yp; } - - void setTopLeft(in QPointF p) { setLeft(p.x()); setTop(p.y()); } - - void setTopRight(in QPointF p) { setRight(p.x()); setTop(p.y()); } - - void setBottomLeft(in QPointF p) { setLeft(p.x()); setBottom(p.y()); } - - void setBottomRight(in QPointF p) { setRight(p.x()); setBottom(p.y()); } - - QPointF center() // conts - { return QPointF(xp + w/2, yp + h/2); } - - void moveLeft(qreal pos) { xp = pos; } - - void moveTop(qreal pos) { yp = pos; } - - void moveRight(qreal pos) { xp = pos - w; } - - void moveBottom(qreal pos) { yp = pos - h; } - - void moveTopLeft(in QPointF p) { moveLeft(p.x()); moveTop(p.y()); } - - void moveTopRight(in QPointF p) { moveRight(p.x()); moveTop(p.y()); } - - void moveBottomLeft(in QPointF p) { moveLeft(p.x()); moveBottom(p.y()); } - - void moveBottomRight(in QPointF p) { moveRight(p.x()); moveBottom(p.y()); } - - void moveCenter(in QPointF p) { xp = p.x() - w/2; yp = p.y() - h/2; } - - qreal width() // conts - { return w; } - - qreal height() // conts - { return h; } - - QSizeF size() // conts - { return QSizeF(w, h); } - - void translate(qreal dx, qreal dy) - { - xp += dx; - yp += dy; - } - - void translate(in QPointF p) - { - xp += p.x(); - yp += p.y(); - } - - void moveTo(qreal ax, qreal ay) - { - xp = ax; - yp = ay; - } - - void moveTo(in QPointF p) - { - xp = p.x(); - yp = p.y(); - } - - QRectF translated(qreal dx, qreal dy) // conts - { return QRectF(xp + dx, yp + dy, w, h); } - - QRectF translated(in QPointF p) // conts - { return QRectF(xp + p.x(), yp + p.y(), w, h); } - - void getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) // conts - { - *ax = this.xp; - *ay = this.yp; - *aaw = this.w; - *aah = this.h; - } - - void setRect(qreal ax, qreal ay, qreal aaw, qreal aah) - { - this.xp = ax; - this.yp = ay; - this.w = aaw; - this.h = aah; - } - - void getCoords(qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2) // conts - { - *xp1 = xp; - *yp1 = yp; - *xp2 = xp + w; - *yp2 = yp + h; - } - - void setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2) - { - xp = xp1; - yp = yp1; - w = xp2 - xp1; - h = yp2 - yp1; - } - - void adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2) - { xp += xp1; yp += yp1; w += xp2 - xp1; h += yp2 - yp1; } - - QRectF adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) // conts - { return QRectF(xp + xp1, yp + yp1, w + xp2 - xp1, h + yp2 - yp1); } - - void setWidth(qreal aw) // for convenience - { this.w = aw; } - - void setHeight(qreal ah) // for convenience - { this.h = ah; } - - void setSize(in QSizeF s) // for convenience - { - w = s.width(); - h = s.height(); - } - - void width(qreal aw) - { this.w = aw; } - - void height(qreal ah) - { this.h = ah; } - - void size(in QSizeF s) - { - w = s.width(); - h = s.height(); - } - - bool contains(qreal ax, qreal ay) // conts - { - return contains(QPointF(ax, ay)); - } - - QRectF opOrAssign(in QRectF r) - { - *this = *this | r; - return *this; - } - - QRectF opAndAssign(in QRectF r) - { - *this = *this & r; - return *this; - } - - QRectF intersected(in QRectF r) // conts - { - return *this & r; - } - - QRectF united(in QRectF r) // conts - { - return *this | r; - } - - bool opEquals(in QRectF r) - { - return qFuzzyCompare(xp, r.xp) && qFuzzyCompare(yp, r.yp) - && qFuzzyCompare(w, r.w) && qFuzzyCompare(h, r.h); - } - - QRect toRect() // conts - { - return QRect(qRound(xp), qRound(yp), qRound(w), qRound(h)); - } - - public final bool contains(QPointF p) { - return qtd_QRectF_contains_QPointF(this, &p); - } - - public final bool contains(QRectF r) { - return qtd_QRectF_contains_QRectF(this, &r); - } - - public final bool intersects(QRectF r) { - return qtd_QRectF_intersects_QRectF(this, &r); - } - - public final QRectF normalized() { - return qtd_QRectF_normalized(this); - } - - public final QRectF opAnd(in QRectF r) { - return qtd_QRectF_operator_and_QRectF(this, &r); - } - - public final void writeTo(QDataStream arg__1) { - qtd_QRectF_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final void readFrom(QDataStream arg__1) { - qtd_QRectF_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final QRectF opOr(in QRectF r) { - return qtd_QRectF_operator_or_QRectF(this, &r); - } - - public final QRect toAlignedRect() // const - { - return qtd_QRectF_toAlignedRect(this); - } - -private: - qreal xp; - qreal yp; - qreal w; - qreal h; -} - - -// C wrappers -private extern(C) bool qtd_QRectF_contains_QPointF(void* __this_nativeId, - void* p0); -private extern(C) bool qtd_QRectF_contains_QRectF(void* __this_nativeId, - void* r0); -private extern(C) bool qtd_QRectF_intersects_QRectF(void* __this_nativeId, - void* r0); -private extern(C) QRectF qtd_QRectF_normalized(void* __this_nativeId); -private extern(C) QRectF qtd_QRectF_operator_and_QRectF(void* __this_nativeId, - void* r0); -private extern(C) void qtd_QRectF_writeTo_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void qtd_QRectF_readFrom_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) QRectF qtd_QRectF_operator_or_QRectF(void* __this_nativeId, - void* r0); -private extern(C) QRect qtd_QRectF_toAlignedRect(void* __this_nativeId); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d1/qt/core/QSize.d --- a/qt/d1/qt/core/QSize.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,276 +0,0 @@ -module qt.core.QSize; - -public import qt.QGlobal; -public import qt.core.Qt; - - -public struct QSize -{ -/* ctors, reserved for D2 - public this() - { wd = ht = -1; } - - public this(int w, int h) - { wd = w; ht = h; } -*/ - - public static QSize opCall() { - QSize sz; - sz.wd = sz.ht = -1; - return sz; - } - - public static QSize opCall(int w, int h) { - QSize sz; - sz.wd = w; - sz.ht = h; - return sz; - } - - final bool isNull() - { return wd==0 && ht==0; } - - final bool isEmpty() - { return wd<1 || ht<1; } - - final bool isValid() - { return wd>=0 && ht>=0; } - - final int width() - { return wd; } - - final int height() - { return ht; } - - final void width(int w) - { wd = w; } - - final void height(int h) - { ht = h; } - - final void setWidth(int w) // for convenience - { wd = w; } - - final void setHeight(int h) // for convenience - { ht = h; } - - void transpose() { - int tmp = wd; - wd = ht; - ht = tmp; - } - - void scale(int w, int h, Qt.AspectRatioMode mode) { - scale(QSize(w, h), mode); - } - - void scale(in QSize s, Qt.AspectRatioMode mode) { - __qtd_QSize_scale_QSize_AspectRatioMode(this, &s, mode); - } - - QSize expandedTo(in QSize otherSize) { - return QSize(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht)); - } - - QSize boundedTo(in QSize otherSize) { - return QSize(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht)); - } -/* - public final void writeTo(QDataStream arg__1) { - __qtd_QSize_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.nativeId); - } - - public final void readFrom(QDataStream arg__1) { - __qtd_QSize_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.nativeId); - } -*/ - QSize opAddAssign(in QSize s) - { wd+=s.wd; ht+=s.ht; return *this; } - - QSize opSubAssign(in QSize s) - { wd-=s.wd; ht-=s.ht; return *this; } - - QSize opMulAssign(qreal c) - { wd = qRound(wd*c); ht = qRound(ht*c); return *this; } - - bool opEquals(in QSize s) - { return wd == s.wd && ht == s.ht; } - - QSize opAdd(in QSize s) - { return QSize(this.wd+s.wd, this.ht+s.ht); } - - QSize opSub(in QSize s) - { return QSize(this.wd-s.wd, this.ht-s.ht); } - - QSize opMul(qreal c) - { return QSize(qRound(this.wd*c), qRound(this.ht*c)); } - - QSize opDivAssign(qreal c) { - assert(!qFuzzyCompare(c + 1, 1.)); - wd = qRound(wd/c); ht = qRound(ht/c); - return *this; - } - - QSize opDiv(qreal c) { - assert(!qFuzzyCompare(c + 1, 1.)); - return QSize(qRound(this.wd/c), qRound(this.ht/c)); - } - -private: - int wd; - int ht; -} - - -public struct QSizeF -{ -/* ctors, reserved for D2 - this() - { wd = ht = -1.; } - - this(ref QSize sz) - { wd = sz.width(); ht = sz.height(); } - - this(qreal w, qreal h) - { wd = w; ht = h; } -*/ - public static QSizeF opCall() { - QSizeF sz; - sz.wd = sz.ht = -1.; - return sz; - } - - public static QSizeF opCall(in QSizeF s) { - QSizeF sz; - sz.wd = s.width(); sz.ht = s.height(); - return sz; - } - - public static QSizeF opCall(qreal w, qreal h) { - QSizeF sz; - sz.wd = w; sz.ht = h; - return sz; - } - - bool isNull() - { return qIsNull(wd) && qIsNull(ht); } - - bool isEmpty() - { return wd <= 0. || ht <= 0.; } - - bool isValid() - { return wd >= 0. && ht >= 0.; } - - qreal width() - { return wd; } - - qreal height() - { return ht; } - - void width(qreal w) - { wd = w; } - - void height(qreal h) - { ht = h; } - - void setWidth(qreal w) - { wd = w; } - - void setHeight(qreal h) - { ht = h; } - - void scale(qreal w, qreal h, Qt.AspectRatioMode mode) - { scale(QSizeF(w, h), mode); } - - public final void scale(QSizeF s, Qt.AspectRatioMode mode) - { __qtd_QSizeF_scale_QSizeF_AspectRatioMode(this, &s, mode); } - - void transpose() { - qreal tmp = wd; - wd = ht; - ht = tmp; - } - - QSizeF expandedTo(in QSizeF otherSize) - { return QSizeF(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht)); } - - QSizeF boundedTo(in QSizeF otherSize) - { return QSizeF(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht)); } - - QSize toSize() - { return QSize(qRound(wd), qRound(ht)); } -/* - public final void writeTo(QDataStream arg__1) { - __qtd_QSizeF_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.nativeId); - } - - public final void readFrom(QDataStream arg__1) { - __qtd_QSizeF_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.nativeId); -*/ - QSizeF opAddAssign(in QSizeF s) - { wd += s.wd; ht += s.ht; return *this; } - - QSizeF opSubAssign(in QSizeF s) - { wd -= s.wd; ht -= s.ht; return *this; } - - QSizeF opMulAssign(qreal c) - { wd *= c; ht *= c; return *this; } - - bool opEquals(in QSizeF s) - { return qFuzzyCompare(wd, s.wd) && qFuzzyCompare(ht, s.ht); } - - QSizeF opAdd(in QSizeF s) - { return QSizeF(this.wd+s.wd, this.ht+s.ht); } - - QSizeF opSub(in QSizeF s) - { return QSizeF(this.wd-s.wd, this.ht-s.ht); } - - QSizeF opMul(qreal c) - { return QSizeF(this.wd*c, this.ht*c); } - - QSizeF opDivAssign(qreal c) - { - assert(!qFuzzyCompare(c + 1, 1.)); - wd = wd/c; ht = ht/c; - return *this; - } - - QSizeF opDiv(qreal c) - { - assert(!qFuzzyCompare(c + 1, 1.)); - return QSizeF(this.wd/c, this.ht/c); - } - -private: - qreal wd; - qreal ht; -} - -extern (C) void qtd_append_array_QSize(QSize[]* arr, QSize arg) -{ - *arr ~= arg; -} - -extern (C) void qtd_append_array_QSizeF(QSizeF[]* arr, QSizeF arg) -{ - *arr ~= arg; -} - -// C wrappers -// QSize -private extern(C) void __qtd_QSize_scale_QSize_AspectRatioMode(void* __this_nativeId, - void* s0, - int mode1); -private extern(C) void __qtd_QSize_writeTo_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void __qtd_QSize_readFrom_QDataStream(void* __this_nativeId, - void* arg__1); - -// QSizeF -private extern(C) void __qtd_QSizeF_writeTo_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void __qtd_QSizeF_readFrom_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void __qtd_QSizeF_scale_QSizeF_AspectRatioMode(void* __this_nativeId, - void* s0, - int mode1); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d1/qt/core/QSizeF.d --- a/qt/d1/qt/core/QSizeF.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -module qt.core.QSizeF; -/* dummy */ - -public import qt.core.QSize; diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d1/qt/core/QVariant.d --- a/qt/d1/qt/core/QVariant.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,715 +0,0 @@ -module qt.core.QVariant; - -public import qt.QGlobal; -private import qt.QtdObject; -private import qt.core.QMetaType; - -// automatic imports------------- -private import qt.core.QSizeF; -private import qt.core.QPoint; -private import qt.core.QRectF; -public import qt.core.Qt; -private import qt.core.QDateTime; -private import qt.core.QDataStream; -private import qt.core.QTime; -private import qt.core.QUrl; -private import qt.core.QRegExp; -private import qt.core.QBitArray; -private import qt.core.QLine; -private import qt.core.QByteArray; -private import qt.core.QSize; -private import qt.core.QDate; -private import qt.core.QPointF; -private import qt.core.QLineF; -private import qt.core.QRect; -private import qt.core.QLocale; - -version (Tango) -{ - import tango.core.Array; - import tango.stdc.stringz; - import tango.text.convert.Utf; - import tango.core.Traits; -} - - -public class QVariant : QtdObject -{ - enum Type { - Invalid = 0, - - Bool = 1, - Int = 2, - UInt = 3, - LongLong = 4, - ULongLong = 5, - Double = 6, - Char = 7, - Map = 8, - List = 9, - String = 10, - StringList = 11, - ByteArray = 12, - BitArray = 13, - Date = 14, - Time = 15, - DateTime = 16, - Url = 17, - Locale = 18, - Rect = 19, - RectF = 20, - Size = 21, - SizeF = 22, - Line = 23, - LineF = 24, - Point = 25, - PointF = 26, - RegExp = 27, - LastCoreType = RegExp, - - // value 62 is internally reserved - - Font = 64, - Pixmap = 65, - Brush = 66, - Color = 67, - Palette = 68, - Icon = 69, - Image = 70, - Polygon = 71, - Region = 72, - Bitmap = 73, - Cursor = 74, - SizePolicy = 75, - KeySequence = 76, - Pen = 77, - TextLength = 78, - TextFormat = 79, - Matrix = 80, - Transform = 81, - LastGuiType = Transform, - - UserType = 127, - - LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type - } - -// Functions - - private template getMetaId() - { - const char[] getMetaId = " - int i = qtd_MetatypeId(toStringz(name)); - if(i <= 0) - i = qRegisterMetaType!(T)(name);"; - } - - static public QVariant fromValue(T)(T obj) - { - QVariant var; - static if (is(T == class) || is(T == interface)) - { - string name = obj.classinfo.name; - mixin(getMetaId!()); - var = new QVariant(i, cast(void*)(obj)); - } - else static if (isDynamicArrayType!(T) || isStaticArrayType!(T) ) - { - string name = typeid(ElementTypeOfArray!(T)).toString ~ "[]"; - mixin(getMetaId!()); - auto darray = new DArrayToC; - darray.array = obj.dup; - var = new QVariant(i, cast(void*)(darray)); - } - else - { - string name = typeid(T).toString; - mixin(getMetaId!()); - auto data = new T; - *data = obj; - var = new QVariant(i, cast(void*)(data)); - } - return var; - } - - static public QVariant opCall(T)(T obj) - { - return fromValue(obj); - } - - public this() { - void* __qt_return_value = qtd_QVariant_QVariant(); - super(__qt_return_value); - } - - - public this(QDataStream s) { - void* __qt_return_value = qtd_QVariant_QVariant_QDataStream(s is null ? null : s.__nativeId); - super(__qt_return_value); - } - - - public this(Qt.GlobalColor color) { - void* __qt_return_value = qtd_QVariant_QVariant_GlobalColor(color); - super(__qt_return_value); - } - - - public this(bool b) { - void* __qt_return_value = qtd_QVariant_QVariant_bool(b); - super(__qt_return_value); - } - - - public this(QBitArray bitarray) { - void* __qt_return_value = qtd_QVariant_QVariant_QBitArray(bitarray is null ? null : bitarray.__nativeId); - super(__qt_return_value); - } - - - public this(QByteArray bytearray) { - void* __qt_return_value = qtd_QVariant_QVariant_QByteArray(bytearray is null ? null : bytearray.__nativeId); - super(__qt_return_value); - } - - - public this(QDate date) { - void* __qt_return_value = qtd_QVariant_QVariant_QDate(date is null ? null : date.__nativeId); - super(__qt_return_value); - } - - - public this(QDateTime datetime) { - void* __qt_return_value = qtd_QVariant_QVariant_QDateTime(datetime is null ? null : datetime.__nativeId); - super(__qt_return_value); - } - - - public this(string str) { - void* __qt_return_value = qtd_QVariant_QVariant_String(str); - super(__qt_return_value); - } - - - public this(QLine line) { - void* __qt_return_value = qtd_QVariant_QVariant_QLine(&line); - super(__qt_return_value); - } - - - public this(QLineF line) { - void* __qt_return_value = qtd_QVariant_QVariant_QLineF(&line); - super(__qt_return_value); - } - - - public this(QLocale locale) { - void* __qt_return_value = qtd_QVariant_QVariant_QLocale(locale is null ? null : locale.__nativeId); - super(__qt_return_value); - } - - - public this(QPoint pt) { - void* __qt_return_value = qtd_QVariant_QVariant_QPoint(&pt); - super(__qt_return_value); - } - - - public this(QPointF pt) { - void* __qt_return_value = qtd_QVariant_QVariant_QPointF(&pt); - super(__qt_return_value); - } - - - public this(QRect rect) { - void* __qt_return_value = qtd_QVariant_QVariant_QRect(&rect); - super(__qt_return_value); - } - - - public this(QRectF rect) { - void* __qt_return_value = qtd_QVariant_QVariant_QRectF(&rect); - super(__qt_return_value); - } - - - public this(QRegExp regExp) { - void* __qt_return_value = qtd_QVariant_QVariant_QRegExp(regExp is null ? null : regExp.__nativeId); - super(__qt_return_value); - } - - - public this(QSize size) { - void* __qt_return_value = qtd_QVariant_QVariant_QSize(&size); - super(__qt_return_value); - } - - - public this(QSizeF size) { - void* __qt_return_value = qtd_QVariant_QVariant_QSizeF(&size); - super(__qt_return_value); - } - - - public this(QTime time) { - void* __qt_return_value = qtd_QVariant_QVariant_QTime(time is null ? null : time.__nativeId); - super(__qt_return_value); - } - - - public this(QUrl url) { - void* __qt_return_value = qtd_QVariant_QVariant_QUrl(url is null ? null : url.__nativeId); - super(__qt_return_value); - } - - - public this(QVariant other) { - void* __qt_return_value = qtd_QVariant_QVariant_QVariant(other is null ? null : other.__nativeId); - super(__qt_return_value); - } - -/* - public this(char* str) { - void* __qt_return_value = qtd_QVariant_QVariant_nativepointerchar(str); - super(__qt_return_value); - } -*/ - - public this(double d) { - void* __qt_return_value = qtd_QVariant_QVariant_double(d); - super(__qt_return_value); - } - - - public this(int i) { - void* __qt_return_value = qtd_QVariant_QVariant_int(i); - super(__qt_return_value); - } - - - public this(int typeOrUserType, void* copy) { - void* __qt_return_value = qtd_QVariant_QVariant_int_nativepointervoid(typeOrUserType, copy); - super(__qt_return_value); - } - - - public this(long ll) { - void* __qt_return_value = qtd_QVariant_QVariant_long(ll); - super(__qt_return_value); - } - - - public this(uint ui) { - void* __qt_return_value = qtd_QVariant_QVariant_uint(ui); - super(__qt_return_value); - } - - - public this(ulong ull) { - void* __qt_return_value = qtd_QVariant_QVariant_ulong(ull); - super(__qt_return_value); - } - - private final bool canConvertImpl(string name) - { - int i = qtd_MetatypeId(toStringz(name)); - assert(i > 0); - return qtd_QVariant_canConvert(__nativeId, i); - } - - public final bool canConvert(Type)() { - static if ( is(Type == QBitArray) ) - return canConvertImpl("QBitArray"); - else static if ( is(Type == bool) ) - return canConvertImpl("bool"); - else static if ( is(Type == QByteArray) ) - return canConvertImpl("QByteArray"); - else static if ( is(Type == QDate) ) - return canConvertImpl("QDate"); - else static if ( is(Type == QDateTime) ) - return canConvertImpl("QDateTime"); - else static if ( is(Type == double) ) - return canConvertImpl("double"); - else static if ( is(Type == int) ) - return canConvertImpl("int"); - else static if ( is(Type == QLine) ) - return canConvertImpl("QLine"); - else static if ( is(Type == QLineF) ) - return canConvertImpl("QLineF"); - else static if ( is(Type == QLocale) ) - return canConvertImpl("QLocale"); - else static if ( is(Type == long) ) - return canConvertImpl("long"); - else static if ( is(Type == QPoint) ) - return canConvertImpl("QPoint"); - else static if ( is(Type == QPointF) ) - return canConvertImpl("QPointF"); - else static if ( is(Type == QRect) ) - return canConvertImpl("QRect"); - else static if ( is(Type == QRectF) ) - return canConvertImpl("QRectF"); - else static if ( is(Type == QRegExp) ) - return canConvertImpl("QRegExp"); - else static if ( is(Type == QSize) ) - return canConvertImpl("QSize"); - else static if ( is(Type == QSizeF) ) - return canConvertImpl("QSizeF"); - else static if ( is(Type == string) ) - return canConvertImpl("QString"); - else static if ( is(Type == QTime) ) - return canConvertImpl("QTime"); - else static if ( is(Type == uint) ) - return canConvertImpl("unsigned int"); // TODO: - else static if ( is(Type == ulong) ) - return canConvertImpl("unsigned long long"); // TODO: - else static if ( is(Type == QUrl) ) - return canConvertImpl("QUrl"); - else - { - static if( is( Type == class ) || is( Type == interface ) ) - { - Object object = cast(Object)qtd_QVariant_data(__nativeId); - if(object) - return cast(Type)(object) !is null; - return false; - } - else static if (isDynamicArrayType!(Type) || isStaticArrayType!(Type) ) - { - auto array = cast(DArrayToC*)qtd_QVariant_data(__nativeId); - return cast(Type)(array.array) !is null; - } - else - { - int i = qtd_MetatypeId(toStringz(typeid(Type).toString)); - return qtd_QVariant_canConvert(__nativeId, i); - } - } - } - - public final Type value(Type)() { - static if ( is(Type == QBitArray) ) - return toBitArra; - else static if ( is(Type == bool) ) - return toBool; - else static if ( is(Type == QByteArray) ) - return toByteArray; - else static if ( is(Type == QDate) ) - return toDate; - else static if ( is(Type == QDateTime) ) - return toDateTime; - else static if ( is(Type == double) ) - return toDouble; - else static if ( is(Type == int) ) - return toInt; - else static if ( is(Type == QLine) ) - return toLine; - else static if ( is(Type == QLineF) ) - return toLineF; - else static if ( is(Type == QLocale) ) - return toLocale; - else static if ( is(Type == long) ) - return toLongLong; - else static if ( is(Type == QPoint) ) - return toPoint; - else static if ( is(Type == QPointF) ) - return toPointF; - else static if ( is(Type == QRect) ) - return toRect; - else static if ( is(Type == QRectF) ) - return toRectF; - else static if ( is(Type == QRegExp) ) - return toRegExp; - else static if ( is(Type == QSize) ) - return toSize; - else static if ( is(Type == QSizeF) ) - return toSizeF; - else static if ( is(Type == string) ) - return toString; - else static if ( is(Type == QTime) ) - return toTime; - else static if ( is(Type == uint) ) - return toUInt; - else static if ( is(Type == ulong) ) - return toULongLong; - else static if ( is(Type == QUrl) ) - return toUrl; - else static if( is( Type == class ) || is( Type == interface ) ) - { - Object object = cast(Object)qtd_QVariant_data(__nativeId); - if(object) - return cast(Type)(object); - return null; - } - else static if (isDynamicArrayType!(Type) || isStaticArrayType!(Type) ) - { - auto array = cast(DArrayToC*)qtd_QVariant_data(__nativeId); - return cast(Type)(array.array); - } - else - { - return *cast(Type*)qtd_QVariant_data(__nativeId); - } - } - - public final void clear() { - qtd_QVariant_clear(__nativeId); - } - - protected final bool cmp(QVariant other) { - return qtd_QVariant_cmp_QVariant(__nativeId, other is null ? null : other.__nativeId); - } - - protected final void create(int type, void* copy) { - qtd_QVariant_create_int_nativepointervoid(__nativeId, type, copy); - } - - public final bool isNull() { - return qtd_QVariant_isNull(__nativeId); - } - - public final bool isValid() { - return qtd_QVariant_isValid(__nativeId); - } - - public final void load(QDataStream ds) { - qtd_QVariant_load_QDataStream(__nativeId, ds is null ? null : ds.__nativeId); - } - - public final void writeTo(QDataStream s) { - qtd_QVariant_writeTo_QDataStream(__nativeId, s is null ? null : s.__nativeId); - } - - public final QVariant operator_assign(QVariant other) { - void* __qt_return_value = qtd_QVariant_operator_assign_QVariant(__nativeId, other is null ? null : other.__nativeId); - return new QVariant(__qt_return_value, QtdObjectFlags.nativeOwnership); - } - - private final bool operator_equal(QVariant v) { - return qtd_QVariant_operator_equal_QVariant(__nativeId, v is null ? null : v.__nativeId); - } - - public final void readFrom(QDataStream s) { - qtd_QVariant_readFrom_QDataStream(__nativeId, s is null ? null : s.__nativeId); - } - - public final void save(QDataStream ds) { - qtd_QVariant_save_QDataStream(__nativeId, ds is null ? null : ds.__nativeId); - } - - public final QBitArray toBitArray() { - void* __qt_return_value = qtd_QVariant_toBitArray(__nativeId); - return new QBitArray(__qt_return_value); - } - - public final bool toBool() { - return qtd_QVariant_toBool(__nativeId); - } - - public final QByteArray toByteArray() { - void* __qt_return_value = qtd_QVariant_toByteArray(__nativeId); - return new QByteArray(__qt_return_value); - } - - public final QDate toDate() { - void* __qt_return_value = qtd_QVariant_toDate(__nativeId); - return new QDate(__qt_return_value); - } - - public final QDateTime toDateTime() { - void* __qt_return_value = qtd_QVariant_toDateTime(__nativeId); - return new QDateTime(__qt_return_value); - } - - public final double toDouble(bool* ok = null) { - return qtd_QVariant_toDouble_nativepointerbool(__nativeId, ok); - } - - public final int toInt(bool* ok = null) { - return qtd_QVariant_toInt_nativepointerbool(__nativeId, ok); - } - - public final QLine toLine() { - return qtd_QVariant_toLine(__nativeId); - } - - public final QLineF toLineF() { - return qtd_QVariant_toLineF(__nativeId); - } - - public final QLocale toLocale() { - void* __qt_return_value = qtd_QVariant_toLocale(__nativeId); - return new QLocale(__qt_return_value); - } - - public final long toLongLong(bool* ok = null) { - return qtd_QVariant_toLongLong_nativepointerbool(__nativeId, ok); - } - - public final QPoint toPoint() { - return qtd_QVariant_toPoint(__nativeId); - } - - public final QPointF toPointF() { - return qtd_QVariant_toPointF(__nativeId); - } - - public final QRect toRect() { - return qtd_QVariant_toRect(__nativeId); - } - - public final QRectF toRectF() { - return qtd_QVariant_toRectF(__nativeId); - } - - public final QRegExp toRegExp() { - void* __qt_return_value = qtd_QVariant_toRegExp(__nativeId); - return new QRegExp(__qt_return_value); - } - - public final QSize toSize() { - return qtd_QVariant_toSize(__nativeId); - } - - public final QSizeF toSizeF() { - return qtd_QVariant_toSizeF(__nativeId); - } - - public final string toString() { - string res; - qtd_QVariant_toString(__nativeId, &res); - return res; - } - - public final QTime toTime() { - void* __qt_return_value = qtd_QVariant_toTime(__nativeId); - return new QTime(__qt_return_value); - } - - public final uint toUInt(bool* ok = null) { - return qtd_QVariant_toUInt_nativepointerbool(__nativeId, ok); - } - - public final ulong toULongLong(bool* ok = null) { - return qtd_QVariant_toULongLong_nativepointerbool(__nativeId, ok); - } - - public final QUrl toUrl() { - void* __qt_return_value = qtd_QVariant_toUrl(__nativeId); - return new QUrl(__qt_return_value); - } - - public final char* typeName() { - return qtd_QVariant_typeName(__nativeId); - } - - public final Type type() { - return cast(Type)qtd_QVariant_type(__nativeId); - } - - public final int userType() { - return qtd_QVariant_userType(__nativeId); - } -// Field accessors - - public this(void* native_id, QtdObjectFlags flags = QtdObjectFlags.none) { - super(native_id, flags); - } - - protected override void __deleteNative() { - qtd_QVariant_destructor(__nativeId); - } - -// Injected code in class -} -extern (C) void qtd_QVariant_destructor(void *ptr); - - -// C wrappers -private extern(C) void* qtd_QVariant_QVariant(); -private extern(C) void* qtd_QVariant_QVariant_QDataStream(void* s0); -private extern(C) void* qtd_QVariant_QVariant_GlobalColor(int color0); -private extern(C) void* qtd_QVariant_QVariant_bool(bool b0); -private extern(C) void* qtd_QVariant_QVariant_QBitArray(void* bitarray0); -private extern(C) void* qtd_QVariant_QVariant_QByteArray(void* bytearray0); -private extern(C) void* qtd_QVariant_QVariant_QDate(void* date0); -private extern(C) void* qtd_QVariant_QVariant_QDateTime(void* datetime0); -private extern(C) void* qtd_QVariant_QVariant_String(string string0); -private extern(C) void* qtd_QVariant_QVariant_QLine(void* line0); -private extern(C) void* qtd_QVariant_QVariant_QLineF(void* line0); -private extern(C) void* qtd_QVariant_QVariant_QLocale(void* locale0); -private extern(C) void* qtd_QVariant_QVariant_QPoint(void* pt0); -private extern(C) void* qtd_QVariant_QVariant_QPointF(void* pt0); -private extern(C) void* qtd_QVariant_QVariant_QRect(void* rect0); -private extern(C) void* qtd_QVariant_QVariant_QRectF(void* rect0); -private extern(C) void* qtd_QVariant_QVariant_QRegExp(void* regExp0); -private extern(C) void* qtd_QVariant_QVariant_QSize(void* size0); -private extern(C) void* qtd_QVariant_QVariant_QSizeF(void* size0); -private extern(C) void* qtd_QVariant_QVariant_QTime(void* time0); -private extern(C) void* qtd_QVariant_QVariant_QUrl(void* url0); -private extern(C) void* qtd_QVariant_QVariant_QVariant(void* other0); -private extern(C) void* qtd_QVariant_QVariant_nativepointerchar(char* str0); -private extern(C) void* qtd_QVariant_QVariant_double(double d0); -private extern(C) void* qtd_QVariant_QVariant_int(int i0); -private extern(C) void* qtd_QVariant_QVariant_int_nativepointervoid(int typeOrUserType0, - void* copy1); -private extern(C) void* qtd_QVariant_QVariant_long(long ll0); -private extern(C) void* qtd_QVariant_QVariant_uint(uint ui0); -private extern(C) void* qtd_QVariant_QVariant_ulong(ulong ull0); -private extern(C) bool qtd_QVariant_canConvert(void* __this_nativeId, int); -private extern(C) void qtd_QVariant_clear(void* __this_nativeId); -private extern(C) bool qtd_QVariant_cmp_QVariant(void* __this_nativeId, - void* other0); -private extern(C) void qtd_QVariant_create_int_nativepointervoid(void* __this_nativeId, - int type0, - void* copy1); -private extern(C) bool qtd_QVariant_isNull(void* __this_nativeId); -private extern(C) bool qtd_QVariant_isValid(void* __this_nativeId); -private extern(C) void qtd_QVariant_load_QDataStream(void* __this_nativeId, - void* ds0); -private extern(C) void qtd_QVariant_writeTo_QDataStream(void* __this_nativeId, - void* s0); -private extern(C) void* qtd_QVariant_operator_assign_QVariant(void* __this_nativeId, - void* other0); -private extern(C) bool qtd_QVariant_operator_equal_QVariant(void* __this_nativeId, - void* v0); -private extern(C) void qtd_QVariant_readFrom_QDataStream(void* __this_nativeId, - void* s0); -private extern(C) void qtd_QVariant_save_QDataStream(void* __this_nativeId, - void* ds0); -private extern(C) void* qtd_QVariant_toBitArray(void* __this_nativeId); -private extern(C) bool qtd_QVariant_toBool(void* __this_nativeId); -private extern(C) void* qtd_QVariant_toByteArray(void* __this_nativeId); -private extern(C) void* qtd_QVariant_toDate(void* __this_nativeId); -private extern(C) void* qtd_QVariant_toDateTime(void* __this_nativeId); -private extern(C) double qtd_QVariant_toDouble_nativepointerbool(void* __this_nativeId, - bool* ok0); -private extern(C) int qtd_QVariant_toInt_nativepointerbool(void* __this_nativeId, - bool* ok0); -private extern(C) QLine qtd_QVariant_toLine(void* __this_nativeId); -private extern(C) QLineF qtd_QVariant_toLineF(void* __this_nativeId); -private extern(C) void* qtd_QVariant_toLocale(void* __this_nativeId); -private extern(C) long qtd_QVariant_toLongLong_nativepointerbool(void* __this_nativeId, - bool* ok0); -private extern(C) QPoint qtd_QVariant_toPoint(void* __this_nativeId); -private extern(C) QPointF qtd_QVariant_toPointF(void* __this_nativeId); -private extern(C) QRect qtd_QVariant_toRect(void* __this_nativeId); -private extern(C) QRectF qtd_QVariant_toRectF(void* __this_nativeId); -private extern(C) void* qtd_QVariant_toRegExp(void* __this_nativeId); -private extern(C) QSize qtd_QVariant_toSize(void* __this_nativeId); -private extern(C) QSizeF qtd_QVariant_toSizeF(void* __this_nativeId); -private extern(C) void qtd_QVariant_toString(void* __this_nativeId, - void* __java_return_value); -private extern(C) void* qtd_QVariant_toTime(void* __this_nativeId); -private extern(C) uint qtd_QVariant_toUInt_nativepointerbool(void* __this_nativeId, - bool* ok0); -private extern(C) ulong qtd_QVariant_toULongLong_nativepointerbool(void* __this_nativeId, - bool* ok0); -private extern(C) void* qtd_QVariant_toUrl(void* __this_nativeId); -private extern(C) char* qtd_QVariant_typeName(void* __this_nativeId); -private extern(C) int qtd_QVariant_type(void* __this_nativeId); -private extern(C) int qtd_QVariant_userType(void* __this_nativeId); -private extern(C) void *qtd_QVariant_data(void* __this_nativeId); - -// Just the private functions for abstract functions implemeneted in superclasses - -// Virtual Dispatch functions diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d1/qt/qtd/Str.d --- a/qt/d1/qt/qtd/Str.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/** - * - * Copyright: Copyright QtD Team, 2008-2009 - * License: Boost License 1.0 -* -* Copyright QtD Team, 2008-2009 -* Distributed under the Boost Software License, Version 1.0. -* (See accompanying file boost-license-1.0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -* -*/ - -module qt.QtdObject; - -import qt.Signal; - -enum QtdObjectFlags : ubyte -{ - none, - nativeOwnership = 0x1, - dOwnership = 0x2, - dynamicEntity = 0x4 - //gcManaged = 0x4 -} - -package abstract class QtdObject -{ - protected QtdObjectFlags __flags_; - void* __nativeId; - - this(void* nativeId, QtdObjectFlags flags = QtdObjectFlags.none) - { - __nativeId = nativeId; - __flags_ = flags; - } - - final QtdObjectFlags __flags() - { - return __flags_; - } - - /+ final +/ void __setFlags(QtdObjectFlags flags, bool value) - { - if (value) - __flags_ |= flags; - else - __flags_ &= ~flags; - } - - // COMPILER BUG: 3206 - protected void __deleteNative() - { - assert(false); - } - - ~this() - { - if (!(__flags_ & QtdObjectFlags.nativeOwnership)) - { - // avoid deleting D object twice. - __flags_ |= QtdObjectFlags.dOwnership; - __deleteNative; - } - } -} diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d2/qt/Signal.d --- a/qt/d2/qt/Signal.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,296 +0,0 @@ -/** - * - * Copyright: Copyright QtD Team, 2008-2009 - * Authors: Max Samukha, Eldar Insafutdinov - * License: (reinterpret_cast(&_t1)) }; - // at least for string argument need to construct a QString value - string res = prepareSignalArguments!(Args); - - res ~= "void*[" ~ __toString(Args.length+1) ~ "] _a = [null"; - foreach(i, _; Args) - res ~= ", " ~ "cast(void*) (" ~ convertSignalArgument!(Args[i])("_t" ~ __toString(i)) ~ ")"; - res ~= "];\n"; - return res; -} - -public string SignalEmitter(A...)(SignalType signalType, string name, string[] defVals, int localIndex) -{ - string fullArgs, args; - int defValsLength = defVals.length; - string argsConversion = ""; - string argsPtr = "null"; - static if (A.length) - { - while(A.length != defVals.length) - defVals = "" ~ defVals; - - fullArgs = A[0].stringof ~ " _t0"; - if (defVals[0].length) - fullArgs ~= " = " ~ defVals[0]; - args = "_t0"; - foreach(i, _; A[1..$]) - { - fullArgs ~= ", " ~ A[i+1].stringof ~ " _t" ~ __toString(i+1); - if (defVals[i+1].length) - fullArgs ~= " = " ~ defVals[i+1]; - args ~= ", _t" ~ __toString(i+1); - } - // build up conversion of signal args from D to C++ - argsPtr = "_a.ptr"; - argsConversion = convertSignalArguments!(A)(); - } - string attribute; - string sigName = name; - if (signalType == SignalType.BindQtSignal) - name ~= "_emit"; - else - attribute = "protected "; - - string indexArgs = __toString(localIndex); - if(defValsLength > 0) - indexArgs ~= ", " ~ __toString(localIndex+defValsLength); - string str = attribute ~ "final void " ~ name ~ "(" ~ fullArgs ~ ") {\n" ~ argsConversion ~ "\n" - ~ " QMetaObject.activate(this, typeof(this).staticMetaObject, " ~ indexArgs ~ ", " ~ argsPtr ~ ");\n" - ~ "}\n"; // ~ - return str; -} -/** ---------------- */ - - -const string signalPrefix = "__signal"; -const string slotPrefix = "__slot"; - -enum SignalType -{ - BindQtSignal, - NewSignal, - NewSlot -} - -string signature(T...)(string name) -{ - string res = name ~ "("; - foreach(i, _; T) - { - if(i > 0) - res ~= ","; - static if (isNativeType!(T[i])) - res ~= Unqual!(T[i]).stringof; - else - res ~= T[i].stringof; - } - res ~= ")"; - return res; -} - -// ------------------------------------------------------------------ - -string[] getSymbols(C)(string prefix) -{ - string[] result; - auto allSymbols = __traits(derivedMembers, C); - foreach(s; allSymbols) - if(ctfeStartsWith(s, prefix)) - result ~= s; - return result; -} - -string removePrefix(string source) -{ - foreach (i, c; source) - if (c == '_') - return source[i+1..$]; - return source; -} - -template Alias(T...) -{ - alias T Alias; -} - -// recursive search in the static meta-information -template findSymbolsImpl2(C, alias signals, int id) -{ - alias Alias!(__traits(getOverloads, C, signals[id])) current; - static if (signals.length - id - 1 > 0) - alias TypeTuple!(current, findSymbolsImpl2!(C, signals, id + 1).result) result; - else - alias current result; -} - -template findSymbols2(C, string prefix) -{ - enum signals = getSymbols!(C)(prefix); - static if (signals) - alias findSymbolsImpl2!(C, signals, 0).result result; - else - alias TypeTuple!() result; -} - -template findSignals(C) -{ - alias findSymbols2!(C, "signal_").result findSignals; -} - -template findSlots(C) -{ - alias findSymbols2!(C, "slot_").result findSlots; -} - -/* commented out for future when we will implement default arguments -template metaMethods(alias func, int index, int defValsCount) -{ - static if(defValsCount >= 0) { - alias TupleWrapper!(func, index) current; -// pragma(msg, __traits(identifier, (current.at)[0]) ~ " " ~ typeof(&(current.at)[0]).stringof); - alias metaMethods!(func, index+1, defValsCount-1).result next; - alias TypeTuple!(current, next) result; - } - else - { - alias TypeTuple!() result; - } -} -*/ - -template toMetaEntriesImpl(int id, Methods...) -{ - static if (Methods.length > id) - { - alias typeof(&Methods[id]) Fn; -// commented out for future when we will implement default arguments -// enum defValsLength = 0; //ParameterTypeTuple!(Fn).length - requiredArgCount!(Methods[id])(); -// pragma(msg, __traits(identifier, Methods[id]) ~ " " ~ typeof(&Methods[id]).stringof); -// alias metaMethods!(Methods[id], 0, defValsLength).result subres; - alias TupleWrapper!(removePrefix(__traits(identifier, Methods[id])), typeof(&Methods[id])) subres; - alias TypeTuple!(subres, toMetaEntriesImpl!(id+1, Methods).result) result; - } - else - { - alias TypeTuple!() result; - } -} - -template toMetaEntries(Methods...) -{ - alias TupleWrapper!(toMetaEntriesImpl!(0, Methods).result) toMetaEntries; -} diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d2/qt/core/QLine.d --- a/qt/d2/qt/core/QLine.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,413 +0,0 @@ -module qt.core.QLine; - -public import qt.QGlobal; -public import qt.core.Qt; -public import qt.core.QPoint; -public import qt.core.QDataStream; - - -public struct QLine -{ - public static QLine opCall() { - QLine ln; - ln.pt1 = QPoint(); - ln.pt2 = QPoint(); - return ln; - } - - public this(QPoint pt1_, QPoint pt2_) { - pt1 = pt1_; - pt2 = pt2_; - } - - public this(int x1pos, int y1pos, int x2pos, int y2pos) { - pt1 = QPoint(x1pos, y1pos); - pt2 = QPoint(x2pos, y2pos); - } - - bool isNull() // const - { - return pt1 == pt2; - } - - int x1() // const - { - return pt1.x(); - } - - int y1() // const - { - return pt1.y(); - } - - int x2() // const - { - return pt2.x(); - } - - int y2() // const - { - return pt2.y(); - } - - QPoint p1() // const - { - return pt1; - } - - QPoint p2() // const - { - return pt2; - } - - int dx() // const - { - return pt2.x() - pt1.x(); - } - - int dy() // const - { - return pt2.y() - pt1.y(); - } - - void translate(ref QPoint point) - { - pt1 += point; - pt2 += point; - } - - void translate(int adx, int ady) - { - translate(QPoint(adx, ady)); - } - - QLine translated(ref QPoint p) // const - { - return QLine(pt1 + p, pt2 + p); - } - - QLine translated(int adx, int ady) // const - { - return translated(QPoint(adx, ady)); - } - - void p1(ref QPoint aP1) - { - pt1 = aP1; - } - - void p2(ref QPoint aP2) - { - pt2 = aP2; - } - - void setP1(ref QPoint aP1) // for convenience - { - pt1 = aP1; - } - - void setP2(ref QPoint aP2) // for convenience - { - pt2 = aP2; - } - - void setPoints(ref QPoint aP1, ref QPoint aP2) - { - pt1 = aP1; - pt2 = aP2; - } - - void setLine(int aX1, int aY1, int aX2, int aY2) - { - pt1 = QPoint(aX1, aY1); - pt2 = QPoint(aX2, aY2); - } - - bool opEquals(ref const QLine d) const - { - return pt1 == d.pt1 && pt2 == d.pt2; - } - - public final void writeTo(QDataStream arg__1) { - qtd_QLine_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final void readFrom(QDataStream arg__1) { - qtd_QLine_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); - } - - // service stuff - public alias void __isNativeValueType; - - struct QTypeInfo - { - enum bool isComplex = true; - enum bool isStatic = false; - enum bool isLarge = true; - enum bool isPointer = false; - enum bool isDummy = false; - } -private: - QPoint pt1, pt2; -} - - -public enum QLineF_IntersectType { - NoIntersection = 0, - BoundedIntersection = 1, - UnboundedIntersection = 2 -} - -public struct QLineF -{ - - alias QLineF_IntersectType IntersectType; - - alias QLineF_IntersectType.NoIntersection NoIntersection; - alias QLineF_IntersectType.BoundedIntersection BoundedIntersection; - alias QLineF_IntersectType.UnboundedIntersection UnboundedIntersection; - - public static QLineF opCall() { - QLineF ln; - ln.pt1 = QPointF(); - ln.pt2 = QPointF(); - return ln; - } - - public this(QPointF apt1, QPointF apt2) { - pt1 = apt1; - pt2 = apt2; - } - - public this(qreal x1pos, qreal y1pos, qreal x2pos, qreal y2pos) { - pt1 = QPointF(x1pos, y1pos); - pt2 = QPointF(x2pos, y2pos); - } - - public this(QLine line){ - pt1 = QPointF(line.p1()); - pt2 = QPointF(line.p2()); - } - - public final bool isNull() // const - { - return qtd_QLineF_isNull(&this); - } - - qreal x1() // const - { - return pt1.x(); - } - - qreal y1() // const - { - return pt1.y(); - } - - qreal x2() // const - { - return pt2.x(); - } - - qreal y2() // const - { - return pt2.y(); - } - - QPointF p1() // const - { - return pt1; - } - - QPointF p2() // const - { - return pt2; - } - - qreal dx() // const - { - return pt2.x() - pt1.x(); - } - - qreal dy() // const - { - return pt2.y() - pt1.y(); - } - - QLineF normalVector() // const - { - return QLineF(p1(), p1() + QPointF(dy(), -dx())); - } - - void translate(ref QPointF point) - { - pt1 += point; - pt2 += point; - } - - void translate(qreal adx, qreal ady) - { - this.translate(QPointF(adx, ady)); - } - - QLineF translated(ref QPointF p) // const - { - return QLineF(pt1 + p, pt2 + p); - } - - QLineF translated(qreal adx, qreal ady) // const - { - return translated(QPointF(adx, ady)); - } - - void setLength(qreal len) - { - if (isNull()) - return; - QLineF v = unitVector(); - pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len); - } - - void length(qreal len) - { - if (isNull()) - return; - QLineF v = unitVector(); - pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len); - } - - QPointF pointAt(qreal t) // const - { - qreal vx = pt2.x() - pt1.x(); - qreal vy = pt2.y() - pt1.y(); - return QPointF(pt1.x() + vx * t, pt1.y() + vy * t); - } - - QLine toLine() // const - { - return QLine(pt1.toPoint(), pt2.toPoint()); - } - - void setP1(ref QPointF aP1) - { - pt1 = aP1; - } - - void setP2(ref QPointF aP2) - { - pt2 = aP2; - } - - void p1(ref QPointF aP1) - { - pt1 = aP1; - } - - void p2(ref QPointF aP2) - { - pt2 = aP2; - } - - void setPoints(ref QPointF aP1, ref QPointF aP2) - { - pt1 = aP1; - pt2 = aP2; - } - - void setLine(qreal aX1, qreal aY1, qreal aX2, qreal aY2) - { - pt1 = QPointF(aX1, aY1); - pt2 = QPointF(aX2, aY2); - } - - bool opEquals(ref const QLineF d) const - { - return pt1 == d.pt1 && pt2 == d.pt2; - } - - public final double angle() { - return qtd_QLineF_angle(&this); - } - - public final double angle(ref QLineF l) { - return qtd_QLineF_angle_QLineF(&this, &l); - } - - public final double angleTo(ref QLineF l) { - return qtd_QLineF_angleTo_QLineF(&this, &l); - } - - // ### Qt 5: rename intersects() or intersection() and rename IntersectType IntersectionType - private final QLineF_IntersectType intersect(ref QLineF l, QPointF* intersectionPoint) { - return cast(QLineF_IntersectType) qtd_QLineF_intersect_QLineF_nativepointerQPointF(&this, &l, intersectionPoint); - } - - public final double length() { - return qtd_QLineF_length(&this); - } - - public final void writeTo(QDataStream arg__1) { - qtd_QLineF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final void readFrom(QDataStream arg__1) { - qtd_QLineF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final void setAngle(double angle) { - qtd_QLineF_setAngle_double(&this, angle); - } - - public final QLineF unitVector() { - return qtd_QLineF_unitVector(&this); - } - - public static QLineF fromPolar(double length, double angle) { - return qtd_QLineF_fromPolar_double_double(length, angle); - } - - // service stuff - public alias void __isNativeValueType; - - struct QTypeInfo - { - enum bool isComplex = true; - enum bool isStatic = false; - enum bool isLarge = true; - enum bool isPointer = false; - enum bool isDummy = false; - } - - private: - QPointF pt1, pt2; -} - - -// C wrappers -// QLine -private extern(C) void qtd_QLine_writeTo_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void qtd_QLine_readFrom_QDataStream(void* __this_nativeId, - void* arg__1); - -// QLineF -private extern(C) bool qtd_QLineF_isNull(void* __this_nativeId); -private extern(C) double qtd_QLineF_angle(void* __this_nativeId); -private extern(C) double qtd_QLineF_angle_QLineF(void* __this_nativeId, - void* l0); -private extern(C) double qtd_QLineF_angleTo_QLineF(void* __this_nativeId, - void* l0); -private extern(C) int qtd_QLineF_intersect_QLineF_nativepointerQPointF(void* __this_nativeId, - void* l0, - void* intersectionPoint1); -private extern(C) double qtd_QLineF_length(void* __this_nativeId); -private extern(C) void qtd_QLineF_writeTo_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void qtd_QLineF_readFrom_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void qtd_QLineF_setAngle_double(void* __this_nativeId, - double angle0); - -private extern(C) QLineF qtd_QLineF_unitVector(void* __this_nativeId); -private extern(C) QLineF qtd_QLineF_fromPolar_double_double(double length0, - double angle1); diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d2/qt/core/QLineF.d --- a/qt/d2/qt/core/QLineF.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -module qt.core.QLineF; -/* dummy */ - -public import qt.core.QLine; \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d2/qt/core/QModelIndex.d --- a/qt/d2/qt/core/QModelIndex.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -module qt.core.QModelIndex; - -public import qt.QGlobal; -private import qt.core.QObject; - -// automatic imports------------- -//private import qt.core.QVariant; -private import qt.core.QAbstractItemModel; -public import qt.core.Qt; - - -public struct QModelIndex -{ - public static QModelIndex opCall() { - QModelIndex mi; - mi.r = mi.c = -1; - mi.p = mi.m = null; - return mi; - } - - public final QModelIndex child(int row, int column) { - return __qtd_QModelIndex_child_int_int(&this, row, column); - } - - public final int column() const { - return __qtd_QModelIndex_column(cast(void*)&this); - } - - public final QVariant data(int role = 0) { - void* __qt_return_value = __qtd_QModelIndex_data_int(&this, role); - return new QVariant(__qt_return_value); - } - - public final int flags() { - return __qtd_QModelIndex_flags(&this); - } - - public final long internalId() { - return __qtd_QModelIndex_internalId(&this); - } - - public final void* internalPointer() const { - //return __qtd_QModelIndex_internalPointer(&this); - return cast(void*)p; - } - - public final Object object() { - return cast(Object) p; - } - - public final bool isValid() const { - return __qtd_QModelIndex_isValid(cast(void*)&this); - } - - public final QAbstractItemModel model() { -// void* __qt_return_value = __qtd_QModelIndex_model(&this); - void* __qt_return_value = m; - if (__qt_return_value is null) - return null; - void* d_obj = qtd_get_d_qobject(__qt_return_value); - return cast(QAbstractItemModel) d_obj; - } - - private final bool operator_less(QModelIndex other) { - return __qtd_QModelIndex_operator_less_QModelIndex(&this, other); - } - - private final bool operator_equal(QModelIndex other) { - return __qtd_QModelIndex_operator_equal_QModelIndex(&this, other); - } - - public final QModelIndex parent() { - return __qtd_QModelIndex_parent(&this); - } - - public final int row() const { - return __qtd_QModelIndex_row(cast(void*)&this); - } - - public final QModelIndex sibling(int row, int column) { - return __qtd_QModelIndex_sibling_int_int(&this, row, column); - } - - public alias void __isNativeValueType; - - struct QTypeInfo - { - enum bool isComplex = true; - enum bool isStatic = false; - enum bool isLarge = true; - enum bool isPointer = false; - enum bool isDummy = false; - } - -private: - int r; - int c; - void *p; - void *m; -} - - -alias QModelIndex QModelIndexAccessor; - - -// C wrappers -private extern(C) void* __qtd_QModelIndex_QModelIndex_QModelIndex(QModelIndex other0); -private extern(C) QModelIndex __qtd_QModelIndex_child_int_int(void* __this_nativeId, - int row0, - int column1); -private extern(C) int __qtd_QModelIndex_column(void* __this_nativeId); -private extern(C) void* __qtd_QModelIndex_data_int(void* __this_nativeId, - int role0); -private extern(C) int __qtd_QModelIndex_flags(void* __this_nativeId); -private extern(C) long __qtd_QModelIndex_internalId(void* __this_nativeId); -private extern(C) void* __qtd_QModelIndex_internalPointer(void* __this_nativeId); -private extern(C) bool __qtd_QModelIndex_isValid(void* __this_nativeId); -private extern(C) void* __qtd_QModelIndex_model(void* __this_nativeId); -private extern(C) bool __qtd_QModelIndex_operator_less_QModelIndex(void* __this_nativeId, - QModelIndex other0); -private extern(C) bool __qtd_QModelIndex_operator_equal_QModelIndex(void* __this_nativeId, - QModelIndex other0); -private extern(C) QModelIndex __qtd_QModelIndex_parent(void* __this_nativeId); -private extern(C) int __qtd_QModelIndex_row(void* __this_nativeId); -private extern(C) QModelIndex __qtd_QModelIndex_sibling_int_int(void* __this_nativeId, - int row0, - int column1); - \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d2/qt/core/QPoint.d --- a/qt/d2/qt/core/QPoint.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,254 +0,0 @@ -module qt.core.QPoint; - -public import qt.QGlobal; -public import qt.core.Qt; -public import qt.core.QDataStream; - - -public struct QPoint -{ - -// Functions - public static QPoint opCall() { - QPoint pt; - pt.xp = pt.yp = 0; - return pt; - } - - public this(int xpos, int ypos) { - xp = xpos; - yp = ypos; - } - - bool isNull() // const - { return xp == 0 && yp == 0; } - - int x() const - { return xp; } - - int y() const - { return yp; } - - void x(int xpos) - { xp = xpos; } - - void y(int ypos) - { yp = ypos; } - - void setX(int xpos) // for convenience - { xp = xpos; } - - void setY(int ypos) // for convenience - { yp = ypos; } - - public final int manhattanLength() { - return qtd_QPoint_manhattanLength(&this); - } -/* -inline int &rx() -{ return xp; } - -inline int &ry() -{ return yp; } -*/ - - QPoint opAddAssign(ref QPoint p) - { xp+=p.xp; yp+=p.yp; return this; } - - QPoint opSubAssign(ref QPoint p) - { xp-=p.xp; yp-=p.yp; return this; } - - QPoint opMulAssign(qreal c) - { xp = qRound(xp*c); yp = qRound(yp*c); return this; } - - bool opEquals(ref const QPoint p) const - { return xp == p.xp && yp == p.yp; } - - QPoint opAdd(ref QPoint p) - { return QPoint(this.xp+p.xp, this.yp+p.yp); } - - QPoint opSub(ref QPoint p) - { return QPoint(this.xp-p.xp, this.yp-p.yp); } - - QPoint opMul(qreal c) - { return QPoint(qRound(this.xp*c), qRound(this.yp*c)); } - - QPoint opDivAssign(qreal c) - { - xp = qRound(xp/c); - yp = qRound(yp/c); - return this; - } - - QPoint opDiv(qreal c) - { - return QPoint(qRound(this.xp/c), qRound(this.yp/c)); - } - - public final void writeTo(QDataStream arg__1) { - qtd_QPoint_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final void readFrom(QDataStream arg__1) { - qtd_QPoint_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); - } - - // service stuff - public alias void __isNativeValueType; - - struct QTypeInfo - { - enum bool isComplex = true; - enum bool isStatic = false; - enum bool isLarge = true; - enum bool isPointer = false; - enum bool isDummy = false; - } - - -private: - // ### Qt 5; remove the ifdef and just have the same order on all platforms. - version(OSX) - { - int yp; - int xp; - } - else - { - int xp; - int yp; - } -} - - -public struct QPointF -{ - public static QPointF opCall() { - QPointF pt; - pt.xp = pt.yp = 0; - return pt; - } - - public this(qreal xpos, qreal ypos) { - xp = xpos; - yp = ypos; - } - - public this(QPoint p) { - xp = p.x(); - yp = p.y(); - } - - bool isNull() //const - { - return qIsNull(xp) && qIsNull(yp); - } - - qreal x() //const - { - return xp; - } - - qreal y() //const - { - return yp; - } - - void x(qreal xpos) - { - xp = xpos; - } - - void y(qreal ypos) - { - yp = ypos; - } -/* -inline qreal &QPointF::rx() -{ - return xp; -} - -inline qreal &QPointF::ry() -{ - return yp; -} -*/ - - QPointF opAddAssign(ref QPointF p) - { xp+=p.xp; yp+=p.yp; return this; } - - QPointF opSubAssign(ref QPointF p) - { xp-=p.xp; yp-=p.yp; return this; } - - QPointF opMulAssign(qreal c) - { xp*=c; yp*=c; return this; } - - bool opEquals(ref const QPointF p) const - { return qFuzzyCompare(xp, p.xp) && qFuzzyCompare(yp, p.yp); } - - QPointF opAdd(ref QPointF p) - { return QPointF(this.xp+p.xp, this.yp+p.yp); } - - QPointF opSub(ref QPointF p) - { return QPointF(this.xp-p.xp, this.yp-p.yp); } - - QPointF opMul(qreal c) - { return QPointF(this.xp*c, this.yp*c); } - - QPointF opDivAssign(qreal c) - { - xp/=c; - yp/=c; - return this; - } - - QPointF opDiv(qreal c) - { - return QPointF(xp/c, yp/c); - } - - QPoint toPoint() //const - { - return QPoint(qRound(xp), qRound(yp)); - } - - public final void writeTo(QDataStream arg__1) { - qtd_QPointF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final void readFrom(QDataStream arg__1) { - qtd_QPointF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); - } - - // service stuff - public alias void __isNativeValueType; - - struct QTypeInfo - { - enum bool isComplex = true; - enum bool isStatic = false; - enum bool isLarge = true; - enum bool isPointer = false; - enum bool isDummy = false; - } - -private: - qreal xp; - qreal yp; -} - - -// C wrappers -// QPoint -private extern(C) int qtd_QPoint_manhattanLength(void* __this_nativeId); -private extern(C) void qtd_QPoint_writeTo_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void qtd_QPoint_readFrom_QDataStream(void* __this_nativeId, - void* arg__1); - -// QPointF -private extern(C) void qtd_QPointF_writeTo_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void qtd_QPointF_readFrom_QDataStream(void* __this_nativeId, - void* arg__1); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d2/qt/core/QPointF.d --- a/qt/d2/qt/core/QPointF.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -module qt.core.QPointF; -/* dummy */ - -public import qt.core.QPoint; diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d2/qt/core/QRect.d --- a/qt/d2/qt/core/QRect.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,388 +0,0 @@ -module qt.core.QRect; - -public import qt.QGlobal; -public import qt.core.Qt; -public import qt.core.QDataStream; -public import qt.core.QSize; -public import qt.core.QPoint; - - -public struct QRect -{ - public static QRect opCall() { - QRect rt; - rt.x1 = rt.y1 = 0; - rt.x2 = rt.y2 = -1; - return rt; - } - - public this(int aleft, int atop, int awidth, int aheight) - { - x1 = aleft; - y1 = atop; - x2 = (aleft + awidth - 1); - y2 = (atop + aheight - 1); - } - - public this(QPoint atopLeft, QPoint abottomRight) - { - x1 = atopLeft.x(); - y1 = atopLeft.y(); - x2 = abottomRight.x(); - y2 = abottomRight.y(); - } - - public this(ref QPoint atopLeft, ref QSize asize) - { - x1 = atopLeft.x(); - y1 = atopLeft.y(); - x2 = (x1+asize.width() - 1); - y2 = (y1+asize.height() - 1); - } - - bool isNull() const - { return x2 == x1 - 1 && y2 == y1 - 1; } - - bool isEmpty() const - { return x1 > x2 || y1 > y2; } - - bool isValid() const - { return x1 <= x2 && y1 <= y2; } - - int left() const - { return x1; } - - int top() const - { return y1; } - - int right() const - { return x2; } - - int bottom() const - { return y2; } - - int x() const - { return x1; } - - int y() const - { return y1; } - - void left(int pos) - { x1 = pos; } - - void top(int pos) - { y1 = pos; } - - void right(int pos) - { x2 = pos; } - - void bottom(int pos) - { y2 = pos; } - - void setLeft(int pos) - { x1 = pos; } - - void setTop(int pos) - { y1 = pos; } - - void setRight(int pos) - { x2 = pos; } - - void setBottom(int pos) - { y2 = pos; } - - void setTopLeft(const QPoint p) - { x1 = p.x(); y1 = p.y(); } - - void setBottomRight(const QPoint p) - { x2 = p.x(); y2 = p.y(); } - - void setTopRight(const QPoint p) - { x2 = p.x(); y1 = p.y(); } - - void setBottomLeft(const QPoint p) - { x1 = p.x(); y2 = p.y(); } - - void setX(int ax) - { x1 = ax; } - - void setY(int ay) - { y1 = ay; } - - QPoint topLeft() const - { return QPoint(x1, y1); } - - QPoint bottomRight() const - { return QPoint(x2, y2); } - - QPoint topRight() const - { return QPoint(x2, y1); } - - QPoint bottomLeft() const - { return QPoint(x1, y2); } - - QPoint center() const - { return QPoint((x1+x2)/2, (y1+y2)/2); } - - int width() const - { return x2 - x1 + 1; } - - int height() const - { return y2 - y1 + 1; } - - QSize size() const - { return QSize(width(), height()); } - - void translate(int dx, int dy) - { - x1 += dx; - y1 += dy; - x2 += dx; - y2 += dy; - } - - void translate(const QPoint p) - { - x1 += p.x(); - y1 += p.y(); - x2 += p.x(); - y2 += p.y(); - } - - QRect translated(int dx, int dy) const - { return QRect(QPoint(x1 + dx, y1 + dy), QPoint(x2 + dx, y2 + dy)); } - - QRect translated(const QPoint p) const - { return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); } - - void moveTo(int ax, int ay) - { - x2 += ax - x1; - y2 += ay - y1; - x1 = ax; - y1 = ay; - } - - void moveTo(const QPoint p) - { - x2 += p.x() - x1; - y2 += p.y() - y1; - x1 = p.x(); - y1 = p.y(); - } - - void moveLeft(int pos) - { x2 += (pos - x1); x1 = pos; } - - void moveTop(int pos) - { y2 += (pos - y1); y1 = pos; } - - void moveRight(int pos) - { - x1 += (pos - x2); - x2 = pos; - } - - void moveBottom(int pos) - { - y1 += (pos - y2); - y2 = pos; - } - - void moveTopLeft(const QPoint p) - { - moveLeft(p.x()); - moveTop(p.y()); - } - - void moveBottomRight(const QPoint p) - { - moveRight(p.x()); - moveBottom(p.y()); - } - - void moveTopRight(const QPoint p) - { - moveRight(p.x()); - moveTop(p.y()); - } - - void moveBottomLeft(const QPoint p) - { - moveLeft(p.x()); - moveBottom(p.y()); - } - - void getRect(int *ax, int *ay, int *aw, int *ah) const - { - *ax = x1; - *ay = y1; - *aw = x2 - x1 + 1; - *ah = y2 - y1 + 1; - } - - void setRect(int ax, int ay, int aw, int ah) - { - x1 = ax; - y1 = ay; - x2 = (ax + aw - 1); - y2 = (ay + ah - 1); - } - - void getCoords(int *xp1, int *yp1, int *xp2, int *yp2) const - { - *xp1 = x1; - *yp1 = y1; - *xp2 = x2; - *yp2 = y2; - } - - void setCoords(int xp1, int yp1, int xp2, int yp2) - { - x1 = xp1; - y1 = yp1; - x2 = xp2; - y2 = yp2; - } - - QRect adjusted(int xp1, int yp1, int xp2, int yp2) const - { return QRect(QPoint(x1 + xp1, y1 + yp1), QPoint(x2 + xp2, y2 + yp2)); } - - void adjust(int dx1, int dy1, int dx2, int dy2) - { - x1 += dx1; - y1 += dy1; - x2 += dx2; - y2 += dy2; - } - - void setWidth(int w) - { x2 = (x1 + w - 1); } - - void setHeight(int h) - { y2 = (y1 + h - 1); } - - void setSize(const QSize s) - { - x2 = (s.width() + x1 - 1); - y2 = (s.height() + y1 - 1); - } - - bool contains(int ax, int ay, bool aproper) const - { - return contains(QPoint(ax, ay), aproper); - } - - bool contains(int ax, int ay) const - { - return contains(QPoint(ax, ay), false); - } - - QRect opOrAssign(const QRect r) - { - this = this | r; - return this; - } - - QRect opAndAssign(const QRect r) - { - this = this & r; - return this; - } - - QRect intersected(const QRect other) const - { - return this & other; - } - - QRect united(const QRect r) const - { - return this | r; - } - - bool opEquals(ref const QRect r) const - { - return x1==r.x1 && x2==r.x2 && y1==r.y1 && y2==r.y2; - } - - public final void writeTo(QDataStream arg__1) { - qtd_QRect_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final void readFrom(QDataStream arg__1) { - qtd_QRect_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final QRect opAnd(const QRect r) const { - return qtd_QRect_operator_and_QRect(&this, &r); - } - - public final QRect opOr(const QRect r) const { - return qtd_QRect_operator_or_QRect(&this, &r); - } - - public final bool contains(const QPoint p, bool proper = false) const { - return qtd_QRect_contains_QPoint_bool(&this, &p, proper); - } - - public final bool contains(const QRect r, bool proper = false) const { - return qtd_QRect_contains_QRect_bool(&this, &r, proper); - } - - public final bool intersects(const QRect r) const { - return qtd_QRect_intersects_QRect(&this, &r); - } - - public final QRect normalized() const { - return qtd_QRect_normalized(&this); - } - - // service stuff - public alias void __isNativeValueType; - - struct QTypeInfo - { - enum bool isComplex = true; - enum bool isStatic = false; - enum bool isLarge = true; - enum bool isPointer = false; - enum bool isDummy = false; - } - - -private: - version(OSX) - { - int y1; - int x1; - int y2; - int x2; - } - else - { - int x1; - int y1; - int x2; - int y2; - } -} - - -// C wrappers -private extern(C) bool qtd_QRect_contains_QPoint_bool(const void* __this_nativeId, - const void* p0, - bool proper1); -private extern(C) bool qtd_QRect_contains_QRect_bool(const void* __this_nativeId, - const void* r0, - bool proper1); -private extern(C) bool qtd_QRect_intersects_QRect(const void* __this_nativeId, - const void* r0); -private extern(C) QRect qtd_QRect_normalized(const void* __this_nativeId); -private extern(C) void qtd_QRect_writeTo_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void qtd_QRect_readFrom_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) QRect qtd_QRect_operator_and_QRect(const void* __this_nativeId, - const void* r0); -private extern(C) QRect qtd_QRect_operator_or_QRect(const void* __this_nativeId, - const void* r0); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d2/qt/core/QRectF.d --- a/qt/d2/qt/core/QRectF.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,340 +0,0 @@ -module qt.core.QRectF; - -public import qt.QGlobal; -public import qt.core.Qt; -public import qt.core.QPointF; -public import qt.core.QRect; -public import qt.core.QSizeF; -public import qt.core.QDataStream; - - -public struct QRectF -{ - public static QRectF opCall() - { - QRectF rt; - rt.xp = rt.yp = 0.; - rt.w = rt.h = 0.; - return rt; - } - - public this(qreal aleft, qreal atop, qreal awidth, qreal aheight) - { - xp = aleft; - yp = atop; - w = awidth; - h = aheight; - } - - public this(QPointF atopLeft, QSizeF asize) - { - xp = atopLeft.x(); - yp = atopLeft.y(); - w = asize.width(); - h = asize.height(); - } - - public this(QPointF atopLeft, QPointF abottomRight) - { - xp = atopLeft.x(); - yp = atopLeft.y(); - w = abottomRight.x() - xp; - h = abottomRight.y() - yp; - } - - public this(QRect r) - { - xp = r.x(); - yp = r.y(); - w = r.width(); - h = r.height(); - } - - bool isNull() const - { return qIsNull(w) && qIsNull(h); } - - bool isEmpty() const - { return w <= 0. || h <= 0.; } - - bool isValid() const - { return w > 0. && h > 0.; } - - qreal x() const - { return xp; } - - qreal y() const - { return yp; } - - qreal left() const - { return xp; } - - qreal top() const - { return yp; } - - qreal right() const - { return xp + w; } - - qreal bottom() const - { return yp + h; } - - QPointF topLeft() const - { return QPointF(xp, yp); } - - QPointF bottomRight() const - { return QPointF(xp+w, yp+h); } - - QPointF topRight() const - { return QPointF(xp+w, yp); } - - QPointF bottomLeft() const - { return QPointF(xp, yp+h); } - - void setLeft(qreal pos) { qreal diff = pos - xp; xp += diff; w -= diff; } - - void setRight(qreal pos) { w = pos - xp; } - - void setTop(qreal pos) { qreal diff = pos - yp; yp += diff; h -= diff; } - - void setBottom(qreal pos) { h = pos - yp; } - - void setTopLeft(ref QPointF p) { setLeft(p.x()); setTop(p.y()); } - - void setTopRight(ref QPointF p) { setRight(p.x()); setTop(p.y()); } - - void setBottomLeft(ref QPointF p) { setLeft(p.x()); setBottom(p.y()); } - - void setBottomRight(ref QPointF p) { setRight(p.x()); setBottom(p.y()); } - - QPointF center() const - { return QPointF(xp + w/2, yp + h/2); } - - void moveLeft(qreal pos) { xp = pos; } - - void moveTop(qreal pos) { yp = pos; } - - void moveRight(qreal pos) { xp = pos - w; } - - void moveBottom(qreal pos) { yp = pos - h; } - - void moveTopLeft(ref QPointF p) { moveLeft(p.x()); moveTop(p.y()); } - - void moveTopRight(ref QPointF p) { moveRight(p.x()); moveTop(p.y()); } - - void moveBottomLeft(ref QPointF p) { moveLeft(p.x()); moveBottom(p.y()); } - - void moveBottomRight(ref QPointF p) { moveRight(p.x()); moveBottom(p.y()); } - - void moveCenter(ref QPointF p) { xp = p.x() - w/2; yp = p.y() - h/2; } - - qreal width() const - { return w; } - - qreal height() const - { return h; } - - QSizeF size() const - { return QSizeF(w, h); } - - void translate(qreal dx, qreal dy) - { - xp += dx; - yp += dy; - } - - void translate(ref QPointF p) - { - xp += p.x(); - yp += p.y(); - } - - void moveTo(qreal ax, qreal ay) - { - xp = ax; - yp = ay; - } - - void moveTo(ref QPointF p) - { - xp = p.x(); - yp = p.y(); - } - - QRectF translated(qreal dx, qreal dy) const - { return QRectF(xp + dx, yp + dy, w, h); } - - QRectF translated(ref QPointF p) const - { return QRectF(xp + p.x(), yp + p.y(), w, h); } - - void getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const - { - *ax = this.xp; - *ay = this.yp; - *aaw = this.w; - *aah = this.h; - } - - void setRect(qreal ax, qreal ay, qreal aaw, qreal aah) - { - this.xp = ax; - this.yp = ay; - this.w = aaw; - this.h = aah; - } - - void getCoords(qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2) const - { - *xp1 = xp; - *yp1 = yp; - *xp2 = xp + w; - *yp2 = yp + h; - } - - void setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2) - { - xp = xp1; - yp = yp1; - w = xp2 - xp1; - h = yp2 - yp1; - } - - void adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2) - { xp += xp1; yp += yp1; w += xp2 - xp1; h += yp2 - yp1; } - - QRectF adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const - { return QRectF(xp + xp1, yp + yp1, w + xp2 - xp1, h + yp2 - yp1); } - - void setWidth(qreal aw) // for convenience - { this.w = aw; } - - void setHeight(qreal ah) // for convenience - { this.h = ah; } - - void setSize(ref QSizeF s) // for convenience - { - w = s.width(); - h = s.height(); - } - - void width(qreal aw) - { this.w = aw; } - - void height(qreal ah) - { this.h = ah; } - - void size(ref QSizeF s) - { - w = s.width(); - h = s.height(); - } - - bool contains(qreal ax, qreal ay) const - { - return contains(QPointF(ax, ay)); - } - - QRectF opOrAssign(ref QRectF r) - { - this = this | r; - return this; - } - - QRectF opAndAssign(ref QRectF r) - { - this = this & r; - return this; - } - - QRectF intersected(ref QRectF r) const - { - return this & r; - } - - QRectF united(ref QRectF r) const - { - return this | r; - } - - bool opEquals(ref const QRectF r) const - { - return qFuzzyCompare(xp, r.xp) && qFuzzyCompare(yp, r.yp) - && qFuzzyCompare(w, r.w) && qFuzzyCompare(h, r.h); - } - - QRect toRect() const - { - return QRect(qRound(xp), qRound(yp), qRound(w), qRound(h)); - } - - public final bool contains(QPointF p) const { - return qtd_QRectF_contains_QPointF(cast(void*)&this, &p); - } - - public final bool contains(QRectF r) const { - return qtd_QRectF_contains_QRectF(cast(void*)&this, &r); - } - - public final bool intersects(QRectF r) const { - return qtd_QRectF_intersects_QRectF(cast(void*)&this, &r); - } - - public final QRectF normalized() const { - return qtd_QRectF_normalized(cast(void*)&this); - } - - public final QRectF opAnd(ref QRectF r) const { - return qtd_QRectF_operator_and_QRectF(cast(void*)&this, &r); - } - - public final void writeTo(QDataStream arg__1) { - qtd_QRectF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final void readFrom(QDataStream arg__1) { - qtd_QRectF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); - } - - public final QRectF opOr(ref QRectF r) const { - return qtd_QRectF_operator_or_QRectF(cast(void*)&this, &r); - } - - public final QRect toAlignedRect() const - { - return qtd_QRectF_toAlignedRect(cast(void*)&this); - } - - // service stuff - public alias void __isNativeValueType; - - struct QTypeInfo - { - enum bool isComplex = true; - enum bool isStatic = false; - enum bool isLarge = true; - enum bool isPointer = false; - enum bool isDummy = false; - } -private: - qreal xp; - qreal yp; - qreal w; - qreal h; -} - - -// C wrappers -private extern(C) bool qtd_QRectF_contains_QPointF(void* __this_nativeId, - void* p0); -private extern(C) bool qtd_QRectF_contains_QRectF(void* __this_nativeId, - void* r0); -private extern(C) bool qtd_QRectF_intersects_QRectF(void* __this_nativeId, - void* r0); -private extern(C) QRectF qtd_QRectF_normalized(void* __this_nativeId); -private extern(C) QRectF qtd_QRectF_operator_and_QRectF(void* __this_nativeId, - void* r0); -private extern(C) void qtd_QRectF_writeTo_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void qtd_QRectF_readFrom_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) QRectF qtd_QRectF_operator_or_QRectF(void* __this_nativeId, - void* r0); -private extern(C) QRect qtd_QRectF_toAlignedRect(void* __this_nativeId); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d2/qt/core/QSize.d --- a/qt/d2/qt/core/QSize.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,297 +0,0 @@ -module qt.core.QSize; - -public import qt.QGlobal; -public import qt.core.Qt; - - -public struct QSize -{ -/* ctors, reserved for D2 - public this() - { wd = ht = -1; } - - public this(int w, int h) - { wd = w; ht = h; } -*/ - - public static QSize opCall() { - QSize sz; - sz.wd = sz.ht = -1; - return sz; - } - - public this(int w, int h) { - wd = w; - ht = h; - } - - final bool isNull() - { return wd==0 && ht==0; } - - final bool isEmpty() - { return wd<1 || ht<1; } - - final bool isValid() - { return wd>=0 && ht>=0; } - - final int width() const - { return wd; } - - final int height() const - { return ht; } - - final void width(int w) - { wd = w; } - - final void height(int h) - { ht = h; } - - final void setWidth(int w) // for convenience - { wd = w; } - - final void setHeight(int h) // for convenience - { ht = h; } - - void transpose() { - int tmp = wd; - wd = ht; - ht = tmp; - } - - void scale(int w, int h, Qt.AspectRatioMode mode) { - scale(QSize(w, h), mode); - } - - void scale(ref QSize s, Qt.AspectRatioMode mode) { - __qtd_QSize_scale_QSize_AspectRatioMode(&this, &s, mode); - } - - QSize expandedTo(ref QSize otherSize) { - return QSize(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht)); - } - - QSize boundedTo(ref QSize otherSize) { - return QSize(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht)); - } -/* - public final void writeTo(QDataStream arg__1) { - __qtd_QSize_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.nativeId); - } - - public final void readFrom(QDataStream arg__1) { - __qtd_QSize_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.nativeId); - } -*/ - QSize opAddAssign(ref QSize s) - { wd+=s.wd; ht+=s.ht; return this; } - - QSize opSubAssign(ref QSize s) - { wd-=s.wd; ht-=s.ht; return this; } - - QSize opMulAssign(qreal c) - { wd = qRound(wd*c); ht = qRound(ht*c); return this; } - - bool opEquals(ref const QSize s) const - { return wd == s.wd && ht == s.ht; } - - QSize opAdd(ref QSize s) - { return QSize(this.wd+s.wd, this.ht+s.ht); } - - QSize opSub(ref QSize s) - { return QSize(this.wd-s.wd, this.ht-s.ht); } - - QSize opMul(qreal c) - { return QSize(qRound(this.wd*c), qRound(this.ht*c)); } - - QSize opDivAssign(qreal c) { - assert(!qFuzzyCompare(c + 1, 1.)); - wd = qRound(wd/c); ht = qRound(ht/c); - return this; - } - - QSize opDiv(qreal c) { - assert(!qFuzzyCompare(c + 1, 1.)); - return QSize(qRound(this.wd/c), qRound(this.ht/c)); - } - - // service stuff - public alias void __isNativeValueType; - - struct QTypeInfo - { - enum bool isComplex = true; - enum bool isStatic = false; - enum bool isLarge = true; - enum bool isPointer = false; - enum bool isDummy = false; - } -private: - int wd; - int ht; -} - - -public struct QSizeF -{ -/* ctors, reserved for D2 - this() - { wd = ht = -1.; } - - this(ref QSize sz) - { wd = sz.width(); ht = sz.height(); } - - this(qreal w, qreal h) - { wd = w; ht = h; } -*/ - public static QSizeF opCall() { - QSizeF sz; - sz.wd = sz.ht = -1.; - return sz; - } - - public static QSizeF opCall(ref QSizeF s) { - QSizeF sz; - sz.wd = s.width(); sz.ht = s.height(); - return sz; - } - - public static QSizeF opCall(qreal w, qreal h) { - QSizeF sz; - sz.wd = w; sz.ht = h; - return sz; - } - - bool isNull() - { return qIsNull(wd) && qIsNull(ht); } - - bool isEmpty() - { return wd <= 0. || ht <= 0.; } - - bool isValid() - { return wd >= 0. && ht >= 0.; } - - qreal width() - { return wd; } - - qreal height() - { return ht; } - - void width(qreal w) - { wd = w; } - - void height(qreal h) - { ht = h; } - - void setWidth(qreal w) - { wd = w; } - - void setHeight(qreal h) - { ht = h; } - - void scale(qreal w, qreal h, Qt.AspectRatioMode mode) - { scale(QSizeF(w, h), mode); } - - public final void scale(QSizeF s, Qt.AspectRatioMode mode) - { __qtd_QSizeF_scale_QSizeF_AspectRatioMode(&this, &s, mode); } - - void transpose() { - qreal tmp = wd; - wd = ht; - ht = tmp; - } - - QSizeF expandedTo(ref QSizeF otherSize) - { return QSizeF(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht)); } - - QSizeF boundedTo(ref QSizeF otherSize) - { return QSizeF(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht)); } - - QSize toSize() - { return QSize(qRound(wd), qRound(ht)); } -/* - public final void writeTo(QDataStream arg__1) { - __qtd_QSizeF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.nativeId); - } - - public final void readFrom(QDataStream arg__1) { - __qtd_QSizeF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.nativeId); -*/ - QSizeF opAddAssign(ref QSizeF s) - { wd += s.wd; ht += s.ht; return this; } - - QSizeF opSubAssign(ref QSizeF s) - { wd -= s.wd; ht -= s.ht; return this; } - - QSizeF opMulAssign(qreal c) - { wd *= c; ht *= c; return this; } - - bool opEquals(ref const QSizeF s) const - { return qFuzzyCompare(wd, s.wd) && qFuzzyCompare(ht, s.ht); } - - QSizeF opAdd(ref QSizeF s) - { return QSizeF(this.wd+s.wd, this.ht+s.ht); } - - QSizeF opSub(ref QSizeF s) - { return QSizeF(this.wd-s.wd, this.ht-s.ht); } - - QSizeF opMul(qreal c) - { return QSizeF(this.wd*c, this.ht*c); } - - QSizeF opDivAssign(qreal c) - { - assert(!qFuzzyCompare(c + 1, 1.)); - wd = wd/c; ht = ht/c; - return this; - } - - QSizeF opDiv(qreal c) - { - assert(!qFuzzyCompare(c + 1, 1.)); - return QSizeF(this.wd/c, this.ht/c); - } - - // service stuff - public alias void __isNativeValueType; - - struct QTypeInfo - { - enum bool isComplex = true; - enum bool isStatic = false; - enum bool isLarge = true; - enum bool isPointer = false; - enum bool isDummy = false; - } -private: - qreal wd; - qreal ht; -} - - -extern (C) void qtd_append_array_QSize(QSize[]* arr, QSize arg) -{ - *arr ~= arg; -} - -extern (C) void qtd_append_array_QSizeF(QSizeF[]* arr, QSizeF arg) -{ - *arr ~= arg; -} - -// C wrappers -// QSize -private extern(C) void __qtd_QSize_scale_QSize_AspectRatioMode(void* __this_nativeId, - void* s0, - int mode1); -private extern(C) void __qtd_QSize_writeTo_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void __qtd_QSize_readFrom_QDataStream(void* __this_nativeId, - void* arg__1); - -// QSizeF -private extern(C) void __qtd_QSizeF_writeTo_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void __qtd_QSizeF_readFrom_QDataStream(void* __this_nativeId, - void* arg__1); -private extern(C) void __qtd_QSizeF_scale_QSizeF_AspectRatioMode(void* __this_nativeId, - void* s0, - int mode1); \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d2/qt/core/QSizeF.d --- a/qt/d2/qt/core/QSizeF.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -module qt.core.QSizeF; -/* dummy */ - -public import qt.core.QSize; diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d2/qt/core/QVariant.d --- a/qt/d2/qt/core/QVariant.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,741 +0,0 @@ -module qt.core.QVariant; - -public import qt.QGlobal; -private import qt.QtdObject; -private import qt.core.QMetaType; - -// automatic imports------------- -private import qt.core.QSizeF; -private import qt.core.QPoint; -private import qt.core.QRectF; -public import qt.core.Qt; -private import qt.core.QDateTime; -private import qt.core.QDataStream; -private import qt.core.QTime; -private import qt.core.QUrl; -private import qt.core.QRegExp; -private import qt.core.QBitArray; -private import qt.core.QLine; -private import qt.core.QByteArray; -private import qt.core.QSize; -private import qt.core.QDate; -private import qt.core.QPointF; -private import qt.core.QLineF; -private import qt.core.QRect; -private import qt.core.QLocale; - -import std.string; - - -public class QVariant : QtdObject -{ - enum Type { - Invalid = 0, - - Bool = 1, - Int = 2, - UInt = 3, - LongLong = 4, - ULongLong = 5, - Double = 6, - Char = 7, - Map = 8, - List = 9, - String = 10, - StringList = 11, - ByteArray = 12, - BitArray = 13, - Date = 14, - Time = 15, - DateTime = 16, - Url = 17, - Locale = 18, - Rect = 19, - RectF = 20, - Size = 21, - SizeF = 22, - Line = 23, - LineF = 24, - Point = 25, - PointF = 26, - RegExp = 27, - LastCoreType = RegExp, - - // value 62 is internally reserved - - Font = 64, - Pixmap = 65, - Brush = 66, - Color = 67, - Palette = 68, - Icon = 69, - Image = 70, - Polygon = 71, - Region = 72, - Bitmap = 73, - Cursor = 74, - SizePolicy = 75, - KeySequence = 76, - Pen = 77, - TextLength = 78, - TextFormat = 79, - Matrix = 80, - Transform = 81, - LastGuiType = Transform, - - UserType = 127, - - LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type - } - -// Functions - - private template getMetaId() - { - const char[] getMetaId = " - int i = qtd_MetatypeId(toStringz(name)); - if(i <= 0) - i = qRegisterMetaType!(T)(name);"; - } - - static public QVariant fromValue(T)(T obj) - { - QVariant var; - static if (is(T == class) || is(T == interface)) - { - string name = obj.classinfo.name; - mixin(getMetaId!()); - var = new QVariant(i, cast(void*)(obj)); - } - else static if (isDynamicArrayType!(T) || isStaticArrayType!(T) ) - { - string name = typeid(ElementTypeOfArray!(T)).toString ~ "[]"; - mixin(getMetaId!()); - auto darray = new DArrayToC; - darray.array = obj.dup; - var = new QVariant(i, cast(void*)(darray)); - } - else - { - string name = typeid(T).toString; - mixin(getMetaId!()); - auto data = new T; - *data = obj; - var = new QVariant(i, cast(void*)(data)); - } - return var; - } - - static public QVariant opCall(T)(T obj) - { - return fromValue(obj); - } - - public this() { - void* __qt_return_value = qtd_QVariant_QVariant(); - super(__qt_return_value); - } - - - public this(QDataStream s) { - void* __qt_return_value = qtd_QVariant_QVariant_QDataStream(s is null ? null : s.__nativeId); - super(__qt_return_value); - } - - - public this(Qt.GlobalColor color) { - void* __qt_return_value = qtd_QVariant_QVariant_GlobalColor(color); - super(__qt_return_value); - } - - - public this(bool b) { - void* __qt_return_value = qtd_QVariant_QVariant_bool(b); - super(__qt_return_value); - } - - - public this(QBitArray bitarray) { - void* __qt_return_value = qtd_QVariant_QVariant_QBitArray(bitarray is null ? null : bitarray.__nativeId); - super(__qt_return_value); - } - - - public this(QByteArray bytearray) { - void* __qt_return_value = qtd_QVariant_QVariant_QByteArray(bytearray is null ? null : bytearray.__nativeId); - super(__qt_return_value); - } - - - public this(QDate date) { - void* __qt_return_value = qtd_QVariant_QVariant_QDate(date is null ? null : date.__nativeId); - super(__qt_return_value); - } - - - public this(QDateTime datetime) { - void* __qt_return_value = qtd_QVariant_QVariant_QDateTime(datetime is null ? null : datetime.__nativeId); - super(__qt_return_value); - } - - - public this(string str) { - void* __qt_return_value = qtd_QVariant_QVariant_String(str); - super(__qt_return_value); - } - - - public this(QLine line) { - void* __qt_return_value = qtd_QVariant_QVariant_QLine(&line); - super(__qt_return_value); - } - - - public this(QLineF line) { - void* __qt_return_value = qtd_QVariant_QVariant_QLineF(&line); - super(__qt_return_value); - } - - - public this(QLocale locale) { - void* __qt_return_value = qtd_QVariant_QVariant_QLocale(locale is null ? null : locale.__nativeId); - super(__qt_return_value); - } - - - public this(QPoint pt) { - void* __qt_return_value = qtd_QVariant_QVariant_QPoint(&pt); - super(__qt_return_value); - } - - - public this(QPointF pt) { - void* __qt_return_value = qtd_QVariant_QVariant_QPointF(&pt); - super(__qt_return_value); - } - - - public this(QRect rect) { - void* __qt_return_value = qtd_QVariant_QVariant_QRect(&rect); - super(__qt_return_value); - } - - - public this(QRectF rect) { - void* __qt_return_value = qtd_QVariant_QVariant_QRectF(&rect); - super(__qt_return_value); - } - - - public this(QRegExp regExp) { - void* __qt_return_value = qtd_QVariant_QVariant_QRegExp(regExp is null ? null : regExp.__nativeId); - super(__qt_return_value); - } - - - public this(QSize size) { - void* __qt_return_value = qtd_QVariant_QVariant_QSize(&size); - super(__qt_return_value); - } - - - public this(QSizeF size) { - void* __qt_return_value = qtd_QVariant_QVariant_QSizeF(&size); - super(__qt_return_value); - } - - - public this(QTime time) { - void* __qt_return_value = qtd_QVariant_QVariant_QTime(time is null ? null : time.__nativeId); - super(__qt_return_value); - } - - - public this(QUrl url) { - void* __qt_return_value = qtd_QVariant_QVariant_QUrl(url is null ? null : url.__nativeId); - super(__qt_return_value); - } - - - public this(QVariant other) { - void* __qt_return_value = qtd_QVariant_QVariant_QVariant(other is null ? null : other.__nativeId); - super(__qt_return_value); - } - -/* - public this(char* str) { - void* __qt_return_value = qtd_QVariant_QVariant_nativepointerchar(str); - super(__qt_return_value); - } -*/ - - public this(double d) { - void* __qt_return_value = qtd_QVariant_QVariant_double(d); - super(__qt_return_value); - } - - - public this(int i) { - void* __qt_return_value = qtd_QVariant_QVariant_int(i); - super(__qt_return_value); - } - - - public this(int typeOrUserType, void* copy) { - void* __qt_return_value = qtd_QVariant_QVariant_int_nativepointervoid(typeOrUserType, copy); - super(__qt_return_value); - } - - - public this(long ll) { - void* __qt_return_value = qtd_QVariant_QVariant_long(ll); - super(__qt_return_value); - } - - - public this(uint ui) { - void* __qt_return_value = qtd_QVariant_QVariant_uint(ui); - super(__qt_return_value); - } - - - public this(ulong ull) { - void* __qt_return_value = qtd_QVariant_QVariant_ulong(ull); - super(__qt_return_value); - } - - private final bool canConvertImpl(string name) - { - int i = qtd_MetatypeId(toStringz(name)); - assert(i > 0); - return qtd_QVariant_canConvert(__nativeId, i); - } - - public final bool canConvert(Type)() { - static if ( is(Type == QBitArray) ) - return canConvertImpl("QBitArray"); - else static if ( is(Type == bool) ) - return canConvertImpl("bool"); - else static if ( is(Type == QByteArray) ) - return canConvertImpl("QByteArray"); - else static if ( is(Type == QDate) ) - return canConvertImpl("QDate"); - else static if ( is(Type == QDateTime) ) - return canConvertImpl("QDateTime"); - else static if ( is(Type == double) ) - return canConvertImpl("double"); - else static if ( is(Type == int) ) - return canConvertImpl("int"); - else static if ( is(Type == QLine) ) - return canConvertImpl("QLine"); - else static if ( is(Type == QLineF) ) - return canConvertImpl("QLineF"); - else static if ( is(Type == QLocale) ) - return canConvertImpl("QLocale"); - else static if ( is(Type == long) ) - return canConvertImpl("long"); - else static if ( is(Type == QPoint) ) - return canConvertImpl("QPoint"); - else static if ( is(Type == QPointF) ) - return canConvertImpl("QPointF"); - else static if ( is(Type == QRect) ) - return canConvertImpl("QRect"); - else static if ( is(Type == QRectF) ) - return canConvertImpl("QRectF"); - else static if ( is(Type == QRegExp) ) - return canConvertImpl("QRegExp"); - else static if ( is(Type == QSize) ) - return canConvertImpl("QSize"); - else static if ( is(Type == QSizeF) ) - return canConvertImpl("QSizeF"); - else static if ( is(Type == string) ) - return canConvertImpl("QString"); - else static if ( is(Type == QTime) ) - return canConvertImpl("QTime"); - else static if ( is(Type == uint) ) - return canConvertImpl("unsigned int"); // TODO: - else static if ( is(Type == ulong) ) - return canConvertImpl("unsigned long long"); // TODO: - else static if ( is(Type == QUrl) ) - return canConvertImpl("QUrl"); - else - { - static if( is( Type == class ) || is( Type == interface ) ) - { - Object object = cast(Object)qtd_QVariant_data(__nativeId); - if(object) - return cast(Type)(object) !is null; - return false; - } - else static if (isDynamicArrayType!(Type) || isStaticArrayType!(Type) ) - { - auto array = cast(DArrayToC*)qtd_QVariant_data(__nativeId); - return cast(Type)(array.array) !is null; - } - else - { - int i = qtd_MetatypeId(toStringz(typeid(Type).toString)); - return qtd_QVariant_canConvert(__nativeId, i); - } - } - } - - public final Type value(Type)() { - static if ( is(Type == QBitArray) ) - return toBitArra; - else static if ( is(Type == bool) ) - return toBool; - else static if ( is(Type == QByteArray) ) - return toByteArray; - else static if ( is(Type == QDate) ) - return toDate; - else static if ( is(Type == QDateTime) ) - return toDateTime; - else static if ( is(Type == double) ) - return toDouble; - else static if ( is(Type == int) ) - return toInt; - else static if ( is(Type == QLine) ) - return toLine; - else static if ( is(Type == QLineF) ) - return toLineF; - else static if ( is(Type == QLocale) ) - return toLocale; - else static if ( is(Type == long) ) - return toLongLong; - else static if ( is(Type == QPoint) ) - return toPoint; - else static if ( is(Type == QPointF) ) - return toPointF; - else static if ( is(Type == QRect) ) - return toRect; - else static if ( is(Type == QRectF) ) - return toRectF; - else static if ( is(Type == QRegExp) ) - return toRegExp; - else static if ( is(Type == QSize) ) - return toSize; - else static if ( is(Type == QSizeF) ) - return toSizeF; - else static if ( is(Type == string) ) - return toString; - else static if ( is(Type == QTime) ) - return toTime; - else static if ( is(Type == uint) ) - return toUInt; - else static if ( is(Type == ulong) ) - return toULongLong; - else static if ( is(Type == QUrl) ) - return toUrl; - else static if( is( Type == class ) || is( Type == interface ) ) - { - Object object = cast(Object)qtd_QVariant_data(__nativeId); - if(object) - return cast(Type)(object); - return null; - } - else static if (isDynamicArrayType!(Type) || isStaticArrayType!(Type) ) - { - auto array = cast(DArrayToC*)qtd_QVariant_data(__nativeId); - return cast(Type)(array.array); - } - else - { - return *cast(Type*)qtd_QVariant_data(__nativeId); - } - } - - public final void clear() { - qtd_QVariant_clear(__nativeId); - } - - protected final bool cmp(QVariant other) { - return qtd_QVariant_cmp_QVariant(__nativeId, other is null ? null : other.__nativeId); - } - - protected final void create(int type, void* copy) { - qtd_QVariant_create_int_nativepointervoid(__nativeId, type, copy); - } - - public final bool isNull() { - return qtd_QVariant_isNull(__nativeId); - } - - public final bool isValid() { - return qtd_QVariant_isValid(__nativeId); - } - - public final void load(QDataStream ds) { - qtd_QVariant_load_QDataStream(__nativeId, ds is null ? null : ds.__nativeId); - } - - public final void writeTo(QDataStream s) { - qtd_QVariant_writeTo_QDataStream(__nativeId, s is null ? null : s.__nativeId); - } - - public final QVariant operator_assign(QVariant other) { - void* __qt_return_value = qtd_QVariant_operator_assign_QVariant(__nativeId, other is null ? null : other.__nativeId); - return new QVariant(__qt_return_value, QtdObjectFlags.nativeOwnership); - } - - private final bool operator_equal(QVariant v) { - return qtd_QVariant_operator_equal_QVariant(__nativeId, v is null ? null : v.__nativeId); - } - - public final void readFrom(QDataStream s) { - qtd_QVariant_readFrom_QDataStream(__nativeId, s is null ? null : s.__nativeId); - } - - public final void save(QDataStream ds) { - qtd_QVariant_save_QDataStream(__nativeId, ds is null ? null : ds.__nativeId); - } - - public final QBitArray toBitArray() { - void* __qt_return_value = qtd_QVariant_toBitArray(__nativeId); - return new QBitArray(__qt_return_value); - } - - public final bool toBool() { - return qtd_QVariant_toBool(__nativeId); - } - - public final QByteArray toByteArray() { - void* __qt_return_value = qtd_QVariant_toByteArray(__nativeId); - return new QByteArray(__qt_return_value); - } - - public final QDate toDate() { - void* __qt_return_value = qtd_QVariant_toDate(__nativeId); - return new QDate(__qt_return_value); - } - - public final QDateTime toDateTime() { - void* __qt_return_value = qtd_QVariant_toDateTime(__nativeId); - return new QDateTime(__qt_return_value); - } - - public final double toDouble(bool* ok = null) { - return qtd_QVariant_toDouble_nativepointerbool(__nativeId, ok); - } - - public final int toInt(bool* ok = null) { - return qtd_QVariant_toInt_nativepointerbool(__nativeId, ok); - } - - public final QLine toLine() { - return qtd_QVariant_toLine(__nativeId); - } - - public final QLineF toLineF() { - return qtd_QVariant_toLineF(__nativeId); - } - - public final QLocale toLocale() { - void* __qt_return_value = qtd_QVariant_toLocale(__nativeId); - return new QLocale(__qt_return_value); - } - - public final long toLongLong(bool* ok = null) { - return qtd_QVariant_toLongLong_nativepointerbool(__nativeId, ok); - } - - public final QPoint toPoint() { - return qtd_QVariant_toPoint(__nativeId); - } - - public final QPointF toPointF() { - return qtd_QVariant_toPointF(__nativeId); - } - - public final QRect toRect() { - return qtd_QVariant_toRect(__nativeId); - } - - public final QRectF toRectF() { - return qtd_QVariant_toRectF(__nativeId); - } - - public final QRegExp toRegExp() { - void* __qt_return_value = qtd_QVariant_toRegExp(__nativeId); - return new QRegExp(__qt_return_value); - } - - public final QSize toSize() { - return qtd_QVariant_toSize(__nativeId); - } - - public final QSizeF toSizeF() { - return qtd_QVariant_toSizeF(__nativeId); - } - - public final string toString() { - string res; - qtd_QVariant_toString(__nativeId, &res); - return res; - } - - public final QTime toTime() { - void* __qt_return_value = qtd_QVariant_toTime(__nativeId); - return new QTime(__qt_return_value); - } - - public final uint toUInt(bool* ok = null) { - return qtd_QVariant_toUInt_nativepointerbool(__nativeId, ok); - } - - public final ulong toULongLong(bool* ok = null) { - return qtd_QVariant_toULongLong_nativepointerbool(__nativeId, ok); - } - - public final QUrl toUrl() { - void* __qt_return_value = qtd_QVariant_toUrl(__nativeId); - return new QUrl(__qt_return_value); - } - - public final char* typeName() { - return qtd_QVariant_typeName(__nativeId); - } - - public final Type type() { - return cast(Type)qtd_QVariant_type(__nativeId); - } - - public final int userType() { - return qtd_QVariant_userType(__nativeId); - } -// Field accessors - - public this(void* native_id, QtdObjectFlags flags = QtdObjectFlags.none) { - super(native_id, flags); - } - - protected override void __deleteNative() { - qtd_QVariant_destructor(__nativeId); - } - - public alias void __isValueType; - - public alias void __isQtType_QVariant; - - struct QTypeInfo - { - enum bool isComplex = true; - enum bool isStatic = false; - enum bool isLarge = true; - enum bool isPointer = false; - enum bool isDummy = false; - } - - static void* __constructNativeCopy(const void* orig) { - return qtd_QVariant_QVariant_QVariant(cast(void*)orig); - } - - static void* __constructPlacedNativeCopy(const void* orig, void* place) { - return qtd_QVariant_placed_copy(orig, place); - } - - public static void __deleteNativeObject(void* ptr) { - qtd_QVariant_destructor(ptr); - } - - public static void __callNativeDestructor(void* ptr) { - qtd_QVariant_call_destructor(ptr); - } -// Injected code in class -} - -extern (C) void qtd_QVariant_destructor(void *ptr); -extern (C) void qtd_QVariant_call_destructor(void *ptr); - -private extern(C) void* qtd_QVariant_placed_copy(const void* orig, void* place); - - -// C wrappers -private extern(C) void* qtd_QVariant_QVariant(); -private extern(C) void* qtd_QVariant_QVariant_QDataStream(void* s0); -private extern(C) void* qtd_QVariant_QVariant_GlobalColor(int color0); -private extern(C) void* qtd_QVariant_QVariant_bool(bool b0); -private extern(C) void* qtd_QVariant_QVariant_QBitArray(void* bitarray0); -private extern(C) void* qtd_QVariant_QVariant_QByteArray(void* bytearray0); -private extern(C) void* qtd_QVariant_QVariant_QDate(void* date0); -private extern(C) void* qtd_QVariant_QVariant_QDateTime(void* datetime0); -private extern(C) void* qtd_QVariant_QVariant_String(string string0); -private extern(C) void* qtd_QVariant_QVariant_QLine(void* line0); -private extern(C) void* qtd_QVariant_QVariant_QLineF(void* line0); -private extern(C) void* qtd_QVariant_QVariant_QLocale(void* locale0); -private extern(C) void* qtd_QVariant_QVariant_QPoint(void* pt0); -private extern(C) void* qtd_QVariant_QVariant_QPointF(void* pt0); -private extern(C) void* qtd_QVariant_QVariant_QRect(void* rect0); -private extern(C) void* qtd_QVariant_QVariant_QRectF(void* rect0); -private extern(C) void* qtd_QVariant_QVariant_QRegExp(void* regExp0); -private extern(C) void* qtd_QVariant_QVariant_QSize(void* size0); -private extern(C) void* qtd_QVariant_QVariant_QSizeF(void* size0); -private extern(C) void* qtd_QVariant_QVariant_QTime(void* time0); -private extern(C) void* qtd_QVariant_QVariant_QUrl(void* url0); -private extern(C) void* qtd_QVariant_QVariant_QVariant(void* other0); -private extern(C) void* qtd_QVariant_QVariant_nativepointerchar(char* str0); -private extern(C) void* qtd_QVariant_QVariant_double(double d0); -private extern(C) void* qtd_QVariant_QVariant_int(int i0); -private extern(C) void* qtd_QVariant_QVariant_int_nativepointervoid(int typeOrUserType0, - void* copy1); -private extern(C) void* qtd_QVariant_QVariant_long(long ll0); -private extern(C) void* qtd_QVariant_QVariant_uint(uint ui0); -private extern(C) void* qtd_QVariant_QVariant_ulong(ulong ull0); -private extern(C) bool qtd_QVariant_canConvert(void* __this_nativeId, int); -private extern(C) void qtd_QVariant_clear(void* __this_nativeId); -private extern(C) bool qtd_QVariant_cmp_QVariant(void* __this_nativeId, - void* other0); -private extern(C) void qtd_QVariant_create_int_nativepointervoid(void* __this_nativeId, - int type0, - void* copy1); -private extern(C) bool qtd_QVariant_isNull(void* __this_nativeId); -private extern(C) bool qtd_QVariant_isValid(void* __this_nativeId); -private extern(C) void qtd_QVariant_load_QDataStream(void* __this_nativeId, - void* ds0); -private extern(C) void qtd_QVariant_writeTo_QDataStream(void* __this_nativeId, - void* s0); -private extern(C) void* qtd_QVariant_operator_assign_QVariant(void* __this_nativeId, - void* other0); -private extern(C) bool qtd_QVariant_operator_equal_QVariant(void* __this_nativeId, - void* v0); -private extern(C) void qtd_QVariant_readFrom_QDataStream(void* __this_nativeId, - void* s0); -private extern(C) void qtd_QVariant_save_QDataStream(void* __this_nativeId, - void* ds0); -private extern(C) void* qtd_QVariant_toBitArray(void* __this_nativeId); -private extern(C) bool qtd_QVariant_toBool(void* __this_nativeId); -private extern(C) void* qtd_QVariant_toByteArray(void* __this_nativeId); -private extern(C) void* qtd_QVariant_toDate(void* __this_nativeId); -private extern(C) void* qtd_QVariant_toDateTime(void* __this_nativeId); -private extern(C) double qtd_QVariant_toDouble_nativepointerbool(void* __this_nativeId, - bool* ok0); -private extern(C) int qtd_QVariant_toInt_nativepointerbool(void* __this_nativeId, - bool* ok0); -private extern(C) QLine qtd_QVariant_toLine(void* __this_nativeId); -private extern(C) QLineF qtd_QVariant_toLineF(void* __this_nativeId); -private extern(C) void* qtd_QVariant_toLocale(void* __this_nativeId); -private extern(C) long qtd_QVariant_toLongLong_nativepointerbool(void* __this_nativeId, - bool* ok0); -private extern(C) QPoint qtd_QVariant_toPoint(void* __this_nativeId); -private extern(C) QPointF qtd_QVariant_toPointF(void* __this_nativeId); -private extern(C) QRect qtd_QVariant_toRect(void* __this_nativeId); -private extern(C) QRectF qtd_QVariant_toRectF(void* __this_nativeId); -private extern(C) void* qtd_QVariant_toRegExp(void* __this_nativeId); -private extern(C) QSize qtd_QVariant_toSize(void* __this_nativeId); -private extern(C) QSizeF qtd_QVariant_toSizeF(void* __this_nativeId); -private extern(C) void qtd_QVariant_toString(void* __this_nativeId, - void* __java_return_value); -private extern(C) void* qtd_QVariant_toTime(void* __this_nativeId); -private extern(C) uint qtd_QVariant_toUInt_nativepointerbool(void* __this_nativeId, - bool* ok0); -private extern(C) ulong qtd_QVariant_toULongLong_nativepointerbool(void* __this_nativeId, - bool* ok0); -private extern(C) void* qtd_QVariant_toUrl(void* __this_nativeId); -private extern(C) char* qtd_QVariant_typeName(void* __this_nativeId); -private extern(C) int qtd_QVariant_type(void* __this_nativeId); -private extern(C) int qtd_QVariant_userType(void* __this_nativeId); -private extern(C) void *qtd_QVariant_data(void* __this_nativeId); - -// Just the private functions for abstract functions implemeneted in superclasses - -// Virtual Dispatch functions diff -r 552647ec0f82 -r 96a75b1e5b26 qt/d2/qt/qtd/Str.d --- a/qt/d2/qt/qtd/Str.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/** - * - * Copyright: Copyright QtD Team, 2008-2009 - * License: Boost License 1.0 - * - * Copyright QtD Team, 2008-2009 - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file boost-license-1.0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - * - */ -module qt.qtd.Array; - -version (Tango) - import tango.stdc.string; -else - import core.stdc.string; - -void remove(T)(ref T[] haystack, T needle) -{ - foreach (i, e; haystack) - { - if (e == needle) - { - if (haystack.length > 1) - { - i++; - memmove(haystack.ptr + i - 1, haystack.ptr + i, (haystack.length - i) * T.sizeof); - haystack.length = haystack.length - 1; - } - else - haystack.length = 0; - - break; - } - } -} \ No newline at end of file diff -r 552647ec0f82 -r 96a75b1e5b26 qt/qtd/ArrayOpsPrimitive.d --- a/qt/qtd/ArrayOpsPrimitive.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -/** -* -* Copyright: Copyright QtD Team, 2008-2009 -* License: - // implementation provides a 'ddhlb' ordering specifier for - // data-dependent loads to handle this situation, but as there - // are no plans to support the Alpha there is no reason to add - // that option here. - // - // For reference, the old behavior (acquire semantics for loads) - // required a memory barrier if: ms == msync.seq || isSinkOp!(ms) - template needsLoadBarrier( msync ms ) - { - const bool needsLoadBarrier = ms != msync.raw; - } - - - // NOTE: x86 stores implicitly have release semantics so a membar is only - // necessary on acquires. - template needsStoreBarrier( msync ms ) - { - const bool needsStoreBarrier = ms == msync.seq || isHoistOp!(ms); - } - } - - - //////////////////////////////////////////////////////////////////////////// - // Atomic Load - //////////////////////////////////////////////////////////////////////////// - - - template atomicLoad( msync ms = msync.seq, T ) - { - T atomicLoad( ref T val ) - in - { - assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); - } - body - { - static if( T.sizeof == byte.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 1 Byte Load - //////////////////////////////////////////////////////////////// - - - static if( needsLoadBarrier!(ms) ) - { - asm - { - mov DL, 42; - mov AL, 42; - mov ECX, val; - lock; - cmpxchg [ECX], DL; - } - } - else - { - synchronized - { - return val; - } - } - } - else static if( T.sizeof == short.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 2 Byte Load - //////////////////////////////////////////////////////////////// - - static if( needsLoadBarrier!(ms) ) - { - asm - { - mov DX, 42; - mov AX, 42; - mov ECX, val; - lock; - cmpxchg [ECX], DX; - } - } - else - { - synchronized - { - return val; - } - } - } - else static if( T.sizeof == int.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 4 Byte Load - //////////////////////////////////////////////////////////////// - - - static if( needsLoadBarrier!(ms) ) - { - asm - { - mov EDX, 42; - mov EAX, 42; - mov ECX, val; - lock; - cmpxchg [ECX], EDX; - } - } - else - { - synchronized - { - return val; - } - } - } - else static if( T.sizeof == long.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 8 Byte Load - //////////////////////////////////////////////////////////////// - - - version( Has64BitOps ) - { - //////////////////////////////////////////////////////////// - // 8 Byte Load on 64-Bit Processor - //////////////////////////////////////////////////////////// - - - static if( needsLoadBarrier!(ms) ) - { - asm - { - mov RAX, val; - lock; - mov RAX, [RAX]; - } - } - else - { - synchronized - { - return val; - } - } - } - else - { - //////////////////////////////////////////////////////////// - // 8 Byte Load on 32-Bit Processor - //////////////////////////////////////////////////////////// - - - pragma( msg, "This operation is only available on 64-bit platforms." ); - static assert( false ); - } - } - else - { - //////////////////////////////////////////////////////////////// - // Not a 1, 2, 4, or 8 Byte Type - //////////////////////////////////////////////////////////////// - - - pragma( msg, "Invalid template type specified." ); - static assert( false ); - } - } - } - - - //////////////////////////////////////////////////////////////////////////// - // Atomic Store - //////////////////////////////////////////////////////////////////////////// - - - template atomicStore( msync ms = msync.seq, T ) - { - void atomicStore( ref T val, T newval ) - in - { - assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); - } - body - { - static if( T.sizeof == byte.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 1 Byte Store - //////////////////////////////////////////////////////////////// - - - static if( needsStoreBarrier!(ms) ) - { - asm - { - mov EAX, val; - mov DL, newval; - lock; - xchg [EAX], DL; - } - } - else - { - asm - { - mov EAX, val; - mov DL, newval; - mov [EAX], DL; - } - } - } - else static if( T.sizeof == short.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 2 Byte Store - //////////////////////////////////////////////////////////////// - - - static if( needsStoreBarrier!(ms) ) - { - asm - { - mov EAX, val; - mov DX, newval; - lock; - xchg [EAX], DX; - } - } - else - { - asm - { - mov EAX, val; - mov DX, newval; - mov [EAX], DX; - } - } - } - else static if( T.sizeof == int.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 4 Byte Store - //////////////////////////////////////////////////////////////// - - - static if( needsStoreBarrier!(ms) ) - { - asm - { - mov EAX, val; - mov EDX, newval; - lock; - xchg [EAX], EDX; - } - } - else - { - asm - { - mov EAX, val; - mov EDX, newval; - mov [EAX], EDX; - } - } - } - else static if( T.sizeof == long.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 8 Byte Store - //////////////////////////////////////////////////////////////// - - - version( Has64BitOps ) - { - //////////////////////////////////////////////////////////// - // 8 Byte Store on 64-Bit Processor - //////////////////////////////////////////////////////////// - - - static if( needsStoreBarrier!(ms) ) - { - asm - { - mov RAX, val; - mov RDX, newval; - lock; - xchg [RAX], RDX; - } - } - else - { - asm - { - mov RAX, val; - mov RDX, newval; - mov [RAX], RDX; - } - } - } - else - { - //////////////////////////////////////////////////////////// - // 8 Byte Store on 32-Bit Processor - //////////////////////////////////////////////////////////// - - - pragma( msg, "This operation is only available on 64-bit platforms." ); - static assert( false ); - } - } - else - { - //////////////////////////////////////////////////////////////// - // Not a 1, 2, 4, or 8 Byte Type - //////////////////////////////////////////////////////////////// - - - pragma( msg, "Invalid template type specified." ); - static assert( false ); - } - } - } - - - //////////////////////////////////////////////////////////////////////////// - // Atomic Store If - //////////////////////////////////////////////////////////////////////////// - - - template atomicStoreIf( msync ms = msync.seq, T ) - { - bool atomicStoreIf( ref T val, T newval, T equalTo ) - in - { - // NOTE: 32 bit x86 systems support 8 byte CAS, which only requires - // 4 byte alignment, so use size_t as the align type here. - static if( T.sizeof > size_t.sizeof ) - assert( atomicValueIsProperlyAligned!(size_t)( cast(size_t) &val ) ); - else - assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); - } - body - { - static if( T.sizeof == byte.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 1 Byte StoreIf - //////////////////////////////////////////////////////////////// - - - asm - { - mov DL, newval; - mov AL, equalTo; - mov ECX, val; - lock; // lock always needed to make this op atomic - cmpxchg [ECX], DL; - setz AL; - } - } - else static if( T.sizeof == short.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 2 Byte StoreIf - //////////////////////////////////////////////////////////////// - - - asm - { - mov DX, newval; - mov AX, equalTo; - mov ECX, val; - lock; // lock always needed to make this op atomic - cmpxchg [ECX], DX; - setz AL; - } - } - else static if( T.sizeof == int.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 4 Byte StoreIf - //////////////////////////////////////////////////////////////// - - - asm - { - mov EDX, newval; - mov EAX, equalTo; - mov ECX, val; - lock; // lock always needed to make this op atomic - cmpxchg [ECX], EDX; - setz AL; - } - } - else static if( T.sizeof == long.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 8 Byte StoreIf - //////////////////////////////////////////////////////////////// - - - version( Has64BitOps ) - { - //////////////////////////////////////////////////////////// - // 8 Byte StoreIf on 64-Bit Processor - //////////////////////////////////////////////////////////// - - - asm - { - mov RDX, newval; - mov RAX, equalTo; - mov RCX, val; - lock; // lock always needed to make this op atomic - cmpxchg [RCX], RDX; - setz AL; - } - } - else version( Has64BitCAS ) - { - //////////////////////////////////////////////////////////// - // 8 Byte StoreIf on 32-Bit Processor - //////////////////////////////////////////////////////////// - version(darwin){ - static if(ms==msync.raw){ - return OSAtomicCompareAndSwap64(cast(long)equalTo, cast(long)newval, cast(long*)&val); - } else { - return OSAtomicCompareAndSwap64Barrier(cast(long)equalTo, cast(long)newval, cast(long*)&val); - } - } else { - asm - { - push EDI; - push EBX; - lea EDI, newval; - mov EBX, [EDI]; - mov ECX, 4[EDI]; - lea EDI, equalTo; - mov EAX, [EDI]; - mov EDX, 4[EDI]; - mov EDI, val; - lock; // lock always needed to make this op atomic - cmpxch8b [EDI]; - setz AL; - pop EBX; - pop EDI; - } - } - } - } - else - { - //////////////////////////////////////////////////////////////// - // Not a 1, 2, 4, or 8 Byte Type - //////////////////////////////////////////////////////////////// - - - pragma( msg, "Invalid template type specified." ); - static assert( false ); - } - } - } - - - //////////////////////////////////////////////////////////////////////////// - // Atomic Increment - //////////////////////////////////////////////////////////////////////////// - - - template atomicIncrement( msync ms = msync.seq, T ) - { - // - // NOTE: This operation is only valid for integer or pointer types - // - static assert( isValidNumericType!(T) ); - - - T atomicIncrement( ref T val ) - in - { - assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); - } - body - { - static if( T.sizeof == byte.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 1 Byte Increment - //////////////////////////////////////////////////////////////// - - - asm - { - mov EAX, val; - lock; // lock always needed to make this op atomic - inc [EAX]; - mov AL, [EAX]; - } - } - else static if( T.sizeof == short.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 2 Byte Increment - //////////////////////////////////////////////////////////////// - - - asm - { - mov EAX, val; - lock; // lock always needed to make this op atomic - inc short ptr [EAX]; - mov AX, [EAX]; - } - } - else static if( T.sizeof == int.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 4 Byte Increment - //////////////////////////////////////////////////////////////// - - - asm - { - mov EAX, val; - lock; // lock always needed to make this op atomic - inc int ptr [EAX]; - mov EAX, [EAX]; - } - } - else static if( T.sizeof == long.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 8 Byte Increment - //////////////////////////////////////////////////////////////// - - - version( Has64BitOps ) - { - //////////////////////////////////////////////////////////// - // 8 Byte Increment on 64-Bit Processor - //////////////////////////////////////////////////////////// - - - asm - { - mov RAX, val; - lock; // lock always needed to make this op atomic - inc qword ptr [RAX]; - mov RAX, [RAX]; - } - } - else - { - //////////////////////////////////////////////////////////// - // 8 Byte Increment on 32-Bit Processor - //////////////////////////////////////////////////////////// - - - pragma( msg, "This operation is only available on 64-bit platforms." ); - static assert( false ); - } - } - else - { - //////////////////////////////////////////////////////////////// - // Not a 1, 2, 4, or 8 Byte Type - //////////////////////////////////////////////////////////////// - - - pragma( msg, "Invalid template type specified." ); - static assert( false ); - } - } - } - - - //////////////////////////////////////////////////////////////////////////// - // Atomic Decrement - //////////////////////////////////////////////////////////////////////////// - - - template atomicDecrement( msync ms = msync.seq, T ) - { - // - // NOTE: This operation is only valid for integer or pointer types - // - static assert( isValidNumericType!(T) ); - - - T atomicDecrement( ref T val ) - in - { - assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); - } - body - { - static if( T.sizeof == byte.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 1 Byte Decrement - //////////////////////////////////////////////////////////////// - - - asm - { - mov EAX, val; - lock; // lock always needed to make this op atomic - dec [EAX]; - mov AL, [EAX]; - } - } - else static if( T.sizeof == short.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 2 Byte Decrement - //////////////////////////////////////////////////////////////// - - - asm - { - mov EAX, val; - lock; // lock always needed to make this op atomic - dec short ptr [EAX]; - mov AX, [EAX]; - } - } - else static if( T.sizeof == int.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 4 Byte Decrement - //////////////////////////////////////////////////////////////// - - - asm - { - mov EAX, val; - lock; // lock always needed to make this op atomic - dec int ptr [EAX]; - mov EAX, [EAX]; - } - } - else static if( T.sizeof == long.sizeof ) - { - //////////////////////////////////////////////////////////////// - // 8 Byte Decrement - //////////////////////////////////////////////////////////////// - - - version( Has64BitOps ) - { - //////////////////////////////////////////////////////////// - // 8 Byte Decrement on 64-Bit Processor - //////////////////////////////////////////////////////////// - - - asm - { - mov RAX, val; - lock; // lock always needed to make this op atomic - dec qword ptr [RAX]; - mov RAX, [RAX]; - } - } - else - { - //////////////////////////////////////////////////////////// - // 8 Byte Decrement on 32-Bit Processor - //////////////////////////////////////////////////////////// - - - pragma( msg, "This operation is only available on 64-bit platforms." ); - static assert( false ); - } - } - else - { - //////////////////////////////////////////////////////////////// - // Not a 1, 2, 4, or 8 Byte Type - //////////////////////////////////////////////////////////////// - - - pragma( msg, "Invalid template type specified." ); - static assert( false ); - } - } - } -} -else -{ - version( BuildInfo ) - { - pragma( msg, "tango.core.Atomic: using synchronized ops" ); - } - - private - { - //////////////////////////////////////////////////////////////////////// - // Default Value Requirements - //////////////////////////////////////////////////////////////////////// - - - template atomicValueIsProperlyAligned( T ) - { - bool atomicValueIsProperlyAligned( size_t addr ) - { - return addr % T.sizeof == 0; - } - } - - - //////////////////////////////////////////////////////////////////////// - // Default Synchronization Requirements - //////////////////////////////////////////////////////////////////////// - - - template needsLoadBarrier( msync ms ) - { - const bool needsLoadBarrier = ms != msync.raw; - } - - - template needsStoreBarrier( msync ms ) - { - const bool needsStoreBarrier = ms != msync.raw; - } - } - - - //////////////////////////////////////////////////////////////////////////// - // Atomic Load - //////////////////////////////////////////////////////////////////////////// - - - template atomicLoad( msync ms = msync.seq, T ) - { - T atomicLoad( ref T val ) - in - { - assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); - } - body - { - static if( T.sizeof <= (void*).sizeof ) - { - //////////////////////////////////////////////////////////////// - // <= (void*).sizeof Byte Load - //////////////////////////////////////////////////////////////// - - - static if( needsLoadBarrier!(ms) ) - { - synchronized - { - return val; - } - } - else - { - synchronized - { - return val; - } - } - } - else - { - //////////////////////////////////////////////////////////////// - // > (void*).sizeof Byte Type - //////////////////////////////////////////////////////////////// - - - pragma( msg, "Invalid template type specified." ); - static assert( false ); - } - } - } - - - //////////////////////////////////////////////////////////////////////////// - // Atomic Store - //////////////////////////////////////////////////////////////////////////// - - - template atomicStore( msync ms = msync.seq, T ) - { - void atomicStore( ref T val, T newval ) - in - { - assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); - } - body - { - static if( T.sizeof <= (void*).sizeof ) - { - //////////////////////////////////////////////////////////////// - // <= (void*).sizeof Byte Store - //////////////////////////////////////////////////////////////// - - - static if( needsStoreBarrier!(ms) ) - { - synchronized - { - val = newval; - } - } - else - { - synchronized - { - val = newval; - } - } - } - else - { - //////////////////////////////////////////////////////////////// - // > (void*).sizeof Byte Type - //////////////////////////////////////////////////////////////// - - - pragma( msg, "Invalid template type specified." ); - static assert( false ); - } - } - } - - - //////////////////////////////////////////////////////////////////////////// - // Atomic Store If - //////////////////////////////////////////////////////////////////////////// - - - template atomicStoreIf( msync ms = msync.seq, T ) - { - bool atomicStoreIf( ref T val, T newval, T equalTo ) - in - { - assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); - } - body - { - static if( T.sizeof <= (void*).sizeof ) - { - //////////////////////////////////////////////////////////////// - // <= (void*).sizeof Byte StoreIf - //////////////////////////////////////////////////////////////// - - - synchronized - { - if( val == equalTo ) - { - val = newval; - return true; - } - return false; - } - } - else - { - //////////////////////////////////////////////////////////////// - // > (void*).sizeof Byte Type - //////////////////////////////////////////////////////////////// - - - pragma( msg, "Invalid template type specified." ); - static assert( false ); - } - } - } - - - ///////////////////////////////////////////////////////////////////////////// - // Atomic Increment - //////////////////////////////////////////////////////////////////////////// - - - template atomicIncrement( msync ms = msync.seq, T ) - { - // - // NOTE: This operation is only valid for integer or pointer types - // - static assert( isValidNumericType!(T) ); - - - T atomicIncrement( ref T val ) - in - { - assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); - } - body - { - static if( T.sizeof <= (void*).sizeof ) - { - //////////////////////////////////////////////////////////////// - // <= (void*).sizeof Byte Increment - //////////////////////////////////////////////////////////////// - - - synchronized - { - return ++val; - } - } - else - { - //////////////////////////////////////////////////////////////// - // > (void*).sizeof Byte Type - //////////////////////////////////////////////////////////////// - - - pragma( msg, "Invalid template type specified." ); - static assert( false ); - } - } - } - - - //////////////////////////////////////////////////////////////////////////// - // Atomic Decrement - //////////////////////////////////////////////////////////////////////////// - - - template atomicDecrement( msync ms = msync.seq, T ) - { - // - // NOTE: This operation is only valid for integer or pointer types - // - static assert( isValidNumericType!(T) ); - - - T atomicDecrement( ref T val ) - in - { - assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); - } - body - { - static if( T.sizeof <= (void*).sizeof ) - { - //////////////////////////////////////////////////////////////// - // <= (void*).sizeof Byte Decrement - //////////////////////////////////////////////////////////////// - - - synchronized - { - return --val; - } - } - else - { - //////////////////////////////////////////////////////////////// - // > (void*).sizeof Byte Type - //////////////////////////////////////////////////////////////// - - - pragma( msg, "Invalid template type specified." ); - static assert( false ); - } - } - } -} - - -//////////////////////////////////////////////////////////////////////////////// -// Atomic -//////////////////////////////////////////////////////////////////////////////// - - -/** - * This struct represents a value which will be subject to competing access. - * All accesses to this value will be synchronized with main memory, and - * various memory barriers may be employed for instruction ordering. Any - * primitive type of size equal to or smaller than the memory bus size is - * allowed, so 32-bit machines may use values with size <= int.sizeof and - * 64-bit machines may use values with size <= long.sizeof. The one exception - * to this rule is that architectures that support DCAS will allow double-wide - * storeIf operations. The 32-bit x86 architecture, for example, supports - * 64-bit storeIf operations. - */ -struct Atomic( T ) -{ - //////////////////////////////////////////////////////////////////////////// - // Atomic Load - //////////////////////////////////////////////////////////////////////////// - - - template load( msync ms = msync.seq ) - { - static assert( ms == msync.raw || ms == msync.hlb || - ms == msync.acq || ms == msync.seq, - "ms must be one of: msync.raw, msync.hlb, msync.acq, msync.seq" ); - - /** - * Refreshes the contents of this value from main memory. This - * operation is both lock-free and atomic. - * - * Returns: - * The loaded value. - */ - T load() - { - return atomicLoad!(ms,T)( m_val ); - } - } - - - //////////////////////////////////////////////////////////////////////////// - // Atomic Store - //////////////////////////////////////////////////////////////////////////// - - - template store( msync ms = msync.seq ) - { - static assert( ms == msync.raw || ms == msync.ssb || - ms == msync.acq || ms == msync.rel || - ms == msync.seq, - "ms must be one of: msync.raw, msync.ssb, msync.acq, msync.rel, msync.seq" ); - - /** - * Stores 'newval' to the memory referenced by this value. This - * operation is both lock-free and atomic. - * - * Params: - * newval = The value to store. - */ - void store( T newval ) - { - atomicStore!(ms,T)( m_val, newval ); - } - } - - - //////////////////////////////////////////////////////////////////////////// - // Atomic StoreIf - //////////////////////////////////////////////////////////////////////////// - - - template storeIf( msync ms = msync.seq ) - { - static assert( ms == msync.raw || ms == msync.ssb || - ms == msync.acq || ms == msync.rel || - ms == msync.seq, - "ms must be one of: msync.raw, msync.ssb, msync.acq, msync.rel, msync.seq" ); - - /** - * Stores 'newval' to the memory referenced by this value if val is - * equal to 'equalTo'. This operation is both lock-free and atomic. - * - * Params: - * newval = The value to store. - * equalTo = The comparison value. - * - * Returns: - * true if the store occurred, false if not. - */ - bool storeIf( T newval, T equalTo ) - { - return atomicStoreIf!(ms,T)( m_val, newval, equalTo ); - } - } - - - //////////////////////////////////////////////////////////////////////////// - // Numeric Functions - //////////////////////////////////////////////////////////////////////////// - - - /** - * The following additional functions are available for integer types. - */ - static if( isValidNumericType!(T) ) - { - //////////////////////////////////////////////////////////////////////// - // Atomic Increment - //////////////////////////////////////////////////////////////////////// - - - template increment( msync ms = msync.seq ) - { - static assert( ms == msync.raw || ms == msync.ssb || - ms == msync.acq || ms == msync.rel || - ms == msync.seq, - "ms must be one of: msync.raw, msync.ssb, msync.acq, msync.rel, msync.seq" ); - - /** - * This operation is only legal for built-in value and pointer - * types, and is equivalent to an atomic "val = val + 1" operation. - * This function exists to facilitate use of the optimized - * increment instructions provided by some architecures. If no - * such instruction exists on the target platform then the - * behavior will perform the operation using more traditional - * means. This operation is both lock-free and atomic. - * - * Returns: - * The result of an atomicLoad of val immediately following the - * increment operation. This value is not required to be equal to - * the newly stored value. Thus, competing writes are allowed to - * occur between the increment and successive load operation. - */ - T increment() - { - return atomicIncrement!(ms,T)( m_val ); - } - } - - - //////////////////////////////////////////////////////////////////////// - // Atomic Decrement - //////////////////////////////////////////////////////////////////////// - - - template decrement( msync ms = msync.seq ) - { - static assert( ms == msync.raw || ms == msync.ssb || - ms == msync.acq || ms == msync.rel || - ms == msync.seq, - "ms must be one of: msync.raw, msync.ssb, msync.acq, msync.rel, msync.seq" ); - - /** - * This operation is only legal for built-in value and pointer - * types, and is equivalent to an atomic "val = val - 1" operation. - * This function exists to facilitate use of the optimized - * decrement instructions provided by some architecures. If no - * such instruction exists on the target platform then the behavior - * will perform the operation using more traditional means. This - * operation is both lock-free and atomic. - * - * Returns: - * The result of an atomicLoad of val immediately following the - * increment operation. This value is not required to be equal to - * the newly stored value. Thus, competing writes are allowed to - * occur between the increment and successive load operation. - */ - T decrement() - { - return atomicDecrement!(ms,T)( m_val ); - } - } - } - -private: - T m_val; -} - - -//////////////////////////////////////////////////////////////////////////////// -// Support Code for Unit Tests -//////////////////////////////////////////////////////////////////////////////// - - -private -{ - version( D_Ddoc ) {} else - { - template testLoad( msync ms, T ) - { - void testLoad( T val = T.init + 1 ) - { - T base; - Atomic!(T) atom; - - assert( atom.load!(ms)() == base ); - base = val; - atom.m_val = val; - assert( atom.load!(ms)() == base ); - } - } - - - template testStore( msync ms, T ) - { - void testStore( T val = T.init + 1 ) - { - T base; - Atomic!(T) atom; - - assert( atom.m_val == base ); - base = val; - atom.store!(ms)( base ); - assert( atom.m_val == base ); - } - } - - - template testStoreIf( msync ms, T ) - { - void testStoreIf( T val = T.init + 1 ) - { - T base; - Atomic!(T) atom; - - assert( atom.m_val == base ); - base = val; - atom.storeIf!(ms)( base, val ); - assert( atom.m_val != base ); - atom.storeIf!(ms)( base, T.init ); - assert( atom.m_val == base ); - } - } - - - template testIncrement( msync ms, T ) - { - void testIncrement( T val = T.init + 1 ) - { - T base = val; - T incr = val; - Atomic!(T) atom; - - atom.m_val = val; - assert( atom.m_val == base && incr == base ); - base = cast(T)( base + 1 ); - incr = atom.increment!(ms)(); - assert( atom.m_val == base && incr == base ); - } - } - - - template testDecrement( msync ms, T ) - { - void testDecrement( T val = T.init + 1 ) - { - T base = val; - T decr = val; - Atomic!(T) atom; - - atom.m_val = val; - assert( atom.m_val == base && decr == base ); - base = cast(T)( base - 1 ); - decr = atom.decrement!(ms)(); - assert( atom.m_val == base && decr == base ); - } - } - - - template testType( T ) - { - void testType( T val = T.init +1 ) - { - testLoad!(msync.raw, T)( val ); - testLoad!(msync.hlb, T)( val ); - testLoad!(msync.acq, T)( val ); - testLoad!(msync.seq, T)( val ); - - testStore!(msync.raw, T)( val ); - testStore!(msync.ssb, T)( val ); - testStore!(msync.acq, T)( val ); - testStore!(msync.rel, T)( val ); - testStore!(msync.seq, T)( val ); - - testStoreIf!(msync.raw, T)( val ); - testStoreIf!(msync.ssb, T)( val ); - testStoreIf!(msync.acq, T)( val ); - testStoreIf!(msync.rel, T)( val ); - testStoreIf!(msync.seq, T)( val ); - - static if( isValidNumericType!(T) ) - { - testIncrement!(msync.raw, T)( val ); - testIncrement!(msync.ssb, T)( val ); - testIncrement!(msync.acq, T)( val ); - testIncrement!(msync.rel, T)( val ); - testIncrement!(msync.seq, T)( val ); - - testDecrement!(msync.raw, T)( val ); - testDecrement!(msync.ssb, T)( val ); - testDecrement!(msync.acq, T)( val ); - testDecrement!(msync.rel, T)( val ); - testDecrement!(msync.seq, T)( val ); - } - } - } - } -} - - -//////////////////////////////////////////////////////////////////////////////// -// Unit Tests -//////////////////////////////////////////////////////////////////////////////// - - -debug( UnitTest ) -{ - unittest - { - testType!(bool)(); - - testType!(byte)(); - testType!(ubyte)(); - - testType!(short)(); - testType!(ushort)(); - - testType!(int)(); - testType!(uint)(); - - int x; - testType!(void*)( &x ); - - version( Has64BitOps ) - { - testType!(long)(); - testType!(ulong)(); - } - else version( Has64BitCAS ) - { - testStoreIf!(msync.raw, long)(); - testStoreIf!(msync.ssb, long)(); - testStoreIf!(msync.acq, long)(); - testStoreIf!(msync.rel, long)(); - testStoreIf!(msync.seq, long)(); - - testStoreIf!(msync.raw, ulong)(); - testStoreIf!(msync.ssb, ulong)(); - testStoreIf!(msync.acq, ulong)(); - testStoreIf!(msync.rel, ulong)(); - testStoreIf!(msync.seq, ulong)(); - } - } -} diff -r 552647ec0f82 -r 96a75b1e5b26 qt/qtd/CMakeLists.txt --- a/qt/qtd/CMakeLists.txt Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -set(QT_QTD_SRCS_D -Str.d -) diff -r 552647ec0f82 -r 96a75b1e5b26 qt/qtd/MOC.d --- a/qt/qtd/MOC.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,561 +0,0 @@ -module qt.qtd.MOC; - -import qt.qtd.ctfe.Format; - -import std.typetuple; - -import qt.QGlobal; -import qt.Signal; -import qt.qtd.MetaMarshall; -import qt.qtd.Meta; - -public import qt.core.QString; - -public import std.traits; -/** - Utils. - */ - -bool is_digit_char(const char s) -{ - return (s >= '0' && s <= '9'); -} - -bool is_octal_char(const char s) -{ - return (s >= '0' && s <= '7'); -} - -bool is_hex_char(const char s) -{ - return ((s >= 'a' && s <= 'f') - || (s >= 'A' && s <= 'F') - || (s >= '0' && s <= '9') - ); -} - -int lastIndexOf(T)(T[] haystack, T[] needle, int from = -1) -{ - auto l = haystack.length; - auto ol = needle.length; - int delta = l - ol; - if (from < 0) - from = delta; - if (from < 0 || from > l) - return -1; - if (from > delta) - from = delta; - - while(from >= 0) - { - if (haystack[from..from+ol] == needle) - return from; - from--; - } - return -1; -} - - -T[] newArray(T)(size_t len, T[] from = []) -{ - if (len == from.length) - return from; - - if (!from.length) - from = [T.init]; - - if (from.length < len) - return newArray!T(len, from ~ from); - - return from[0..len]; -} - -string replicate(int n, char value) -{ - char[] ret = "".dup; - if (n > 0) - { -// ret = newArray!char(n); - for(int i = 0; i < n; i++) - ret ~= value; - } - return cast(string)ret; -} - -/** - CTFE MOC port. - */ - -enum MethodFlags { - AccessPrivate = 0x00, - AccessProtected = 0x01, - AccessPublic = 0x02, - MethodMethod = 0x00, - MethodSignal = 0x04, - MethodSlot = 0x08, - MethodConstructor = 0x0c, - MethodCompatibility = 0x10, - MethodCloned = 0x20, - MethodScriptable = 0x40 -} - -enum Access { Private, Protected, Public } - -struct FunctionDef -{ -/* FunctionDef(): returnTypeIsVolatile(false), access(Private), isConst(false), isVirtual(false), - inlineCode(false), wasCloned(false), isCompat(false), isInvokable(false), - isScriptable(false), isSlot(false), isSignal(false), - isConstructor(false), isDestructor(false), isAbstract(false) {} - */ -// Type type; -// string normalizedType; -// string tag; -// string name; - string sig; - string arguments; - Access access; -/* bool returnTypeIsVolatile; - - QList arguments; - - enum Access { Private, Protected, Public }; - bool isConst; - bool isVirtual; - bool inlineCode; - bool wasCloned; - - QByteArray inPrivateClass; - bool isCompat; - bool isInvokable; - bool isScriptable; - bool isSlot; - bool isSignal; - bool isConstructor; - bool isDestructor; - bool isAbstract; - */ -} - -FunctionDef newSlot(string sig, string args) -{ - return FunctionDef(sig, args, Access.Public); -} - -FunctionDef newSignal(string sig, string args) -{ - return FunctionDef(sig, args, Access.Protected); -} - -struct Generator -{ - string output; - string[] strings; -// QByteArray purestSuperClass; -// QList metaTypes; -} - -int lengthOfEscapeSequence(string s, uint i) -{ - if (s[i] != '\\' || i >= s.length - 1) - return 1; - const int startPos = i; - ++i; - auto ch = s[i]; - if (ch == 'x') { - ++i; - while (i < s.length && is_hex_char(s[i])) - ++i; - } else if (is_octal_char(ch)) { - while (i < startPos + 4 - && i < s.length - && is_octal_char(s[i])) { - ++i; - } - } else { // single character escape sequence - i = qMin(i + 1, s.length); - } - return i - startPos; -} - -int strreg(ref Generator gen, string s) -{ - int idx = 0; - foreach (str; gen.strings) { - if (str == s) - return idx; - idx += str.length + 1; - foreach (i, c; str) { - if (c == '\\') { - int cnt = lengthOfEscapeSequence(str, i) - 1; - idx -= cnt; - i += cnt; - } - } - } - gen.strings ~= s; - return idx; -} - -void generateFunctions(ref Generator gen, FunctionDef[] list, string functype, byte type) -{ - if (!list.length) - return; - gen.output ~= format_ctfe("\n // ${}s: signature, parameters, type, tag, flags\n", functype); - - foreach (i, f; list) { - byte flags = type; - - if (f.access == Access.Private) - flags |= MethodFlags.AccessPrivate; - else if (f.access == Access.Public) - flags |= MethodFlags.AccessPublic; - else if (f.access == Access.Protected) - flags |= MethodFlags.AccessProtected; - - gen.output ~= format_ctfe(" ${}, ${}, ${}, ${}, 0x${:x},\n", strreg(gen, f.sig), - strreg(gen, f.arguments), strreg(gen, ""/*f.normalizedType*/), strreg(gen, ""/*f.tag*/), flags); - } -} - -string generateCode(string className, FunctionDef[] signalList, FunctionDef[] slotList) -{ - auto gen = Generator("", []); - -/* bool isQt = (cdef->classname == "Qt"); - bool isQObject = (cdef->classname == "QObject"); - bool isConstructible = !cdef->constructorList.isEmpty(); - -// -// build the data array -// - int i = 0; - - - // filter out undeclared enumerators and sets - { - QList enumList; - for (i = 0; i < cdef->enumList.count(); ++i) { - EnumDef def = cdef->enumList.at(i); - if (cdef->enumDeclarations.contains(def.name)) { - enumList += def; - } - QByteArray alias = cdef->flagAliases.value(def.name); - if (cdef->enumDeclarations.contains(alias)) { - def.name = alias; - enumList += def; - } - } - cdef->enumList = enumList; - } - - - QByteArray qualifiedClassNameIdentifier = cdef->qualified; - qualifiedClassNameIdentifier.replace(':', '_'); -*/ - bool isConstructible = false; - - FunctionDef[] propertyList, enumList, constructorList; - int index = 12; - gen.output ~= format_ctfe("static const uint[] qt_meta_data_${} = [\n", className); - gen.output ~= format_ctfe("\n // content:\n"); - gen.output ~= format_ctfe(" ${}, // revision\n", 2); - gen.output ~= format_ctfe(" ${}, // classname\n", strreg(gen, className)); - gen.output ~= format_ctfe(" ${}, ${}, // classinfo\n", 0, 0); -// index += cdef->classInfoList.count() * 2; - - int methodCount = signalList.length + slotList.length;// + cdef->methodList.count(); - gen.output ~= format_ctfe(" ${}, ${}, // methods\n", methodCount, methodCount ? index : 0); - index += methodCount * 5; - gen.output ~= format_ctfe(" ${}, ${}, // properties\n", propertyList.length, propertyList.length ? index : 0); - index += propertyList.length * 3; -// if(cdef->notifyableProperties) -// index += cdef->propertyList.count(); - gen.output ~= format_ctfe(" ${}, ${}, // enums/sets\n", enumList.length, enumList.length ? index : 0); - -// int enumsIndex = index; -// for (i = 0; i < cdef->enumList.count(); ++i) -// index += 4 + (cdef->enumList.at(i).values.count() * 2); - gen.output ~= format_ctfe(" ${}, ${}, // constructors\n", isConstructible ? constructorList.length : 0, - isConstructible ? index : 0); - -// -// Build classinfo array -// -// generateClassInfos(); - -// -// Build signals array first, otherwise the signal indices would be wrong -// - generateFunctions(gen, signalList, "signal", MethodFlags.MethodSignal); - -// -// Build slots array -// - generateFunctions(gen, slotList, "slot", MethodFlags.MethodSlot); - -// -// Build method array -// -// generateFunctions(cdef->methodList, "method", MethodMethod); - - -// -// Build property array -// -// generateProperties(); - -// -// Build enums array -// -// generateEnums(enumsIndex); - -// -// Build constructors array -// -// if (isConstructible) -// generateFunctions(cdef->constructorList, "constructor", MethodConstructor); - -// -// Terminate data array -// - gen.output ~= format_ctfe("\n 0 // eod\n];\n\n"); - -// -// Build stringdata array -// - gen.output ~= format_ctfe("static const string qt_meta_stringdata_${} = \n", className); - gen.output ~= format_ctfe(" \""); - int col = 0; - int len = 0; - foreach (i, s; gen.strings) { - len = s.length; - if (col && col + len >= 72) { - gen.output ~= format_ctfe("\"\n \""); - col = 0; - } else if (len && s[0] >= '0' && s[0] <= '9') { - gen.output ~= format_ctfe("\"\""); - len += 2; - } - int idx = 0; - while (idx < s.length) { - if (idx > 0) { - col = 0; - gen.output ~= format_ctfe("\"\n \""); - } - int spanLen = qMin(cast(uint)70, s.length - idx); - // don't cut escape sequences at the end of a line - int backSlashPos = s.lastIndexOf("\\", idx + spanLen - 1); - if (backSlashPos >= idx) { - int escapeLen = lengthOfEscapeSequence(s, backSlashPos); - spanLen = qBound(spanLen, backSlashPos + escapeLen - idx, cast(int)(s.length - idx)); - } - gen.output ~= s[idx..idx+spanLen]; - idx += spanLen; - col += spanLen; - } - - gen.output ~= "\\0"; - col += len + 2; - } - gen.output ~= "\";\n\n"; - - return gen.output; -} - -string metaCallArgs(Args...)() -{ - string res; - foreach(i, _; Args) { - if (i > 0) - res ~= ","; - res ~= metaCallArgument!(Args[i])("_a[" ~ __toString(i+1) ~ "]"); - } - return res; -} - -string qtDeclArgs(Args...)() -{ - string ret; - foreach(i, _; Args) - { - if(i > 0) - ret ~= ","; - ret ~= qtDeclArg!(Args[i]); - } - return ret; -} - -string generate_qt_metacall(alias Signals, alias Slots)() -{ - string res = " -protected int qt_metacall(QMetaObject.Call _c, int _id, void **_a) - { - _id = super.qt_metacall(_c, _id, _a); - if (_id < 0) - return _id;\n"; - - alias TypeTuple!(Signals.at, Slots.at) Methods; - enum methodCount = Methods.length; - if(methodCount) - { - res ~= " - if (_c == QMetaObject.Call.InvokeMetaMethod) { - switch (_id) {"; - foreach(i, _; Repeat!(void, methodCount)) { - res ~= " - case " ~ __toString(i) ~ ": " ~ MetaEntryName!(Methods[i].at) ~ "(" ~ metaCallArgs!(MetaEntryArgs!(Methods[i].at))() ~ "); break;"; - } - res ~= "\n default: ;\n }\n"; - res ~= " _id -= " ~ __toString(methodCount) ~ ";"; - res ~= "\n }"; - } - - res ~= "\n return _id; - }"; - return res; -} - -string dDeclArgs(Args...)() -{ - string ret; - foreach(i, _; Args) - { - if (i > 0) - ret ~= ", "; - ret ~= fullDName!(Args[i]); - } - return ret; -} -string genMetaMethodsConstr(alias Funcs)(string className) -{ - string res; - enum funcsCount = Funcs.at.length; - foreach(i, bogus; Repeat!(void, funcsCount)) - { - res ~= " index++;\n" ~ - " _staticMetaObject.addMethod(new " ~ className ~ "(signature!(" ~ dDeclArgs!(MetaEntryArgs!(Funcs.at[i].at))()~ ")(\"" ~ MetaEntryName!(Funcs.at[i].at) ~ "\"), index));\n\n"; - } - return res; -} -string generateMetaObjectConstruction(alias Signals, alias Slots)() -{ - string res; - res ~= "\n - private static void _populateMetaInfo() { - alias BaseClassesTuple!(typeof(this))[0] BaseClass; - int index = BaseClass.staticMetaObject().methodCount() - 1;\n\n"; - - res ~= genMetaMethodsConstr!(Signals)("QMetaSignal"); - res ~= genMetaMethodsConstr!(Slots)("QMetaSlot"); - - res ~= " - }\n"; - return res; -} - -string generateQMetaObject(string className) -{ - string res; - res ~= " - public QMetaObject metaObject() { return staticMetaObject(); } - private static __gshared QMetaObject _staticMetaObject; - private static __gshared QMetaObjectNative _nativeStaticMetaObject; - public static QMetaObject staticMetaObject() - { - if(!_staticMetaObject) - createStaticMetaObject(); - return _staticMetaObject; - } - protected static void createStaticMetaObject() { - assert(!_staticMetaObject); - alias BaseClassesTuple!(typeof(this))[0] BaseClass; - if (!BaseClass._staticMetaObject) - BaseClass.createStaticMetaObject; - auto base = BaseClass._staticMetaObject; - _nativeStaticMetaObject = QMetaObjectNative(base.nativeId, qt_meta_stringdata_" ~ className ~ ".ptr, - qt_meta_data_" ~ className ~ ".ptr, null ); - - _staticMetaObject = new QMetaObject(&_nativeStaticMetaObject, base); -// _staticMetaObject.construct!(typeof(this)); - _populateMetaInfo(); - }\n\n"; - return res; -} - -size_t commaCount(int argCount) -{ - size_t ret = 0; - if(argCount > 1) - ret = argCount - 1; - return ret; -} - -FunctionDef[] genFuncDefs(alias Funcs, alias newFunc)() -{ - typeof(return) res; - enum funcsCount = Funcs.at.length; - foreach(i, bogus; Repeat!(void, funcsCount)) - { - string args = replicate(commaCount((MetaEntryArgs!(Funcs.at[i].at)).length), ','); - string funcSig = MetaEntryName!(Funcs.at[i].at) ~ "(" ~ qtDeclArgs!(MetaEntryArgs!(Funcs.at[i].at))() ~ ")"; - res ~= newFunc(funcSig, args); - } - return res; -} - -template Q_OBJECT_BIND() -{ -} - -// ------------------------------------------------------------------------------------------ - -string generateSignalEmitters(alias Funcs)() -{ - string res; - enum funcsCount = Funcs.at.length; - foreach(i, bogus; Repeat!(void, funcsCount)) - { - res ~= SignalEmitter!(MetaEntryArgs!(Funcs.at[i].at))(SignalType.NewSignal, MetaEntryName!(Funcs.at[i].at), cast(string[])[], i); - } - return res; -} - -string generateSlotAliases(alias Funcs)() -{ - string res; - enum funcsCount = Funcs.at.length; - foreach(i, bogus; Repeat!(void, funcsCount)) - { - string name = MetaEntryName!(Funcs.at[i].at); - res ~= format_ctfe(" alias slot_${} ${};\n", name, name); - } - return res; -} - - -string generateMetaInfo(T, alias Signals, alias Slots)() -{ - string res = ""; - auto signalList = genFuncDefs!(Signals, newSignal)(); - auto slotList = genFuncDefs!(Slots, newSlot)(); - res ~= generateSignalEmitters!(Signals)(); - res ~= generateSlotAliases!(Slots)(); - res ~= generateCode(T.stringof, signalList, slotList); - res ~= generate_qt_metacall!(Signals, Slots); - res ~= generateMetaObjectConstruction!(Signals, Slots); - res ~= generateQMetaObject(T.stringof); - return res; -} - -template Q_OBJECT() -{ - alias findSignals!(typeof(this)) SignalFuncs; - alias toMetaEntries!(SignalFuncs) SignalMetaEntries; - alias findSlots!(typeof(this)) SlotFuncs; - alias toMetaEntries!(SlotFuncs) SlotMetaEntries; - - mixin(generateMetaInfo!(typeof(this), SignalMetaEntries, SlotMetaEntries)()); - // debug output -// pragma(msg, generateMetaInfo!(typeof(this), SignalMetaEntries, SlotMetaEntries)()); -} diff -r 552647ec0f82 -r 96a75b1e5b26 qt/qtd/Meta.d --- a/qt/qtd/Meta.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -module qt.qtd.Meta; - -import std.traits; -import std.typetuple; -import std.string; - -// Various compile time utilities - -public bool ctfeStartsWith(T)(T[] source, T[] pattern) -{ - return source.length >= pattern.length && source[0 .. pattern.length] == pattern[]; -} - -// compile-time toString, maybe to!string is already working in CT -string __toString(long v) -{ - if (v == 0) - return "0"; - - string ret; - - bool neg; - if (v < 0) - { - neg = true; - v = -v; - } - - while (v != 0) - { - ret = cast(char)(v % 10 + '0') ~ ret; - v = cast(long)(v / 10); - } - - if (neg) - ret = "-" ~ ret; - - return ret; -} - -// returns the type of a template parameter if there is one -template templateParam(U : V!(U), alias V) -{ - alias U templateParam; -} - -// to workaround buggy foreach, returns a tuple of Ts of size I -template Repeat(T, int I) -{ - static if (!I) alias TypeTuple!() Repeat; - else alias TypeTuple!(T, Repeat!(T, I - 1)) Repeat; -} - -//returns number of required function arguments, optional arguments excluded -int requiredArgCount(alias fn)() { - alias ParameterTypeTuple!(typeof(&fn)) P; - P p; - static if (P.length == 0) - return 0; - - foreach(i, _; P) - { - static if (!__traits(compiles, fn(p[0..$-i-1]))) - { - return p.length - i; - } - } - return 0; -} - -template isDg(Dg) -{ - enum isDg = is(Dg == delegate); -} - -template isFn(Fn) -{ - enum isFn = is(typeof(*Fn.init) == function); -} - -template isFnOrDg(Dg) -{ - enum isFnOrDg = isFn!(Dg) || isDg!(Dg); -} - -uint isModule(string str) -{ - return startsWith(str, "module "); -} - -template qualifiedCppName(T) -{ - static if(!isModule(__traits(parent, T).stringof)) - enum qualifiedCppName = qualifiedCppName!(__traits(parent, T)) ~ "::" ~ T.stringof; - else - enum qualifiedCppName = T.stringof; -} - -template qualifiedDName(T) -{ - static if (!isModule(__traits(parent, T).stringof)) - enum qualifiedDName = qualifiedDName!(__traits(parent, T)) ~ "." ~ T.stringof; - else - enum qualifiedDName = T.stringof; -} - -template fullDName(T) -{ - static if (is(T == enum)) - enum fullDName = qualifiedDName!T; - else - enum fullDName = T.stringof; -} diff -r 552647ec0f82 -r 96a75b1e5b26 qt/qtd/MetaMarshall.d --- a/qt/qtd/MetaMarshall.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,129 +0,0 @@ -module qt.qtd.MetaMarshall; - -import std.traits; - -import qt.qtd.Meta; - -template isQObjectType(T) // is a QObject type that belongs to the library -{ - enum isQObjectType = is(T.__isQObjectType); -} - -template isObjectType(T) // is a Qt Object type that belongs to the library -{ - enum isObjectType = is(T.__isObjectType); -} - -template isValueType(T) // is a Qt Value type that belongs to the library -{ - enum isValueType = is(T.__isValueType); -} - -template isQtType(T) -{ - mixin ("enum isQtType = is(T.__isQtType_" ~ T.stringof ~ ");"); -} -/* -template isQtType(T) -{ - enum isQtType = isQObjectType!(T) || isObjectType!(T) || isValueType!(T) || is(T.__isQtType); -} -*/ -template isNativeType(T) // type that doesn't require conversion i.e. is the same in C++ and D -{ - enum isNativeType = isNumeric!T || is(T == bool) || is(T == struct); -} - -template isStringType(T) // string type -{ - enum isStringType = is(T == string); -} - -template isQList(T) -{ - enum isQList = ctfeStartsWith(Unqual!(T).stringof, "QList!"); -} - -// returns full name of enum: -// for Qt enum it is in the form of QPaintDevice::PaintDeviceMetric -// for pure D enums it is Foo.Bar -template enumFullName(T) -{ - static if(!isModule(__traits(parent, T).stringof)) - { - static if(isQtType!(__traits(parent, T))) - enum enumFullName = qualifiedCppName!T; - else - enum enumFullName = qualifiedDName!T; - } - else - enum enumFullName = qualifiedDName!T; - -} - -// converts an argumnent from C++ to D in qt_metacall -string metaCallArgument(T)(string ptr) -{ - static if (isQObjectType!T || isObjectType!T) - return T.stringof ~ ".__getObject(*cast(void**)(" ~ ptr ~ "))"; - else static if (isValueType!T) - return "new " ~ T.stringof ~ "(" ~ T.stringof ~ ".__constructNativeCopy(" ~ ptr ~ "))"; - else static if (isNativeType!T) - return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")"; - else static if (isStringType!T) - return "QStringUtil.toNativeString(" ~ ptr ~ ")"; - else static if (is(T == enum)) - return "*(cast(" ~ qualifiedDName!T ~ "*)" ~ ptr ~ ")"; - else - return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")"; - //res = T.stringof; -} - -// converts a D argument type to C++ for registering in Qt meta system -string qtDeclArg(T)() -{ - static if (isQObjectType!T || isObjectType!T) - return T.stringof ~ "*"; - else static if (isValueType!T) - return T.stringof; - else static if (isStringType!T) - return "QString"; - else static if (isQList!T) - { - alias templateParam!T ElementType; - static if (is(ElementType == string)) - return "QStringList"; - else - return "QList<" ~ qtDeclArg!(templateParam!T)() ~ ">"; - } - else static if (is(T == enum)) - return enumFullName!T; - else static if (isNativeType!T) - return Unqual!T.stringof; - else - return T.stringof; -} - -// converts an argument from D to C++ in a signal emitter -string convertSignalArgument(T)(string arg) -{ - static if (isQObjectType!T || isObjectType!T) - return arg ~ " ? " "&" ~ arg ~ ".__nativeId : cast(void**) &" ~ arg; // since it is a pointer type check arg for null - else static if (isValueType!T) - return arg ~ ".__nativeId"; - else static if (isStringType!T) - return "&_qt" ~ arg; - else static if (isNativeType!T) - return "&" ~ arg; - else - return "&" ~ arg; -} - -string prepareSignalArguments(Args...)() -{ - string res; - foreach(i, _; Args) - static if (isStringType!(Args[i])) - res ~= "auto _qt_t" ~ __toString(i) ~ " = QString(_t" ~ __toString(i) ~ ");\n"; - return res; -} diff -r 552647ec0f82 -r 96a75b1e5b26 qt/qtd/Traits.d --- a/qt/qtd/Traits.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -module qt.qtd.Traits; - -version (D_Version2) -{ - public import std.traits; -} -else -{ - public import tango.core.Traits : BaseTypeTuple = BaseTypeTupleOf; -} diff -r 552647ec0f82 -r 96a75b1e5b26 qt/qtd/ctfe/Format.d --- a/qt/qtd/ctfe/Format.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,693 +0,0 @@ -/** - * Compile-Time String Formatting. - * - * Authors: Daniel Keep - * Copyright: See LICENSE. - */ -module qt.qtd.ctfe.Format; - -//debug = gb_Format_verbose; - -import Integer = qt.qtd.ctfe.Integer; -import String = qt.qtd.ctfe.String; -import Tuple = qt.qtd.util.Tuple; - -private -{ - string stringify(Args...)(size_t index, int alignment, - string opt, Args args) - { - if( index >= args.length ) - return "{invalid index " ~ Integer.format_ctfe(index) ~ "}"; - - if( alignment != 0 ) - return "{non-zero alignments not supported yet}"; - - foreach( i,_ ; Args ) - { - if( i == index ) - { - static if( is( Args[i] == char ) ) - { - string r; - r ~= args[i]; - return r; - } - else static if( is( Args[i] : long ) || is( Args[i] : ulong ) ) - { - int base = 10; - string prefix = ""; - - if( opt == "x" ) - base = 16; - - else if( opt == "xx" ) - { - base = 16; - prefix = "0x"; - } - else if( opt == "o" ) - base = 8; - - else if( opt == "b" ) - base = 2; - - return prefix ~ Integer.format_ctfe(args[i], base); - } - else static if( is( Args[i] : string ) ) - { - if( opt == "x" ) - { - return String.hexify_ctfe(args[i][]); - } - - if( opt == "q" ) - { - return String.escape_ctfe(args[i][]); - } - - if( opt == "l" ) - { - return Integer.format_ctfe(args[i].length); - } - - // If you don't slice, then the CALLER has to slice the - // string, otherwise CTFE barfs. - return args[i][]; - } - else static if( is( Args[i] Elem : Elem[] ) ) - { - if( opt == "l" ) - { - return Integer.format_ctfe(args[i].length); - } - - string r = "["; - foreach( ei, e ; args[i][] ) - { - if( ei != 0 ) - r ~= ", "; - r ~= stringify(0, alignment, opt, e); - } - r ~= "]"; - return r; - } - else - { - return "{cannot stringify "~Args[i].stringof~"}"; - } - } - } - - assert(false); - } - - version( Unittest ) - { - static assert( stringify(0, 0, "", 0) == "0" ); - static assert( stringify(0, 0, "", 1, -2, "abc") == "1" ); - static assert( stringify(1, 0, "", 1, -2, "abc") == "-2" ); - static assert( stringify(2, 0, "", 1, -2, "abc") == "abc" ); - - static assert( stringify(0, 0, "x", "abc") == `616263` ); - static assert( stringify(0, 0, "q", "abc") == `"abc"` ); - static assert( stringify(0, 0, "l", "abc") == `3` ); - - static assert( stringify(0, 0, "x", 0x4a) == "4a" ); - - static assert( stringify(0, 0, "", [1,2,3]) == "[1, 2, 3]" ); - static assert( stringify(0, 0, "l", [1,2,3]) == "3" ); - static assert( stringify(0, 0, "x", [9,10]) == "[9, a]" ); - static assert( stringify(0, 0, "", ["a","b"]) == "[a, b]" ); - static assert( stringify(0, 0, "q", ["a","b"]) == "[\"a\", \"b\"]" ); - - static assert( stringify(0, 0, "", 'a') == "a" ); - } -} - -/** - * Substitutes a set of arguments into a template string. - * - * The template string allows for the following escape forms: - * - * - $$ -- Literal dollar. - * - $* -- Next argument. - * - $n -- nth argument; 0-9 only. - * - ${} -- Next argument. - * - ${:f} -- Next argument, using format options "f". - * - ${n} -- nth argument. - * - ${n:f} -- nth argument, using format options "f". - * - * formatNamed allows the use of named arguments (given as alternating - * name,value pairs), but disallows "next" argument and indexed forms. - * - * Eventually, alignment and named arguments will be supported. - * - * Supported formatting options are: - * - * Integers: - * - x -- format integer in hexadecimal. - * - o -- format integer in octal. - * - b -- format integer in binary. - * - * Strings: - * - q -- quotes the string as a literal. - * - x -- formats as hexadecimal data. - * - l -- length of the string in decimal. - * - * Arrays: - * - l -- length of the array in decimal. - * - Other options are used to control element formatting. - * - * Params: - * tmpl = template string. - * args = arguments to substitute. - * Returns: - * formatted string. - */ - -string format_ctfe(Args...)(string tmpl, Args args) -{ - string r = ""; - int argPos = 0; - - while( tmpl.length > 0 ) - { - bool inExp = false; - - // Look for a $ - foreach( i,c ; tmpl ) - { - if (c == '$') - { - inExp = true; - r ~= tmpl[0..i]; - tmpl = tmpl[i+1..$]; - break; - } - } - - // If we didn't find a $, it's because we hit the end of the template. - if( !inExp ) - { - r ~= tmpl; - break; - } - - // So we're in an expansion/substitution. - - debug(gb_Format_verbose) r ~= "{in exp}"; - - if( tmpl.length == 0 ) - { - r ~= "{unterminated substitution}"; - break; - } - - // c is the next character, whilst tmpl is everything left in the - // template string. - char c = tmpl[0]; - tmpl = tmpl[1..$]; - - // $$ - escaped $. - if( c == '$' ) - { - debug(gb_Format_verbose) r ~= "{escaped $}"; - r ~= '$'; - continue; - } - - // $n - shortcut for ${n}. - if( '0' <= c && c <= '9' ) - { - debug(gb_Format_verbose) r ~= "{shorthand index}"; - r ~= stringify(c-'0', 0, "", args); - continue; - } - - // $* - shortcut for ${} - if( c == '*' ) - { - debug(gb_Format_verbose) r ~= "{shorthand next}"; - r ~= stringify(argPos++, 0, "", args); - continue; - } - - // This means we got a $ followed by something unexpected. - if( c != '{' ) - { - r ~= "{malformed substitution}"; - break; - } - - if( tmpl.length == 0 ) - { - r ~= "{unterminated substitution}"; - break; - } - - debug(gb_Format_verbose) - { - r ~= "{parse complex at '"; - r ~= c; - r ~= "':\"" ~ tmpl ~ "\"}"; - } - - // NOTE: We haven't updated c and tmpl yet. - - { - // arg will contain the index of the argument the user wanted - // substituted. - size_t arg = size_t.max; - // fmt will contain any additional formatting options. - string fmt = ""; - - // If we didn't get a : or }, that means we expect an index. - if( !( tmpl[0] == ':' || tmpl[0] == '}' ) ) - { - // So parse it. - auto used = Integer.parse_ctfe!(size_t)(tmpl, true); - - if( used == 0 ) - { - debug(gb_Format_verbose) r ~= "{used zero of \""~tmpl~"\"}"; - r ~= "{invalid argument index}"; - break; - } - - arg = Integer.parse_ctfe!(size_t)(tmpl); - tmpl = tmpl[used..$]; - - if( tmpl.length == 0 ) - { - r ~= "{unterminated substitution}"; - break; - } - } - else - { - // Otherwise, the index was elided, which means we want to use - // the index of the "next" argument. - arg = argPos; - ++ argPos; - } - - c = tmpl[0]; - tmpl = tmpl[1..$]; - - debug(gb_Format_verbose) - r ~= "{index " ~ Integer.format_ctfe(arg) ~ "}"; - - // If c is :, then we've got formatting options to parse - - if( c == ':' ) - { - debug(gb_Format_verbose) r ~= "{fmt string}"; - - // Look for the closing }. - size_t len = 0; - foreach( i,d ; tmpl ) - { - if( d == '}' ) - { - len = i; - break; - } - } - if( len == 0 ) - { - r ~= "{malformed format}"; - break; - } - fmt = tmpl[0..len]; - tmpl = tmpl[len..$]; - - if( tmpl.length == 0 ) - { - r ~= "{unterminated substitution}"; - break; - } - - c = tmpl[0]; - tmpl = tmpl[1..$]; - } - - // At this point, we should have the closing }. If not, someone's - // screwed up. - if( c != '}' ) - { - debug(gb_Format_verbose) - { - r ~= "{expected closing; got '"; - r ~= c; - r ~= "':\"" ~ tmpl ~ "\"}"; - } - r ~= "{malformed substitution}"; - break; - } - - // Stringify that bugger. - r ~= stringify(arg, 0, fmt, args); - - // When we fall off the end here, we'll continue with the - // remainder of tmpl, unless it's empty in which case we're - // finished. - } - } - - return r; -} - -version( Unittest ) -{ - static assert(format_ctfe("A: $$", "foo"[]) == "A: $"); - static assert(format_ctfe("B: a $$ c", "b"[]) == "B: a $ c"); - - static assert(format_ctfe("C: ${}", "foo"[]) == "C: foo"); - static assert(format_ctfe("D: a ${} c", "b"[]) == "D: a b c"); - - static assert(format_ctfe("E: $0", "foo"[]) == "E: foo"); - static assert(format_ctfe("F: a $0 c", "b"[]) == "F: a b c"); - - static assert(format_ctfe("G: $*", "foo"[]) == "G: foo"); - static assert(format_ctfe("H: a $* c", "b"[]) == "H: a b c"); - - static assert(format_ctfe("I: ${0}", "foo"[]) == "I: foo"); - static assert(format_ctfe("J: a ${0} c", "b"[]) == "J: a b c"); - - static assert(format_ctfe("K: ${} ${} ${}", 1, -2, "c"[]) == "K: 1 -2 c"); - static assert(format_ctfe("L: $* $* $*", 1, -2, "c"[]) == "L: 1 -2 c"); - static assert(format_ctfe("M: $0 $1 $2", 1, -2, "c"[]) == "M: 1 -2 c"); - static assert(format_ctfe("N: ${0} ${1} ${2}", 1, -2, "c"[]) == "N: 1 -2 c"); - - static assert(format_ctfe("O: ${2} ${0} ${1}", 1, -2, "c"[]) == "O: c 1 -2"); - - static assert(format_ctfe("P: ${:x} ${0:x} ${0:o} ${0:b}", 42) == "P: 2a 2a 52 101010"); - - static assert(format_ctfe("Q: ${0} ${0:q} ${0:x}", "abc"[]) == "Q: abc \"abc\" 616263"); - static assert(format_ctfe("R: ${0} ${0:q}", ["a","b","c"][]) == "R: [a, b, c] [\"a\", \"b\", \"c\"]"); - - const TORTURE_TMPL = ` - struct $*Enum - { - const Name = ${0:q}; - const string[${:l}] Members = ${1:q}; - - ${2} value() - { - return ${3:xx}; - } - } - `[]; - - const TORTURE_EXPECTED = ` - struct FooEnum - { - const Name = "Foo"; - const string[3] Members = ["bar", "quxx", "zyzzy"]; - - int value() - { - return 0x42; - } - } - `[]; - - const TORTURE_ACTUAL = format_ctfe(TORTURE_TMPL, - "Foo"[], ["bar"[],"quxx","zyzzy"][], - "int"[], 0x42); - - static assert( TORTURE_EXPECTED == TORTURE_ACTUAL ); -} - -private -{ - size_t findIndexByName(Args...)(string name, Args args) - { - foreach( i ; Tuple.Sequence!(0, Args.length, 2) ) - { - static if( !is( Args[i] : string ) ) - { - static assert(false, "expected string for argument " - ~ Integer.format_ctfe(i) ~ " in " ~ Args.stringof - ~ " not " ~ Args[i].stringof); - } - if( name == args[i][] ) - return i+1; - } - return size_t.max; - } - - version( Unittest ) - { - static assert( findIndexByName("a", "a", 0, "b", 1) == 1 ); - static assert( findIndexByName("b", "a", 0, "b", 1) == 3 ); - static assert( findIndexByName("c", "a", 0, "b", 1) == size_t.max ); - } -} - -/// ditto - -string formatNamed_ctfe(Args...)(string tmpl, Args args) -{ - string r = ""; - int argPos = 0; - - while( tmpl.length > 0 ) - { - bool inExp = false; - - // Look for a $ - foreach( i,c ; tmpl ) - { - if (c == '$') - { - inExp = true; - r ~= tmpl[0..i]; - tmpl = tmpl[i+1..$]; - break; - } - } - - // If we didn't find a $, it's because we hit the end of the template. - if( !inExp ) - { - r ~= tmpl; - break; - } - - // So we're in an expansion/substitution. - - debug(gb_Format_verbose) r ~= "{in exp}"; - - if( tmpl.length == 0 ) - { - r ~= "{unterminated substitution}"; - break; - } - - // c is the next character, whilst tmpl is everything left in the - // template string. - char c = tmpl[0]; - tmpl = tmpl[1..$]; - - // $$ - escaped $. - if( c == '$' ) - { - debug(gb_Format_verbose) r ~= "{escaped $}"; - r ~= '$'; - continue; - } - - // $a... - shortcut for $a... - if( String.isIdentStartChar_ctfe(c) ) - { - debug(gb_Format_verbose) r ~= "{shorthand name}"; - size_t i = 0; - while( i < tmpl.length ) - { - if( !String.isIdentChar_ctfe(tmpl[i]) ) - break; - ++ i; - } - string name = c ~ tmpl[0..i]; - tmpl = tmpl[i..$]; - r ~= stringify(findIndexByName(name, args), 0, "", args); - continue; - } - - // This means we got a $ followed by something unexpected. - if( c != '{' ) - { - r ~= "{malformed substitution}"; - break; - } - - if( tmpl.length == 0 ) - { - r ~= "{unterminated substitution}"; - break; - } - - debug(gb_Format_verbose) - { - r ~= "{parse complex at '"; - r ~= c; - r ~= "':\"" ~ tmpl ~ "\"}"; - } - - // NOTE: We haven't updated c and tmpl yet. - - { - // arg will contain the index of the argument the user wanted - // substituted. - size_t arg = size_t.max; - // fmt will contain any additional formatting options. - string fmt = ""; - - // If we didn't get a : or }, that means we expect a name. - if( !( tmpl[0] == ':' || tmpl[0] == '}' ) ) - { - // So parse it. - size_t i = 0; - while( i < tmpl.length ) - { - if( !String.isIdentChar_ctfe(tmpl[i]) ) - break; - ++ i; - } - string name = tmpl[0..i]; - tmpl = tmpl[i..$]; - - arg = findIndexByName(name, args); - - if( tmpl.length == 0 ) - { - r ~= "{unterminated substitution}"; - break; - } - } - else - { - // Otherwise, the name was elided. Kaboom! - r ~= "{substitution missing name}"; - break; - } - - c = tmpl[0]; - tmpl = tmpl[1..$]; - - debug(gb_Format_verbose) - r ~= "{index " ~ Integer.format_ctfe(arg) ~ "}"; - - // If c is :, then we've got formatting options to parse - - if( c == ':' ) - { - debug(gb_Format_verbose) r ~= "{fmt string}"; - - // Look for the closing }. - size_t len = 0; - foreach( i,d ; tmpl ) - { - if( d == '}' ) - { - len = i; - break; - } - } - if( len == 0 ) - { - r ~= "{malformed format}"; - break; - } - fmt = tmpl[0..len]; - tmpl = tmpl[len..$]; - - debug(gb_Format_verbose) r ~= "{fmt:"~fmt~"}"; - - if( tmpl.length == 0 ) - { - r ~= "{unterminated substitution}"; - break; - } - - c = tmpl[0]; - tmpl = tmpl[1..$]; - } - - // At this point, we should have the closing }. If not, someone's - // screwed up. - if( c != '}' ) - { - debug(gb_Format_verbose) - { - r ~= "{expected closing; got '"; - r ~= c; - r ~= "':\"" ~ tmpl ~ "\"}"; - } - r ~= "{malformed substitution}"; - break; - } - - // Stringify that bugger. - r ~= stringify(arg, 0, fmt, args); - - // When we fall off the end here, we'll continue with the - // remainder of tmpl, unless it's empty in which case we're - // finished. - } - } - - return r; -} - -version( Unittest ) -{ - static assert( formatNamed_ctfe("A: $$", "a"[], 0, "b"[], 1) == "A: $" ); - static assert( formatNamed_ctfe("B: $a", "a"[], 0, "b"[], 1) == "B: 0" ); - static assert( formatNamed_ctfe("C: $b", "a"[], 0, "b"[], 1) == "C: 1" ); - - static assert( formatNamed_ctfe("D: ${a}", "a"[], 0, "b"[], 1) == "D: 0" ); - static assert( formatNamed_ctfe("E: ${b}", "a"[], 0, "b"[], 1) == "E: 1" ); - - static assert( formatNamed_ctfe("F: $foo$bar", "foo"[], 0, "bar"[], 1) == "F: 01" ); - static assert( formatNamed_ctfe("G: ${foo}${bar}", "foo"[], 0, "bar"[], 1) == "G: 01" ); - - static assert( formatNamed_ctfe("H: ${foo:x}${bar:xx}", "foo"[], 0, "bar"[], 1) == "H: 00x1" ); - - const TORTURE_NAMED_TMPL = ` - struct ${name}Enum - { - const Name = ${name:q}; - const string[${members:l}] Members = ${members:q}; - - ${retType} value() - { - return ${value:xx}; - } - } - `[]; - - const TORTURE_NAMED_EXPECTED = ` - struct FooEnum - { - const Name = "Foo"; - const string[3] Members = ["bar", "quxx", "zyzzy"]; - - int value() - { - return 0x42; - } - } - `[]; - - const TORTURE_NAMED_ACTUAL = formatNamed_ctfe(TORTURE_NAMED_TMPL, - "name"[], "Foo"[], - "members"[], ["bar"[],"quxx","zyzzy"][], - "retType"[], "int"[], - "value"[], 0x42); - - static assert( TORTURE_NAMED_EXPECTED == TORTURE_NAMED_ACTUAL ); -} - diff -r 552647ec0f82 -r 96a75b1e5b26 qt/qtd/ctfe/Integer.d --- a/qt/qtd/ctfe/Integer.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,169 +0,0 @@ -/** - * CTFE Integer routines. - * - * Authors: Daniel Keep - * Copyright: See LICENSE. - */ -module qt.qtd.ctfe.Integer; - -/** - * Formats an integer as a string. You can optionally specify a different - * base; any value between 2 and 16 inclusive is supported. - * - * Params: - * v = value to format. - * base = base to use; defaults to 10. - * Returns: - * integer formatted as a string. - */ - -string format_ctfe(intT)(intT v, int base = 10) -{ - static if( !is( intT == ulong ) ) - { - return (v < 0) - ? "-" ~ format_ctfe(cast(ulong) -v, base) - : format_ctfe(cast(ulong) v, base); - } - else - { - assert( 2 <= base && base <= 16, - "base must be between 2 and 16; got " ~ format_ctfe(base, 10) ); - - string r = ""; - do - { - r = INT_CHARS[cast(size_t)(v % base)] ~ r; - v /= base; - } - while( v > 0 ); - return r; - } -} - -/** - * Parses an integer value from a string. You can optionally specify a - * different base; any value between 2 and 16 inclusive is supported. - * - * Note that this does not fail if it cannot consume the entire string; - * use returnUsed to determine the number of characters consumed. - * - * Params: - * str = string to parse. - * returnUsed = defaults to false; if set to true, returns the number of - * characters consumed from the string instead of the - * parsed value. - * base = base to use; defaults to 10. - * Returns: - * either the parsed integer or the number of characters consumed, - * depending on the value of returnUsed. - */ - -intT parse_ctfe(intT)(string str, bool returnUsed = false, int base = 10) -{ - auto origStr = str; - - assert( 2 <= base && base <= 16, - "base must be between 2 and 16; got " ~ format_ctfe(base, 10) ); - - bool neg = false; - if( str.length > 0 && str[0] == '-' ) - { - neg = true; - str = str[1..$]; - } - - if( intT.min == 0 && neg ) - assert(false, "underwhile while parsing \"" ~ origStr - ~ "\" as a " ~ intT.stringof ~ ": cannot represent negative " - ~ "values"); - - intT r = 0; - size_t used = 0; - - foreach( c ; str ) - { - int cv = -1; - - if( '0' <= c && c <= '9' ) - cv = c - '0'; - - else if( 'A' <= c && c <= 'Z' ) - cv = 10 + c - 'A'; - - else if( 'a' <= c && c <= 'z' ) - cv = 10 + c - 'a'; - - if( cv >= base || cv < 0 ) - break; - - auto oldR = r; - r = r*base + cast(intT) cv; - ++ used; - - if( r < oldR ) - assert(false, "overflow while parsing \"" ~ origStr - ~ "\" as a " ~ intT.stringof); - } - - if( neg ) - { - r = -r; - ++used; - } - - if( returnUsed ) - { - assert( used < intT.max, "overflow attempting to return " - ~ "number of characters consumed in a " ~ intT.stringof ); - - return used; - } - else - return r; -} - -/** - * Like parse_ctfe, except it will raise an error if the provided string - * cannot be parsed in its entirety. - * - * Params: - * str = the string to parse. - * base = base to use; defaults to 10. - * Returns: - * the parsed integer. - */ - -intT parseAll_ctfe(intT)(string str, int base = 10) -{ - auto used = parse_ctfe!(intT)(str, true, base); - assert( used == str.length, "could not parse entire string \"" ~ str - ~ "\"" ); - return parse_ctfe!(int)(str, false, base); -} - -private -{ - const INT_CHARS = "0123456789abcdef"; -} - -version( Unittest ) -{ - static assert( format_ctfe(0) == "0", "got: " ~ format_ctfe(0) ); - static assert( format_ctfe(1) == "1" ); - static assert( format_ctfe(-1) == "-1" ); - static assert( format_ctfe(42) == "42" ); - static assert( format_ctfe(0xf00, 16) == "f00" ); - static assert( format_ctfe(0123, 8) == "123" ); - - static assert( parse_ctfe!(long)("0") == 0 ); - static assert( parse_ctfe!(long)("1") == 1 ); - static assert( parse_ctfe!(long)("-1") == -1 ); - static assert( parse_ctfe!(long)("42") == 42 ); - static assert( parse_ctfe!(long)("f00", false, 16) == 0xf00 ); - static assert( parse_ctfe!(long)("123", false, 8) == 0123 ); - static assert( parse_ctfe!(long)("123ax", true) == 3 ); - static assert( parse_ctfe!(long)("123ax", true, 16) == 4 ); - - static assert( parseAll_ctfe!(long)("123") == 123 ); -} diff -r 552647ec0f82 -r 96a75b1e5b26 qt/qtd/ctfe/String.d --- a/qt/qtd/ctfe/String.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,317 +0,0 @@ -/** - * CTFE String routines. - * - * Authors: Daniel Keep - * Copyright: See LICENSE. - */ -module qt.qtd.ctfe.String; - -import Integer = qt.qtd.ctfe.Integer; - -private -{ - const HEX_CHARS = "0123456789abcdef"; -} - -/** - * Escapes a string into an equivalent string literal. - * - * Params: - * str = string to escape. - * aggressive = if set, the function will escape all non-printing - * characters, non-space whitespace and newlines. Defaults - * to true. - * Returns: - * Escaped string literal. - */ -string escape_ctfe(string str, bool aggressive=true) -{ - string head = ""; - - foreach( i,c ; str ) - { - if( c == '"' || c == '\\' || c == '\0' ) - { - head = "\""~str[0..i]; - str = str[i..$]; - break; - } - - if( aggressive ) - { - if( c < 0x20 || c == 0x7f ) - { - head = "\""~str[0..i]; - str = str[i..$]; - break; - } - } - } - - if( head.length == 0 ) - return "\"" ~ str ~ "\""; - - string tail = ""; - - foreach( c ; str ) - { - if( c == '"' ) - tail ~= `\"`; - - else if( c == '\\' ) - tail ~= "\\\\"; - - else if( c == '\0' ) - tail ~= `\0`; - - else if( aggressive ) - { - switch( c ) - { - case '\?': - tail ~= `\?`; - break; - - case '\a': - tail ~= `\a`; - break; - - case '\b': - tail ~= `\b`; - break; - - case '\f': - tail ~= `\f`; - break; - - case '\n': - tail ~= `\n`; - break; - - case '\r': - tail ~= `\r`; - break; - - case '\t': - tail ~= `\t`; - break; - - case '\v': - tail ~= `\v`; - break; - - default: - if( c < 0x20 || c == 0x75 ) - { - tail ~= `\x`; - tail ~= HEX_CHARS[c/0xf]; - tail ~= HEX_CHARS[c&0xf]; - } - else - tail ~= c; - } - } - else - tail ~= c; - } - - return head ~ tail ~ "\""; -} - -version( Unittest ) -{ - static assert( escape_ctfe("abc") == "\"abc\"" ); - static assert( escape_ctfe("a\"c") == "\"a\\\"c\"" ); -} - -/** - * Turns an array of bytes into a hexadecimal string. - * - * Params: - * arr = array to hexify. - * grouping = if non-zero, specifies after how many bytes to insert a - * space. - * Returns: - * String of hex bytes. - */ - -string hexify_ctfe(ubyte[] arr, int grouping = 0) -{ - string r = ""; - int bytes = grouping; - foreach( b ; arr ) - { - if( bytes == 0 && grouping > 0 ) - { - r ~= ' '; - bytes = grouping; - } - - auto bh = b/16; - auto bl = b&15; - - assert( bh < 16 ); - assert( bl < 16 ); - - r ~= HEX_CHARS[bh]; - r ~= HEX_CHARS[bl]; - - if( grouping > 0 ) - -- bytes; - } - return r; -} - -/// ditto - -string hexify_ctfe(string arr, int grouping = 0) -{ - string r = ""; - int bytes = grouping; - foreach( b ; arr ) - { - if( bytes == 0 && grouping > 0 ) - { - r ~= ' '; - bytes = grouping; - } - - auto bh = b/16; - auto bl = b&15; - - assert( bh < 16 ); - assert( bl < 16 ); - - r ~= HEX_CHARS[bh]; - r ~= HEX_CHARS[bl]; - - if( grouping > 0 ) - -- bytes; - } - return r; -} - -version( Unittest ) -{ - static const ubyte[] DATA_1 = [0x00,0x01,0x02,0x03]; - static const ubyte[] DATA_2 = [0x0f,0x10,0xef,0xf0]; - - static assert( hexify_ctfe(DATA_1) == "00010203" ); - static assert( hexify_ctfe(DATA_2) == "0f10eff0" ); - - static assert( hexify_ctfe(DATA_1, 1) == "00 01 02 03" ); - static assert( hexify_ctfe(DATA_2, 1) == "0f 10 ef f0" ); - - static assert( hexify_ctfe(DATA_1, 2) == "0001 0203" ); - static assert( hexify_ctfe(DATA_2, 2) == "0f10 eff0" ); - - static assert( hexify_ctfe(DATA_1, 4) == "00010203" ); - static assert( hexify_ctfe(DATA_2, 4) == "0f10eff0" ); -} - -/** - * Pads a string. padl adds padding to the left, padr adds it to the right. - * Params: - * str = string to pad. - * len = length to pad to. - * padding = character to use for padding. Defaults to space. - * Returns: - * padded string. - */ - -string padl_ctfe(string str, int len, char padding = ' ') -{ - while( str.length < len ) - str = padding ~ str; - return str; -} - -/// ditto - -string padr_ctfe(string str, int len, char padding = ' ') -{ - while( str.length < len ) - str ~= padding; - return str; -} - -version( Unittest ) -{ - static assert( padl_ctfe("abc", 2) == "abc" ); - static assert( padl_ctfe("abc", 3) == "abc" ); - static assert( padl_ctfe("abc", 4) == " abc" ); - static assert( padl_ctfe("abc", 4, 'x') == "xabc" ); - - static assert( padr_ctfe("abc", 2) == "abc" ); - static assert( padr_ctfe("abc", 3) == "abc" ); - static assert( padr_ctfe("abc", 4) == "abc " ); - static assert( padr_ctfe("abc", 4, 'x') == "abcx" ); -} - -/** - * Returns the tail of a string after a given splitting character. The Rev - * variant returns the tail after the last instance of the splitting - * character. - */ - -string tail_ctfe(string str, char split) -{ - foreach( i,c ; str ) - { - if( c == split ) - return str[i+1..$]; - } - return str; -} - -/// ditto - -string tailRev_ctfe(string str, char split) -{ - foreach_reverse( i,c ; str ) - { - if( c == split ) - return str[i+1..$]; - } - return str; -} - -/** - * Determines whether a character is valid in an identifier in a - * non-initial position. - * - * Does not support the full range of valid D identifier characters. - */ - -bool isIdentChar_ctfe(char c) -{ - return ('a' <= c && c <= 'z') - || ('A' <= c && c <= 'Z') - || ('0' <= c && c <= '9') - || (c == '_'); -} - -/** - * Determines whether a character is valid in an identifier in an - * initial position. - * - * Does not support the full range of valid D identifier characters. - */ - -bool isIdentStartChar_ctfe(char c) -{ - return ('a' <= c && c <= 'z') - || ('A' <= c && c <= 'Z') - || (c == '_'); -} - -/** - * Returns a line spec suitable for mixing in. This can be used with string - * mixins to ensure compile errors appear on the "correct" line in the source. - */ - -string linespec_ctfe(string file, long line) -{ - return "#line "~Integer.format_ctfe(line)~" \"" ~ file ~ "\"\n"; -} - diff -r 552647ec0f82 -r 96a75b1e5b26 qt/qtd/util/Tuple.d --- a/qt/qtd/util/Tuple.d Thu May 13 21:01:24 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/** - * Tuple-related stuff. - * - * Authors: Daniel Keep - * Copyright: See LICENSE. - */ -module qt.qtd.util.Tuple; - -import std.typetuple; - -/** - * Sequence can be used to generate a tuple of integer values. It can be - * used in one of three forms: - * - * ----- - * Sequence!(6) // ==> (0, 1, 2, 3, 4, 5) - * Sequence!(1,6) // ==> (1, 2, 3, 4, 5) - * Sequence!(1,6,2) // ==> (1, 3, 5) - * ----- - */ - -template Sequence(int max) -{ - static if( max <= 0 ) - alias TypeTuple!() Sequence; - else - alias TypeTuple!(Sequence!(max-1), max-1) Sequence; -} - -/// ditto - -template Sequence(int min, int max) -{ - static if( max <= min ) - alias TypeTuple!() Sequence; - else - alias TypeTuple!(Sequence!(min, max-1), max-1) Sequence; -} - -/// ditto - -template Sequence(int min, int max, int stride) -{ - static if( min >= max ) - alias TypeTuple!() Sequence; - else - alias TypeTuple!(min, Sequence!(min+stride, max, stride)) Sequence; -} - -version( Unittest ) -{ - static assert( Sequence!(3)[0] == 0 ); - static assert( Sequence!(3)[1] == 1 ); - static assert( Sequence!(3)[2] == 2 ); - static assert( Sequence!(3).length == 3 ); - - static assert( Sequence!(1, 3)[0] == 1 ); - static assert( Sequence!(1, 3)[1] == 2 ); - static assert( Sequence!(1, 3).length == 2 ); - - static assert( Sequence!(1, 5, 2)[0] == 1 ); - static assert( Sequence!(1, 5, 2)[1] == 3 ); - static assert( Sequence!(1, 5, 2).length == 2 ); -}