Compare commits

..
Author SHA1 Message Date
Chris HORLER 86064385df test PR integration 2021-09-16 13:58:38 +01:00
239 changed files with 4248 additions and 14667 deletions
+5 -7
View File
@@ -1,8 +1,6 @@
name: STEPCODE
on:
workflow_dispatch:
pull_request:
on: [push]
jobs:
windows:
@@ -185,9 +183,9 @@ jobs:
- name: Checkout
run: |
git clone --depth 1 https://github.com/BRL-CAD/brlcad.git -b main
git clone --depth 1 git://github.com/BRL-CAD/brlcad.git -b main
cd brlcad/src/other/ext && rm -rf stepcode
git clone --depth 1 https://github.com/stepcode/stepcode.git -b develop
git clone --depth 1 git://github.com/stepcode/stepcode.git -b develop
# Ordinarily BRL-CAD keeps track of what files are supposed to be
# present in the repository. In this case we're not interested in
# updating the list to the working stepcode filelist, so use an empty
@@ -242,10 +240,10 @@ jobs:
- name: Checkout
run: |
git clone --depth 1 https://github.com/BRL-CAD/brlcad.git -b main
git clone --depth 1 git://github.com/BRL-CAD/brlcad.git -b main
cd brlcad/src/other/ext
cmake -E rm -r stepcode
git clone --depth 1 https://github.com/stepcode/stepcode.git -b develop
git clone --depth 1 git://github.com/stepcode/stepcode.git -b develop
# Ordinarily BRL-CAD keeps track of what files are supposed to be
# present in the repository. In this case we're not interested in
# updating the list to the working stepcode filelist, so use an empty
-1
View File
@@ -10,7 +10,6 @@
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
**/__pycache__/
# OS specific files
.DS_Store
-1
View File
@@ -19,7 +19,6 @@ Paviot, Thomas (tpaviot)
Pictor, Mark (mpictor)
Reed, Nick (nickreed)
Shah, Kesha (kesha, keshashah)
Sparks, Devon (devonsparks)
Thomas, Dawn (homovulgaris, madant)
Wouters, Dave (davyw)
Yapp, Clifford (starseeker)
+7 -1
View File
@@ -120,6 +120,7 @@ option(BUILD_STATIC_LIBS "Build static libraries" OFF)
option(SC_PYTHON_GENERATOR "Compile exp2python" ON)
option(SC_CPP_GENERATOR "Compile exp2cxx" ON)
option(SC_MEMMGR_ENABLE_CHECKS "Enable sc_memmgr's memory leak detection" OFF)
option(SC_TRACE_FPRINTF "Enable extra comments in generated code so the code's source in exp2cxx may be located" OFF)
option(SC_ENABLE_COVERAGE "Enable code coverage test" OFF)
@@ -152,7 +153,7 @@ include(SC_Locale)
# logic related to regenerating the lexer and parser source code
include(SC_Regenerate)
# create config.h header
# create config header sc_cf.h
include(SC_Config_Headers)
if(NOT DEFINED SC_SDAI_ADDITIONAL_EXES_SRCS)
@@ -173,6 +174,10 @@ if(NOT SC_IS_SUBBUILD)
".. Generating step can take a while if you are building several schemas.")
endif(NOT SC_IS_SUBBUILD)
# create config headers sc_cf.h
include(SC_Config_Headers)
################
if(MSVC)
@@ -188,6 +193,7 @@ include_directories(
${SC_BINARY_DIR}/include
)
add_subdirectory(src/base)
add_subdirectory(src/express)
add_subdirectory(src/exppp)
add_subdirectory(src/exp2cxx)
+1 -4
View File
@@ -11,12 +11,9 @@ We love contributions!
* Encouraged but not enforced: each commit should stand alone, in the sense that the code should compile and run at that point.
* One major topic per pull request. Commits that fix small things (typos, formatting) are perfectly acceptable in a PR fixing a bug or adding a feature.
* Tests are good. Tests are required unless you're fixing something simple or that was obviously broken.
* Do not change EXPRESS schema definition without reference to an upstream change.
* Make your changes and push them to your GitHub repo
* Once your branch is pushed, submit a pull request.
- enable github option on each PR 'Allow edits from maintainers', refer to github help if necessary
* We'll look at the PR and either merge (possibly after rebase) or add feedback.
- If there isn't any activity within several days send a message to the mailing list - `scl-dev` AT `groups.google.com`.
* We'll look at the PR and either merge or add feedback. If there isn't any activity within several days, send a message to the mailing list - `scl-dev` AT `groups.google.com`.
## Coding Standards
+2
View File
@@ -3,6 +3,8 @@
***********************************************************************
STEPcode v0.8 -- github.com/stepcode/stepcode
* test PR integration
* What is STEPcode? SC reads ISO10303-11 EXPRESS schemas and generates
C++ source code that can read and write Part 21 files conforming
to that schema. In addition to C++, SC includes experimental
+8 -8
View File
@@ -27,16 +27,16 @@ endmacro(P21_TESTS sfile)
# create p21read_sdai_*, lazy_sdai_*, any exes listed in SC_SDAI_ADDITIONAL_EXES_SRCS
macro(SCHEMA_EXES)
RELATIVE_PATH_TO_TOPLEVEL(${CMAKE_CURRENT_SOURCE_DIR} RELATIVE_PATH_COMPONENT)
SC_ADDEXEC(p21read_${PROJECT_NAME} SOURCES "${RELATIVE_PATH_COMPONENT}/src/test/p21read/p21read.cc;${RELATIVE_PATH_COMPONENT}/src/test/p21read/sc_benchmark.cc" LINK_LIBRARIES ${PROJECT_NAME} stepdai stepcore stepeditor steputils TESTABLE)
SC_ADDEXEC(p21read_${PROJECT_NAME} SOURCES "${RELATIVE_PATH_COMPONENT}/src/test/p21read/p21read.cc" LINK_LIBRARIES ${PROJECT_NAME} stepdai stepcore stepeditor steputils base TESTABLE)
if(NOT WIN32)
SC_ADDEXEC(lazy_${PROJECT_NAME} SOURCES "${RELATIVE_PATH_COMPONENT}/src/cllazyfile/lazy_test.cc;${RELATIVE_PATH_COMPONENT}/src/cllazyfile/sc_benchmark.cc" LINK_LIBRARIES ${PROJECT_NAME} steplazyfile stepdai stepcore stepeditor steputils TESTABLE)
SC_ADDEXEC(lazy_${PROJECT_NAME} SOURCES "${RELATIVE_PATH_COMPONENT}/src/cllazyfile/lazy_test.cc" LINK_LIBRARIES ${PROJECT_NAME} steplazyfile stepdai stepcore stepeditor steputils base TESTABLE)
endif(NOT WIN32)
#add user-defined executables
foreach(src ${SC_SDAI_ADDITIONAL_EXES_SRCS})
get_filename_component(name ${src} NAME_WE)
get_filename_component(path ${src} ABSOLUTE)
SC_ADDEXEC(${name}_${PROJECT_NAME} SOURCES ${src} LINK_LIBRARIES ${PROJECT_NAME} stepdai stepcore stepeditor steputils TESTABLE)
SC_ADDEXEC(${name}_${PROJECT_NAME} SOURCES ${src} LINK_LIBRARIES ${PROJECT_NAME} stepdai stepcore stepeditor steputils base TESTABLE)
#set_target_properties(${name}_${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${${PROJECT_NAME}_COMPILE_FLAGS} -I${path}")
endforeach(src ${SC_SDAI_ADDITIONAL_EXES_SRCS})
ENDMACRO(SCHEMA_EXES)
@@ -89,12 +89,12 @@ macro(SCHEMA_TARGETS expFile schemaName sourceFiles)
)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR} ${SC_SOURCE_DIR}/src/cldai ${SC_SOURCE_DIR}/src/cleditor
${SC_SOURCE_DIR}/src/clutils ${SC_SOURCE_DIR}/src/clstepcore ${SC_SOURCE_DIR}/src/cllazyfile
${SC_SOURCE_DIR}/src/cllazyfile/judy/src
${SC_SOURCE_DIR}/src/clutils ${SC_SOURCE_DIR}/src/clstepcore ${SC_SOURCE_DIR}/src/base
${SC_SOURCE_DIR}/src/base/judy/src
)
# if testing is enabled, "TESTABLE" sets property EXCLUDE_FROM_ALL and prevents installation
if(BUILD_SHARED_LIBS)
SC_ADDLIB(${PROJECT_NAME} SHARED SOURCES ${sourceFiles} LINK_LIBRARIES stepdai stepcore stepeditor steputils TESTABLE)
SC_ADDLIB(${PROJECT_NAME} SHARED SOURCES ${sourceFiles} LINK_LIBRARIES stepdai stepcore stepeditor steputils base TESTABLE)
add_dependencies(${PROJECT_NAME} generate_cpp_${PROJECT_NAME})
if(WIN32)
target_compile_definitions("${PROJECT_NAME}" PRIVATE SC_SCHEMA_DLL_EXPORTS)
@@ -111,9 +111,9 @@ macro(SCHEMA_TARGETS expFile schemaName sourceFiles)
endif()
if($CACHE{SC_BUILD_STATIC_LIBS})
SC_ADDLIB(${PROJECT_NAME}-static STATIC SOURCES ${sourceFiles} LINK_LIBRARIES stepdai-static stepcore-static stepeditor-static steputils-static TESTABLE)
SC_ADDLIB(${PROJECT_NAME}-static STATIC SOURCES ${sourceFiles} LINK_LIBRARIES stepdai-static stepcore-static stepeditor-static steputils-static base-static TESTABLE)
add_dependencies(${PROJECT_NAME}-static generate_cpp_${PROJECT_NAME})
target_compile_definitions("${PROJECT_NAME}-static" PRIVATE SC_STATIC)
target_compile_defines("${PROJECT_NAME}-static" PRIVATE SC_STATIC)
if(MSVC)
target_compile_options("${PROJECT_NAME}-static" PRIVATE "/bigobj")
endif()
+4 -4
View File
@@ -1,4 +1,4 @@
# create config.h
# create sc_cf.h
include(CheckLibraryExists)
include(CheckIncludeFile)
@@ -77,9 +77,9 @@ int main() {return !(f() == f());}
cmake_pop_check_state()
endif(SC_ENABLE_CXX11)
# Now that all the tests are done, configure the config.h file:
configure_file(${CMAKE_SOURCE_DIR}/include/config.h.in ${SC_BINARY_DIR}/${INCLUDE_DIR}/config.h.gen)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SC_BINARY_DIR}/${INCLUDE_DIR}/config.h.gen ${SC_BINARY_DIR}/${INCLUDE_DIR}/config.h)
# Now that all the tests are done, configure the sc_cf.h file:
configure_file(${CMAKE_SOURCE_DIR}/include/sc_cf.h.in ${SC_BINARY_DIR}/${INCLUDE_DIR}/sc_cf.h.gen)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SC_BINARY_DIR}/${INCLUDE_DIR}/sc_cf.h.gen ${SC_BINARY_DIR}/${INCLUDE_DIR}/sc_cf.h)
# Local Variables:
# tab-width: 8
+2
View File
@@ -16,6 +16,7 @@ set(SC_BINARY_DIR ${SC_BUILDDIR})
include(${CMAKE_CURRENT_SOURCE_DIR}/../SC_Outdirs.cmake)
set(schema_scanner_src
${SC_ROOT}/src/base/sc_mkdir.c
${SC_ROOT}/src/exp2cxx/genCxxFilenames.c
${SC_ROOT}/src/exp2cxx/class_strings.c
${SC_ROOT}/src/express/generated/expparse.c
@@ -51,6 +52,7 @@ include_directories(
${SC_ROOT}/include/
${SC_ROOT}/src/express/
${SC_ROOT}/src/express/generated
${SC_ROOT}/src/base
${SC_ROOT}/src/exp2cxx
${SC_BUILDDIR}/include
)
+13 -42
View File
@@ -14,25 +14,20 @@
*/
extern "C" {
#define _XOPEN_SOURCE /* for S_IFDIR */
# include "expparse.h"
# include "expscan.h"
# include "express/scope.h"
# include "genCxxFilenames.h"
# include "sc_mkdir.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
# include <string.h>
#include "expparse.h"
#include "expscan.h"
#include "express/scope.h"
#include "genCxxFilenames.h"
#include <string.h>
#ifdef _WIN32
# include <direct.h>
# define getcwd _getcwd
#else
# include <unistd.h>
#endif
# ifdef _WIN32
# include <direct.h>
# define getcwd _getcwd
# else
# include <unistd.h>
# endif
}
#include <string>
@@ -130,30 +125,6 @@ string makeShortName( const char * longName ) {
return filename;
}
/* cross-platform mkdir */
int sc_mkdir( const char * path ) {
#ifdef _WIN32
return mkdir( path );
#else
return mkdir( path, 0777 );
#endif /* _WIN32 */
}
/* return -1 if error, 0 if created, 1 if dir existed already */
static int mkDirIfNone( const char * path ) {
struct stat s;
if( stat( path, &s ) != 0 ) {
if( errno == ENOENT ) {
return sc_mkdir( path );
}
} else if( s.st_mode & S_IFDIR ) {
return 1;
}
/* either stat returned an error other than ENOENT, or 'path' exists but isn't a dir */
return -1;
}
/** write a CMakeLists.txt file for the schema; print its directory to stdout for CMake's add_subdirectory() command */
void writeLists( const char * schemaName, stringstream & eh, stringstream & ei, int ecount,
stringstream & th, stringstream & ti, int tcount ) {
@@ -249,7 +220,7 @@ void writeLists( const char * schemaName, stringstream & eh, stringstream & ei,
cmLists.close();
char pwd[BUFSIZ+1] = {0};
char pwd[BUFSIZ] = {0};
if( getcwd( pwd, BUFSIZ ) ) {
cout << pwd << "/" << shortName << endl;
} else {
+2 -1
View File
@@ -51,13 +51,14 @@ endif(NOT EXISTS ${SCHEMA_FILE})
get_filename_component(SCHEMA_SN ${SCHEMA_FILE} NAME)
string(REGEX REPLACE "\(.*\).[Ee][Xx][Pp]" "sdai_\\1" SCHEMA_LINK_NAME ${SCHEMA_SN})
set(STEPCODE_LIBRARIES stepcore stepeditor stepdai steputils ${SCHEMA_LINK_NAME})
set(STEPCODE_LIBRARIES base stepcore stepeditor stepdai steputils ${SCHEMA_LINK_NAME})
# Add STEPCode project to CMake build.
add_subdirectory(${STEPCODE_ROOT_DIR} "${CMAKE_CURRENT_BINARY_DIR}/sc" EXCLUDE_FROM_ALL)
# Set up STEPcode include directories.
set(STEPCODE_INCLUDE_DIR
${STEPCODE_ROOT_DIR}/src/base
${STEPCODE_ROOT_DIR}/src/clstepcore
${STEPCODE_ROOT_DIR}/src/cldai
${STEPCODE_ROOT_DIR}/src/clutils
@@ -19,6 +19,7 @@ INCLUDE( External_STEPCode )
IF(NOT WIN32)
set( STEPCODE_LIBRARIES
${STEPCODE_INSTALL_DIR}/lib/libbase.a
${STEPCODE_INSTALL_DIR}/lib/libstepcore.a
${STEPCODE_INSTALL_DIR}/lib/libstepeditor.a
${STEPCODE_INSTALL_DIR}/lib/libstepdai.a
@@ -27,6 +28,7 @@ IF(NOT WIN32)
)
ELSE()
set( STEPCODE_LIBRARIES
${STEPCODE_INSTALL_DIR}/lib/libbase.lib
${STEPCODE_INSTALL_DIR}/lib/libstepcore.lib
${STEPCODE_INSTALL_DIR}/lib/libstepeditor.lib
${STEPCODE_INSTALL_DIR}/lib/libstepdai.lib
@@ -42,6 +44,7 @@ MESSAGE( STATUS "STEPCODE_INSTALL_DIR: " ${STEPCODE_INSTALL_DIR} )
set( STEPCODE_INCLUDE_DIR
${STEPCODE_INSTALL_DIR}/include/stepcode
${STEPCODE_INSTALL_DIR}/include/stepcode/base
${STEPCODE_INSTALL_DIR}/include/stepcode/clstepcore
${STEPCODE_INSTALL_DIR}/include/stepcode/cldai
${STEPCODE_INSTALL_DIR}/include/stepcode/clutils
+2 -1
View File
@@ -32,9 +32,10 @@ install(FILES ${exppp_HDRS}
install(FILES ordered_attrs.h
sc_export.h
sc_stdbool.h
DESTINATION ${INCLUDE_DIR}/stepcode)
install(FILES ${SC_BINARY_DIR}/${INCLUDE_DIR}/config.h
install(FILES ${SC_BINARY_DIR}/${INCLUDE_DIR}/sc_cf.h
DESTINATION ${INCLUDE_DIR}/stepcode)
# Local Variables:
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef EXPPP_H
#define EXPPP_H
#include <stdbool.h>
#include <sc_stdbool.h>
#include <sc_export.h>
+2 -5
View File
@@ -71,7 +71,7 @@
*
*/
#include "config.h"
#include <sc_cf.h>
#include <sc_export.h>
#include <stdio.h>
@@ -82,7 +82,7 @@
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#else
# include <stdbool.h>
# include <sc_stdbool.h>
#endif
#if defined(_MSC_VER) && (_MSC_VER < 1900) && !defined(__cplusplus)
@@ -96,8 +96,5 @@
typedef void ( *voidFuncptr )();
typedef int ( *intFuncptr )();
/* Option index - can we get rid of this? */
extern SC_EXPRESS_EXPORT int sc_optind;
#endif /* BASIC_H */
@@ -15,6 +15,7 @@
#cmakedefine HAVE_IO_H 1
#cmakedefine SC_TRACE_FPRINTF 1
#cmakedefine SC_MEMMGR_ENABLE_CHECKS 1
#cmakedefine HAVE_ABS 1
#cmakedefine HAVE_MEMCPY 1
@@ -2,7 +2,6 @@
#define SCL_CF_H
/**** Define statements for CMake ****/
#cmakedefine SC_VERSION "@SC_VERSION@"
#cmakedefine HAVE_NDIR_H 1
#cmakedefine HAVE_STDINT_H 1
#cmakedefine HAVE_SYS_STAT_H 1
@@ -15,6 +14,7 @@
#cmakedefine HAVE_IO_H 1
#cmakedefine SC_TRACE_FPRINTF 1
#cmakedefine SC_MEMMGR_ENABLE_CHECKS 1
#cmakedefine HAVE_ABS 1
#cmakedefine HAVE_MEMCPY 1
@@ -26,6 +26,5 @@
#cmakedefine HAVE_STD_THREAD 1
#cmakedefine HAVE_STD_CHRONO 1
#cmakedefine HAVE_NULLPTR 1
#endif /* SCL_CF_H */
+43
View File
@@ -0,0 +1,43 @@
#ifndef STDBOOL_H_
#define STDBOOL_H_
/**
* stdbool.h - ISO C99 Boolean type
* Author - Bill Chatfield
* E-mail - bill underscore chatfield at yahoo dot com
* Copyright - You are free to use for any purpose except illegal acts
* Warrenty - None: don't blame me if it breaks something
*
* In ISO C99, stdbool.h is a standard header and _Bool is a keyword, but
* some compilers don't offer these yet. This header file is an
* implementation of the standard ISO C99 stdbool.h header file. It checks
* for various compiler versions and defines things that are missing in
* those versions.
*
* See http://predef.sourceforge.net/precomp.html for compile macros.
*/
#ifndef __cplusplus
/**
* Microsoft C/C++ version 14.00.50727.762, which comes with Visual C++ 2005,
* and version 15.00.30729.01, which comes with Visual C++ 2008, do not
* define _Bool.
*/
#if defined(_MSC_VER) && _MSC_VER<1800
typedef int _Bool;
#endif
/**
* Define the Boolean macros only if they are not already defined.
*/
#ifndef __bool_true_false_are_defined
#define bool _Bool
#define false 0
#define true 1
#define __bool_true_false_are_defined 1
#endif
#endif /* __cplusplus */
#endif /*STDBOOL_H_*/
+72
View File
@@ -0,0 +1,72 @@
set(SC_BASE_SOURCES
sc_memmgr.cc
sc_trace_fprintf.c
sc_getopt.cc
sc_benchmark.cc
sc_mkdir.c
path2str.c
judy/src/judy.c
)
set(SC_BASE_HDRS
sc_benchmark.h
sc_memmgr.h
sc_getopt.h
sc_trace_fprintf.h
sc_mkdir.h
path2str.h
judy/src/judy.h
judy/src/judyLArray.h
judy/src/judyL2Array.h
judy/src/judySArray.h
judy/src/judyS2Array.h
)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/judy/src
)
if($CACHE{SC_MEMMGR_ENABLE_CHECKS})
add_definitions(-DSC_MEMMGR_ENABLE_CHECKS)
endif()
if(BUILD_SHARED_LIBS)
SC_ADDLIB(base SHARED SOURCES ${SC_BASE_SOURCES})
if(WIN32)
target_link_libraries(base psapi)
target_compile_definitions(base PRIVATE SC_BASE_DLL_EXPORTS)
endif()
endif()
if(BUILD_STATIC_LIBS)
SC_ADDLIB(base-static STATIC SOURCES ${SC_BASE_SOURCES})
if(WIN32)
target_link_libraries(base-static psapi)
endif()
endif()
if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/judy/src")
message("Judy array source code not found. Downloading (don't sweat, it's public domain)...")
file(DOWNLOAD "http://github.com/mpictor/judy-template/archive/master.tar.gz"
"${CMAKE_CURRENT_SOURCE_DIR}/judy.tar.gz" SHOW_PROGRESS)
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xzf "${CMAKE_CURRENT_SOURCE_DIR}/judy.tar.gz"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
)
file(RENAME judy-template-master judy)
file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/judy.tar.gz")
message("Judy array source code extracted.")
endif(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/judy/src")
install(FILES ${SC_BASE_HDRS}
DESTINATION ${INCLUDE_DIR}/stepcode/base)
# Local Variables:
# tab-width: 8
# mode: cmake
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8
+29
View File
@@ -0,0 +1,29 @@
#include "path2str.h"
#include "sc_memmgr.h"
#include <string.h>
/* for windows, rewrite backslashes in paths
* that will be written to generated code
*/
const char * path2str_fn( const char * fileMacro ) {
static char * result = 0;
static size_t rlen = 0;
char * p;
if( rlen < strlen( fileMacro ) ) {
if( result ) {
sc_free( result );
}
rlen = strlen( fileMacro );
result = ( char * )sc_malloc( rlen * sizeof( char ) + 1 );
}
strcpy( result, fileMacro );
p = result;
while( *p ) {
if( *p == '\\' ) {
*p = '/';
}
p++;
}
return result;
}
+20
View File
@@ -0,0 +1,20 @@
#ifndef PATH2STR_H
#define PATH2STR_H
#include <sc_export.h>
/** windows only: rewrite backslashes in paths as forward slashes
* call as path2str(__FILE__) to take advantage of macro
*
* silence "unknown escape sequence" warning when contents of __FILE__
* are fprintf'd into string in generated code
*/
SC_BASE_EXPORT const char * path2str_fn( const char * fileMacro );
#ifdef _WIN32
# define path2str(path) path2str_fn(path)
#else
# define path2str(path) path
#endif
#endif /* PATH2STR_H */
@@ -1,6 +1,7 @@
/// \file sc_benchmark.cc memory info, timers, etc for benchmarking
#include "./sc_benchmark.h"
#include "sc_benchmark.h"
#include "sc_memmgr.h"
#ifdef _WIN32
#include <windows.h>
@@ -2,11 +2,14 @@
#define SC_BENCHMARK_H
/// \file sc_benchmark.h memory info, timers, etc for benchmarking
#include "sc_export.h"
#ifdef __cplusplus
#include <iostream>
#include <iosfwd>
#include <string>
#include "sc_memmgr.h"
extern "C" {
#endif
@@ -20,7 +23,7 @@ extern "C" {
*
* not yet implemented for OSX or Windows.
*/
benchVals getMemAndTime( );
SC_BASE_EXPORT benchVals getMemAndTime( );
#ifdef __cplusplus
}
@@ -36,7 +39,7 @@ extern "C" {
* depends on getMemAndTime() above - may not work on all platforms.
*/
class benchmark {
class SC_BASE_EXPORT benchmark {
protected:
benchVals initialVals, laterVals;
#ifdef _MSC_VER
+214
View File
@@ -0,0 +1,214 @@
/****** RENAMED from xgetopt.cc to sc_getopt.cc ***********/
// XGetopt.cpp Version 1.2
//
// Author: Hans Dietrich
// hdietrich2@hotmail.com
//
// Description:
// XGetopt.cpp implements sc_getopt(), a function to parse command lines.
//
// History
// Version 1.2 - 2003 May 17
// - Added Unicode support
//
// Version 1.1 - 2002 March 10
// - Added example to XGetopt.cpp module header
//
// This software is released into the public domain.
// You are free to use it in any way you like.
//
// This software is provided "as is" with no expressed
// or implied warranty. I accept no liability for any
// damage or loss of business that this software may cause.
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// if you are using precompiled headers then include this line:
//#include "stdafx.h"
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// if you are not using precompiled headers then include these lines:
//#include <windows.h>
#include <stdio.h>
#include <string.h>
///////////////////////////////////////////////////////////////////////////////
#include "sc_getopt.h"
///////////////////////////////////////////////////////////////////////////////
//
// X G e t o p t . c p p
//
//
// NAME
// sc_getopt -- parse command line options
//
// SYNOPSIS
// int sc_getopt(int argc, char *argv[], char *optstring)
//
// extern char *sc_optarg;
// extern int sc_optind;
//
// DESCRIPTION
// The sc_getopt() function parses the command line arguments. Its
// arguments argc and argv are the argument count and array as
// passed into the application on program invocation. In the case
// of Visual C++ programs, argc and argv are available via the
// variables __argc and __argv (double underscores), respectively.
// sc_getopt returns the next option letter in argv that matches a
// letter in optstring. (Note: Unicode programs should use
// __targv instead of __argv. Also, all character and string
// literals should be enclosed in _T( ) ).
//
// optstring is a string of recognized option letters; if a letter
// is followed by a colon, the option is expected to have an argument
// that may or may not be separated from it by white space. sc_optarg
// is set to point to the start of the option argument on return from
// sc_getopt.
//
// Option letters may be combined, e.g., "-ab" is equivalent to
// "-a -b". Option letters are case sensitive.
//
// sc_getopt places in the external variable sc_optind the argv index
// of the next argument to be processed. sc_optind is initialized
// to 0 before the first call to sc_getopt.
//
// When all options have been processed (i.e., up to the first
// non-option argument), sc_getopt returns EOF, sc_optarg will point
// to the argument, and sc_optind will be set to the argv index of
// the argument. If there are no non-option arguments, sc_optarg
// will be set to NULL.
//
// The special option "--" may be used to delimit the end of the
// options; EOF will be returned, and "--" (and everything after it)
// will be skipped.
//
// RETURN VALUE
// For option letters contained in the string optstring, sc_getopt
// will return the option letter. sc_getopt returns a question mark (?)
// when it encounters an option letter not included in optstring.
// EOF is returned when processing is finished.
//
// BUGS
// 1) Long options are not supported.
// 2) The GNU double-colon extension is not supported.
// 3) The environment variable POSIXLY_CORRECT is not supported.
// 4) The + syntax is not supported.
// 5) The automatic permutation of arguments is not supported.
// 6) This implementation of sc_getopt() returns EOF if an error is
// encountered, instead of -1 as the latest standard requires.
//
// EXAMPLE
// BOOL CMyApp::ProcessCommandLine(int argc, char *argv[])
// {
// int c;
//
// while ((c = sc_getopt(argc, argv, _T("aBn:"))) != EOF)
// {
// switch (c)
// {
// case _T('a'):
// TRACE(_T("option a\n"));
// //
// // set some flag here
// //
// break;
//
// case _T('B'):
// TRACE( _T("option B\n"));
// //
// // set some other flag here
// //
// break;
//
// case _T('n'):
// TRACE(_T("option n: value=%d\n"), atoi(sc_optarg));
// //
// // do something with value here
// //
// break;
//
// case _T('?'):
// TRACE(_T("ERROR: illegal option %s\n"), argv[sc_optind-1]);
// return FALSE;
// break;
//
// default:
// TRACE(_T("WARNING: no handler for option %c\n"), c);
// return FALSE;
// break;
// }
// }
// //
// // check for non-option args here
// //
// return TRUE;
// }
//
///////////////////////////////////////////////////////////////////////////////
char * sc_optarg; // global argument pointer
int sc_optind = 0; // global argv index
int sc_getopt( int argc, char * argv[], char * optstring ) {
static char * next = NULL;
if( sc_optind == 0 ) {
next = NULL;
}
sc_optarg = NULL;
if( next == NULL || *next == '\0' ) {
if( sc_optind == 0 ) {
sc_optind++;
}
if( sc_optind >= argc || argv[sc_optind][0] != '-' || argv[sc_optind][1] == '\0' ) {
sc_optarg = NULL;
if( sc_optind < argc ) {
sc_optarg = argv[sc_optind];
}
return EOF;
}
if( strcmp( argv[sc_optind], "--" ) == 0 ) {
sc_optind++;
sc_optarg = NULL;
if( sc_optind < argc ) {
sc_optarg = argv[sc_optind];
}
return EOF;
}
next = argv[sc_optind];
next++; // skip past -
sc_optind++;
}
char c = *next++;
char * cp = strchr( optstring, c );
if( cp == NULL || c == ':' ) {
return '?';
}
cp++;
if( *cp == ':' ) {
if( *next != '\0' ) {
sc_optarg = next;
next = NULL;
} else if( sc_optind < argc ) {
sc_optarg = argv[sc_optind];
sc_optind++;
} else {
return '?';
}
}
return c;
}
+32
View File
@@ -0,0 +1,32 @@
/** \file sc_getopt.h
* this was xgetopt.h
* XGetopt.h Version 1.2
*
* Author: Hans Dietrich
* hdietrich2@hotmail.com
*
* This software is released into the public domain.
* You are free to use it in any way you like.
*
* This software is provided "as is" with no expressed
* or implied warranty. I accept no liability for any
* damage or loss of business that this software may cause.
*/
#ifndef XGETOPT_H
#define XGETOPT_H
#include "sc_export.h"
#ifdef __cplusplus
extern "C" {
#endif
extern SC_BASE_EXPORT int sc_optind, sc_opterr;
extern SC_BASE_EXPORT char * sc_optarg;
int SC_BASE_EXPORT sc_getopt( int argc, char * argv[], char * optstring );
#ifdef __cplusplus
}
#endif
#endif /* XGETOPT_H */
+405
View File
@@ -0,0 +1,405 @@
#define SC_MEMMGR_CC
#include <sc_cf.h>
#include "sc_memmgr.h"
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <set>
#ifdef SC_MEMMGR_ENABLE_CHECKS
/**
sc_memmgr_error definition
*/
class sc_memmgr_error {
private:
std::string _srcfile;
unsigned int _srcline;
unsigned int _occurences;
public:
sc_memmgr_error( const std::string & file, const unsigned int line );
sc_memmgr_error( const sc_memmgr_error & rhs );
~sc_memmgr_error( void );
bool operator<( const sc_memmgr_error & rhs ) const;
std::string getsrcfile( void ) const;
unsigned int getsrcline( void ) const;
unsigned int getoccurences( void ) const;
};
typedef std::set<sc_memmgr_error> sc_memmgr_errors;
typedef std::set<sc_memmgr_error>::iterator sc_memmgr_error_iterator;
/**
sc_memmgr_record definition
*/
class sc_memmgr_record {
private:
void * _addr;
size_t _size;
std::string _srcfile;
unsigned int _srcline;
public:
sc_memmgr_record( void * addr, size_t size, const char * file, const unsigned int line );
sc_memmgr_record( void * addr );
sc_memmgr_record( const sc_memmgr_record & rhs );
~sc_memmgr_record( void );
bool operator<( const sc_memmgr_record & rhs ) const;
void * getaddr( void ) const;
size_t getsize( void ) const;
std::string getsrcfile( void ) const;
unsigned int getsrcline( void ) const;
};
typedef std::set<sc_memmgr_record> sc_memmgr_records;
typedef std::set<sc_memmgr_record>::iterator sc_memmgr_record_iterator;
#endif /* SC_MEMMGR_ENABLE_CHECKS */
/**
sc_memmgr definition
*/
class sc_memmgr {
private:
#ifdef SC_MEMMGR_ENABLE_CHECKS
bool _record_insert_busy, _record_erase_busy;
// memory allocation/reallocation records, inserted at allocation, erased at deallocation.
sc_memmgr_records _records;
// memory stats
unsigned int _allocated; // amount of memory allocated simultaniously
unsigned int _maximum_allocated; // maximum amount of memory allocated simultaniously
unsigned int _allocated_total; // total amount of memory allocated in bytes
unsigned int _reallocated_total; // total amount of memory reallocated in bytes
unsigned int _deallocated_total; // total amount of memory deallocated in bytes
#endif /* SC_MEMMGR_ENABLE_CHECKS */
protected:
public:
sc_memmgr( void );
~sc_memmgr( void );
void * allocate( size_t size, const char * file, const int line );
void * reallocate( void * addr, size_t size, const char * file, const int line );
void deallocate( void * addr, const char * file, const int line );
};
/**
sc_memmgr instance.
There should be one static instance of memmgr.
This instance is automatically destroyed when application exits, so this allows us to add
memory leak detection in it's destructor.
*/
sc_memmgr memmgr;
/**
c memory functions implementation
*/
extern "C" {
void * sc_malloc_fn( unsigned int size, const char * file, const int line ) {
return memmgr.allocate( size, file, line );
}
void * sc_calloc_fn( unsigned int count, unsigned int size, const char * file, const int line ) {
return memmgr.allocate( count * size, file, line );
}
void * sc_realloc_fn( void * addr, unsigned int size, const char * file, const int line ) {
return memmgr.reallocate( addr, size, file, line );
}
void sc_free_fn( void * addr ) {
memmgr.deallocate( addr, "", 0 );
}
}
/**
c++ memory operators implementation
*/
void * sc_operator_new( size_t size, const char * file, const int line ) {
return memmgr.allocate( size, file, line );
}
void sc_operator_delete( void * addr, const char * file, const int line ) {
memmgr.deallocate( addr, file, line );
}
void sc_operator_delete( void * addr ) {
memmgr.deallocate( addr, "", 0 );
}
/**
sc_memmgr implementation
*/
sc_memmgr::sc_memmgr( void ) {
#ifdef SC_MEMMGR_ENABLE_CHECKS
_record_insert_busy = false;
_record_erase_busy = false;
_allocated = 0;
_maximum_allocated = 0;
_allocated_total = 0;
_reallocated_total = 0;
_deallocated_total = 0;
#endif /* SC_MEMMGR_ENABLE_CHECKS */
}
/**
Destructor:
sc_memmgr::~sc_memmgr(void)
Description:
The sc_memmgr destructor is used to check for memory leaks when enabled.
All records still present when sc_memmgr instance is destroyed can be considered as
memory leaks.
*/
sc_memmgr::~sc_memmgr( void ) {
#ifdef SC_MEMMGR_ENABLE_CHECKS
sc_memmgr_record_iterator irecord;
sc_memmgr_errors errors;
sc_memmgr_error_iterator ierror;
// Check if total allocated equals total deallocated
if( _allocated_total != _deallocated_total ) {
// todo: generate warning for possible memory leaks, enable full memory leak checking
fprintf( stderr, "sc_memmgr warning: Possible memory leaks detected (%d of %d bytes)\n", _allocated_total - _deallocated_total, _allocated_total );
}
// Compact leaks into an error list to prevent same leak being reported multiple times.
_record_insert_busy = true;
_record_erase_busy = true;
for( irecord = _records.begin();
irecord != _records.end();
irecord ++ ) {
sc_memmgr_error error( irecord->getsrcfile(), irecord->getsrcline() );
ierror = errors.find( error );
if( ierror == errors.end() ) {
errors.insert( error );
}
//else
// ierror->occurences ++;
}
_record_insert_busy = false;
_record_erase_busy = false;
// Loop through memory leaks to generate/buffer errors
for( ierror = errors.begin();
ierror != errors.end();
ierror ++ ) {
// todo: generate error for memory leak
fprintf( stderr, "sc_memmgr warning: Possible memory leak in %s line %d\n", ierror->getsrcfile().c_str(), ierror->getsrcline() );
}
// Clear remaining records
_record_erase_busy = true;
_records.clear();
errors.clear();
_record_erase_busy = false;
#endif /* SC_MEMMGR_ENABLE_CHECKS */
}
void * sc_memmgr::allocate( size_t size, const char * file, const int line ) {
void * addr;
// Allocate
addr = malloc( size );
if( addr == NULL ) {
// todo: error allocation failed
fprintf( stderr, "sc_memmgr error: Memory allocation failed in %s line %d\n", file, line );
}
// Some stl implementations (for example debian gcc) use the new operator to construct
// new elements when inserting sc_memmgr_record. When this our new operator gets used
// for this operation, this would result in an infinite loop. This is fixed by the
// _record_insert_busy flag.
#ifdef SC_MEMMGR_ENABLE_CHECKS
if( !_record_insert_busy ) {
// Store record for this allocation
_record_insert_busy = true;
_records.insert( sc_memmgr_record( addr, size, file, line ) );
_record_insert_busy = false;
// Update stats
_allocated += size;
if( _allocated > _maximum_allocated ) {
_maximum_allocated = _allocated;
}
_allocated_total += size;
}
#endif /* SC_MEMMGR_ENABLE_CHECKS */
return addr;
}
void * sc_memmgr::reallocate( void * addr, size_t size, const char * file, const int line ) {
#ifdef SC_MEMMGR_ENABLE_CHECKS
sc_memmgr_record_iterator record;
if( !_record_insert_busy ) {
// Find record of previous allocation/reallocation
record = _records.find( sc_memmgr_record( addr ) );
if( record == _records.end() ) {
// todo: error reallocating memory not allocated?
fprintf( stderr, "sc_memmgr warning: Reallocation of not allocated memory at %s line %d\n", file, line );
} else {
// Update stats
_allocated -= record->getsize();
_deallocated_total += record->getsize();
// Erase previous allocation/reallocation
_record_erase_busy = true;
_records.erase( record );
_record_erase_busy = false;
}
}
#endif /* SC_MEMMGR_ENABLE_CHECKS */
// Reallocate
addr = realloc( addr, size );
if( addr == NULL ) {
// todo: error reallocation failed
fprintf( stderr, "sc_memmgr error: Reallocation failed at %s line %d\n", file, line );
}
#ifdef SC_MEMMGR_ENABLE_CHECKS
if( !_record_insert_busy ) {
// Store record for this reallocation
_record_insert_busy = true;
_records.insert( sc_memmgr_record( addr, size, file, line ) );
_record_insert_busy = false;
// Update stats
_allocated += size;
if( _allocated > _maximum_allocated ) {
_maximum_allocated = _allocated;
}
_allocated_total += size;
_reallocated_total += size;
}
#endif /* SC_MEMMGR_ENABLE_CHECKS */
return addr;
}
void sc_memmgr::deallocate( void * addr, const char * file, const int line ) {
#ifdef SC_MEMMGR_ENABLE_CHECKS
sc_memmgr_record_iterator record;
if( !_record_erase_busy ) {
// Find record of previous allocation/reallocation
record = _records.find( sc_memmgr_record( addr ) );
if( record == _records.end() ) {
// todo: error free called for not allocated memory?
fprintf( stderr, "sc_memmgr warning: Deallocate of not allocated memory at %s line %d\n", file, line );
} else {
// Update stats
_allocated -= record->getsize();
_deallocated_total += record->getsize();
// Erase record
_record_erase_busy = true;
_records.erase( record );
_record_erase_busy = false;
}
}
#else
(void) file; // quell unused param warnings
(void) line;
#endif /* SC_MEMMGR_ENABLE_CHECKS */
// Deallocate
free( addr );
}
#ifdef SC_MEMMGR_ENABLE_CHECKS
/**
sc_memmgr_error implementation
*/
sc_memmgr_error::sc_memmgr_error( const std::string & file, const unsigned int line ) {
_srcfile = file;
_srcline = line;
_occurences = 1;
}
sc_memmgr_error::sc_memmgr_error( const sc_memmgr_error & rhs ) {
_srcfile = rhs._srcfile;
_srcline = rhs._srcline;
_occurences = rhs._occurences;
}
sc_memmgr_error::~sc_memmgr_error( void ) {
}
bool sc_memmgr_error::operator<( const sc_memmgr_error & rhs ) const {
if( _srcfile == rhs._srcfile ) {
return _srcline < rhs._srcline;
}
return _srcfile < rhs._srcfile;
}
std::string sc_memmgr_error::getsrcfile( void ) const {
return _srcfile;
}
unsigned int sc_memmgr_error::getsrcline( void ) const {
return _srcline;
}
unsigned int sc_memmgr_error::getoccurences( void ) const {
return _occurences;
}
/**
sc_memmgr_record implementation
*/
sc_memmgr_record::sc_memmgr_record( void * addr, size_t size, const char * file, const unsigned int line ) {
_addr = addr;
_size = size;
_srcfile = file;
_srcline = line;
}
sc_memmgr_record::sc_memmgr_record( void * addr ) {
_addr = addr;
_size = 0;
_srcfile = "";
_srcline = -1;
}
sc_memmgr_record::sc_memmgr_record( const sc_memmgr_record & rhs ) {
_addr = rhs._addr;
_size = rhs._size;
_srcfile = rhs._srcfile;
_srcline = rhs._srcline;
}
sc_memmgr_record::~sc_memmgr_record( void ) {
}
bool sc_memmgr_record::operator<( const sc_memmgr_record & rhs ) const {
return _addr < rhs._addr;
}
void * sc_memmgr_record::getaddr( void ) const {
return _addr;
}
size_t sc_memmgr_record::getsize( void ) const {
return _size;
}
std::string sc_memmgr_record::getsrcfile( void ) const {
return _srcfile;
}
unsigned int sc_memmgr_record::getsrcline( void ) const {
return _srcline;
}
#endif /* SC_MEMMGR_ENABLE_CHECKS */
+79
View File
@@ -0,0 +1,79 @@
#ifndef SC_MEMMGR_H
#define SC_MEMMGR_H
#include <sc_export.h>
#include <stdlib.h>
#if defined(SC_MEMMGR_ENABLE_CHECKS)
#ifdef __cplusplus
#include <stddef.h>
extern "C" {
#endif /* __cplusplus */
SC_BASE_EXPORT void * sc_malloc_fn( unsigned int size, const char * file, const int line );
SC_BASE_EXPORT void * sc_calloc_fn( unsigned int count, unsigned int size, const char * file, const int line );
SC_BASE_EXPORT void * sc_realloc_fn( void * addr, unsigned int size, const char * file, const int line );
SC_BASE_EXPORT void sc_free_fn( void * addr );
#ifdef __cplusplus
}
#endif /* __cplusplus */
#ifdef __cplusplus
SC_BASE_EXPORT void * sc_operator_new( size_t size, const char * file, const int line );
SC_BASE_EXPORT void sc_operator_delete( void * addr, const char * file, const int line );
SC_BASE_EXPORT void sc_operator_delete( void * addr );
#endif /* __cplusplus */
#ifndef SC_MEMMGR_CC
#define sc_malloc(size) sc_malloc_fn(size, __FILE__, __LINE__)
#define sc_calloc(count, size) sc_calloc_fn(count, size, __FILE__, __LINE__)
#define sc_realloc(addr, size) sc_realloc_fn(addr, size, __FILE__, __LINE__)
#define sc_free(addr) sc_free_fn(addr)
#ifdef __cplusplus
#include <new>
inline void * operator new( size_t size, const char * file, const int line ) throw (std::bad_alloc) {
return sc_operator_new( size, file, line );
}
inline void * operator new[]( size_t size, const char * file, const int line ) throw (std::bad_alloc) {
return sc_operator_new( size, file, line );
}
inline void operator delete( void * addr, const char * file, const int line ) throw (std::bad_alloc) {
sc_operator_delete( addr, file, line );
}
inline void operator delete[]( void * addr, const char * file, const int line ) throw (std::bad_alloc) {
sc_operator_delete( addr, file, line );
}
inline void operator delete( void * addr ) throw () {
sc_operator_delete( addr );
}
inline void operator delete[]( void * addr ) throw () {
sc_operator_delete( addr );
}
#define new new(__FILE__, __LINE__)
#endif /* __cplusplus */
#endif /* SC_MEMMGR_CC */
#else
#define sc_malloc(size) malloc(size)
#define sc_calloc(count, size) calloc(count, size)
#define sc_realloc(addr, size) realloc(addr, size)
#define sc_free(addr) free(addr)
#endif /* SC_MEMMGR_ENABLE_CHECKS */
#endif /* SC_MEMMGR_H */
+32
View File
@@ -0,0 +1,32 @@
#define _XOPEN_SOURCE /* for S_IFDIR */
#include "sc_mkdir.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#ifdef _WIN32
# include <direct.h>
#endif /* _WIN32 */
/* cross-platform mkdir */
int sc_mkdir( const char * path ) {
#ifdef _WIN32
return mkdir( path );
#else
return mkdir( path, 0777 );
#endif /* _WIN32 */
}
/* return -1 if error, 0 if created, 1 if dir existed already */
int mkDirIfNone( const char * path ) {
struct stat s;
if( stat( path, &s ) != 0 ) {
if( errno == ENOENT ) {
return sc_mkdir( path );
}
} else if( s.st_mode & S_IFDIR ) {
return 1;
}
/* either stat returned an error other than ENOENT, or 'path' exists but isn't a dir */
return -1;
}
+15
View File
@@ -0,0 +1,15 @@
#ifndef SC_MKDIR
#define SC_MKDIR
#include <sc_export.h>
/** cross-platform mkdir() */
SC_BASE_EXPORT int sc_mkdir( const char * path );
/** create a dir 'path' if 'path' doesn't exist
* \return -1 if error, 0 if created, 1 if dir existed already
* if it returns -1, check errno
*/
SC_BASE_EXPORT int mkDirIfNone( const char * path );
#endif /* SC_MKDIR */
+39
View File
@@ -0,0 +1,39 @@
#ifndef __SC_STDIO_H
#define __SC_STDIO_H
/*
* https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
* (NOTE: MSVC defines va_list as a char*, so this should be safe)
*/
#if defined(_MSC_VER) && _MSC_VER < 1900
#include <stdarg.h>
static __inline int
c99_vsnprintf(char *buffer, size_t sz, const char *format, va_list ap) {
int count = -1;
if (sz != 0)
count = _vsnprintf_s(buffer, sz, _TRUNCATE, format, ap);
if (count == -1)
count = _vscprintf(format, ap);
return count;
}
static __inline int
c99_snprintf(char *buffer, size_t sz, const char *format, ...) {
int count;
va_list ap;
va_start(ap, format);
count = c99_vsnprintf(buffer, sz, format, ap);
va_end(ap);
return count;
}
#endif
#endif /* __SC_STDIO_H */
+11
View File
@@ -0,0 +1,11 @@
#ifndef SC_STRTOULL_H
#define SC_STRTOULL_H
#include <limits.h>
#ifdef _WIN32
# define strtoull _strtoui64
# define ULLONG_MAX _UI64_MAX
#endif
#endif /* SC_STRTOULL_H */
@@ -1,7 +1,8 @@
#include <stdarg.h>
#include <stdio.h>
#include "trace_fprintf.h"
#include "sc_trace_fprintf.h"
void trace_fprintf( char const * sourcefile, int line, FILE * file, const char * format, ... ) {
va_list args;
@@ -1,7 +1,7 @@
#ifndef SC_TRACE_FPRINTF_H
#define SC_TRACE_FPRINTF_H
/** \file trace_fprintf.h
/** \file sc_trace_fprintf.h
* Used to track the source file and line where generated code is printed from
* When enabled, comments are printed into the generated files for every 'fprintf':
* / * source: scl/src/exp2cxx/selects.c:1375 * /
@@ -20,7 +20,7 @@ extern "C" {
/** Used to find where generated c++ originates from in exp2cxx.
* To enable, configure with 'cmake .. -DSC_TRACE_FPRINTF=ON'
*/
void trace_fprintf( char const * sourcefile, int line, FILE * file, const char * format, ... );
SC_BASE_EXPORT void trace_fprintf( char const * sourcefile, int line, FILE * file, const char * format, ... );
#ifdef __cplusplus
}
#endif
+2 -1
View File
@@ -29,11 +29,12 @@ SET(SC_CLDAI_HDRS
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${SC_SOURCE_DIR}/src/base
${SC_SOURCE_DIR}/src/clstepcore
${SC_SOURCE_DIR}/src/clutils
)
set(_libdeps steputils)
set(_libdeps steputils base)
if(BUILD_SHARED_LIBS)
SC_ADDLIB(stepdai SHARED SOURCES ${LIBSTEPDAI_SRCS} LINK_LIBRARIES ${_libdeps})
@@ -29,6 +29,7 @@
#include <memory.h>
#include <math.h>
#include "sc_memmgr.h"
#include "sdaiApplication_instance.h"
+1
View File
@@ -11,6 +11,7 @@
#include <sstream>
#include <sdai.h>
#include "sc_memmgr.h"
SDAI_Binary::SDAI_Binary( const char * str, int max ) {
content = std::string( str, max );
+1
View File
@@ -3,6 +3,7 @@
#include <math.h>
#include <sdai.h>
#include "sc_memmgr.h"
// to help ObjectCenter
#ifndef HAVE_MEMMOVE
+1
View File
@@ -3,6 +3,7 @@
//#include <EntityExtent.h>
#include <sdai.h>
#include "sc_memmgr.h"
SDAI_Entity_extent::SDAI_Entity_extent( )
: _definition( 0 ), _definition_name( 0 ), _owned_by( 0 ) {
+3 -2
View File
@@ -27,6 +27,7 @@
#include <math.h>
#include <sdai.h>
#include "sc_memmgr.h"
/*
#include <EntityExtent.h>
@@ -50,7 +51,7 @@ SDAI_Entity_extent__set::SDAI_Entity_extent__set( int defaultSize ) {
}
SDAI_Entity_extent__set::~SDAI_Entity_extent__set() {
delete[] _buf;
delete _buf;
}
void SDAI_Entity_extent__set::Check( int index ) {
@@ -61,7 +62,7 @@ void SDAI_Entity_extent__set::Check( int index ) {
_bufsize = ( index + 1 ) * 2;
newbuf = new SDAI_Entity_extent_ptr[_bufsize];
memmove( newbuf, _buf, _count * sizeof( SDAI_Entity_extent_ptr ) );
delete[] _buf;
delete _buf;
_buf = newbuf;
}
}
+1
View File
@@ -1,5 +1,6 @@
#include <sdai.h>
#include "sc_memmgr.h"
/*
* NIST STEP Core Class Library
+1
View File
@@ -1,5 +1,6 @@
#include <sdai.h>
#include "sc_memmgr.h"
///////// SDAI_Model_contents_instances
+1
View File
@@ -24,6 +24,7 @@
* UArray implementation.
*/
#include <sdai.h>
#include "sc_memmgr.h"
// to help ObjectCenter
#ifndef HAVE_MEMMOVE
+1
View File
@@ -1,4 +1,5 @@
#include <sdai.h>
#include "sc_memmgr.h"
SDAI_sdaiObject::SDAI_sdaiObject() {
}
+1
View File
@@ -1,4 +1,5 @@
#include <sdai.h>
#include "sc_memmgr.h"
SDAI_Session_instance::SDAI_Session_instance() {
}
+1
View File
@@ -11,6 +11,7 @@
#include <sdai.h>
#include <sstream>
#include "sc_memmgr.h"
SDAI_String::SDAI_String( const char * str, size_t max ) {
if( !str ) {
+3 -2
View File
@@ -21,20 +21,21 @@ SET(SC_CLEDITOR_HDRS
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${SC_SOURCE_DIR}/src/base
${SC_SOURCE_DIR}/src/cldai
${SC_SOURCE_DIR}/src/clstepcore
${SC_SOURCE_DIR}/src/clutils
)
if(BUILD_SHARED_LIBS)
SC_ADDLIB(stepeditor SHARED SOURCES ${LIBSTEPEDITOR_SRCS} LINK_LIBRARIES stepcore stepdai steputils)
SC_ADDLIB(stepeditor SHARED SOURCES ${LIBSTEPEDITOR_SRCS} LINK_LIBRARIES stepcore stepdai steputils base)
if(WIN32)
target_compile_definitions(stepeditor PRIVATE SC_EDITOR_DLL_EXPORTS)
endif()
endif()
if(BUILD_STATIC_LIBS)
SC_ADDLIB(stepeditor-static STATIC SOURCES ${LIBSTEPEDITOR_SRCS} LINK_LIBRARIES stepcore-static stepdai-static steputils-static)
SC_ADDLIB(stepeditor-static STATIC SOURCES ${LIBSTEPEDITOR_SRCS} LINK_LIBRARIES stepcore-static stepdai-static steputils-static base-static)
endif()
install(FILES ${SC_CLEDITOR_HDRS}
+10 -27
View File
@@ -34,6 +34,8 @@
// void PushPastString (istream& in, std::string &s, ErrorDescriptor *err)
#include <STEPundefined.h>
#include "sc_memmgr.h"
/**
* \returns The new file name for the class.
* \param newName The file name to be set.
@@ -115,7 +117,7 @@ Severity STEPfile::ReadHeader( istream & in ) {
int fileid;
std::string keywd;
char c = '\0';
char buf [BUFSIZ+1];
char buf [BUFSIZ];
std::string strbuf;
@@ -440,7 +442,7 @@ int STEPfile::ReadData1( istream & in ) {
char c;
int instance_count = 0;
char buf[BUFSIZ+1];
char buf[BUFSIZ];
buf[0] = '\0';
std::string tmpbuf;
@@ -563,7 +565,7 @@ int STEPfile::ReadData2( istream & in, bool useTechCor ) {
_warningCount = 0; // reset error count
char c;
char buf[BUFSIZ+1];
char buf[BUFSIZ];
buf[0] = '\0';
std::string tmpbuf;
@@ -728,7 +730,7 @@ int STEPfile::FindDataSection( istream & in ) {
}
int STEPfile::FindHeaderSection( istream & in ) {
char buf[BUFSIZ+1];
char buf[BUFSIZ];
char * b = buf;
*b = '\0';
@@ -849,8 +851,6 @@ SDAI_Application_instance * STEPfile::CreateInstance( istream & in, ostream & ou
<< " User Defined Entity in DATA section ignored.\n"
<< "\tData lost: \'!" << objnm << "\': " << tmpbuf
<< endl;
if (scopelist)
delete[] scopelist;
return ENTITY_NULL;
} else {
schnm = schemaName();
@@ -879,8 +879,6 @@ SDAI_Application_instance * STEPfile::CreateInstance( istream & in, ostream & ou
out << "ERROR: instance #" << fileid << " \'" << objnm
<< "\': " << result.UserMsg()
<< ".\n\tData lost: " << tmpbuf << "\n\n";
if (scopelist)
delete[] scopelist;
return ENTITY_NULL;
}
obj -> STEPfile_id = fileid;
@@ -889,10 +887,6 @@ SDAI_Application_instance * STEPfile::CreateInstance( istream & in, ostream & ou
SkipInstance( in, tmpbuf );
ReadTokenSeparator( in );
if (scopelist)
delete[] scopelist;
return obj;
}
@@ -1156,7 +1150,7 @@ SDAI_Application_instance * STEPfile::ReadInstance( istream & in, ostream & out,
Severity sev = SEVERITY_NULL;
std::string tmpbuf;
char errbuf[BUFSIZ+1];
char errbuf[BUFSIZ];
errbuf[0] = '\0';
std::string currSch;
std::string objnm;
@@ -1537,11 +1531,9 @@ void STEPfile::WriteHeaderInstance( SDAI_Application_instance * obj, ostream & o
void STEPfile::WriteHeaderInstanceFileName( ostream & out ) {
// Get the FileName instance from _headerInstances
SDAI_Application_instance * se = 0;
bool del_se = false;
se = _headerInstances->GetApplication_instance( "File_Name" );
if( se == ENTITY_NULL ) {
se = ( SDAI_Application_instance * )HeaderDefaultFileName();
del_se = true;
}
//set some of the attribute values at time of output
@@ -1561,9 +1553,6 @@ void STEPfile::WriteHeaderInstanceFileName( ostream & out ) {
//output the values to the file
WriteHeaderInstance( se, out );
if (del_se)
delete se;
}
void STEPfile::WriteHeaderInstanceFileDescription( ostream & out ) {
@@ -1574,11 +1563,8 @@ void STEPfile::WriteHeaderInstanceFileDescription( ostream & out ) {
// ERROR: no File_Name instance in _headerInstances
// create a File_Name instance
se = ( SDAI_Application_instance * )HeaderDefaultFileDescription();
WriteHeaderInstance(se, out);
delete se;
} else {
WriteHeaderInstance( se, out );
}
WriteHeaderInstance( se, out );
}
void STEPfile::WriteHeaderInstanceFileSchema( ostream & out ) {
@@ -1589,11 +1575,8 @@ void STEPfile::WriteHeaderInstanceFileSchema( ostream & out ) {
// ERROR: no File_Name instance in _headerInstances
// create a File_Name instance
se = ( SDAI_Application_instance * ) HeaderDefaultFileSchema();
WriteHeaderInstance( se, out );
delete se;
} else {
WriteHeaderInstance( se, out );
}
WriteHeaderInstance( se, out );
}
void STEPfile::WriteData( ostream & out, int writeComments ) {
@@ -1620,7 +1603,7 @@ void STEPfile::WriteValuePairsData( ostream & out, int writeComments, int mixedC
Severity STEPfile::AppendFile( istream * in, bool useTechCor ) {
Severity rval = SEVERITY_NULL;
char errbuf[BUFSIZ+1];
char errbuf[BUFSIZ];
SetFileIdIncrement();
int total_insts = 0, valid_insts = 0;
+4 -3
View File
@@ -17,6 +17,7 @@
#include <cmath>
#include <cstring>
#include "sc_memmgr.h"
extern void HeaderSchemaInit( Registry & reg );
@@ -178,7 +179,7 @@ istream * STEPfile::OpenInputFile( const std::string filename ) {
return( 0 );
} else {
if( SetFileName( filename ).empty() && ( filename.compare( "-" ) != 0 ) ) {
char msg[BUFSIZ+1];
char msg[BUFSIZ];
sprintf( msg, "Unable to find file for input: \'%s\'. File not read.\n", filename.c_str() );
_error.AppendToUserMsg( msg );
_error.GreaterSeverity( SEVERITY_INPUT_ERROR );
@@ -195,7 +196,7 @@ istream * STEPfile::OpenInputFile( const std::string filename ) {
}
if( !in || !( in -> good() ) ) {
char msg[BUFSIZ+1];
char msg[BUFSIZ];
sprintf( msg, "Unable to open file for input: \'%s\'. File not read.\n", filename.c_str() );
_error.AppendToUserMsg( msg );
_error.GreaterSeverity( SEVERITY_INPUT_ERROR );
@@ -230,7 +231,7 @@ ofstream * STEPfile::OpenOutputFile( std::string filename ) {
}
} else {
if( SetFileName( filename ).empty() ) {
char msg[BUFSIZ+1];
char msg[BUFSIZ];
sprintf( msg, "can't find file: %s\nFile not written.\n", filename.c_str() );
_error.AppendToUserMsg( msg );
_error.GreaterSeverity( SEVERITY_INPUT_ERROR );
+1
View File
@@ -13,6 +13,7 @@ extern ofstream * logStream;
#include <ExpDict.h>
#include <STEPattribute.h>
#include <SdaiHeaderSchema.h>
#include "sc_memmgr.h"
Schema * s_header_section_schema = 0;
+1
View File
@@ -5,6 +5,7 @@
// regenerate it.
#include <SdaiHeaderSchema.h>
#include "sc_memmgr.h"
void HeaderInitSchemasAndEnts( Registry & reg ) {
Uniqueness_rule_ptr ur;
+1
View File
@@ -8,6 +8,7 @@
#include <ExpDict.h>
#include <STEPattribute.h>
#include <SdaiHeaderSchema.h>
#include "sc_memmgr.h"
void SdaiHEADER_SECTION_SCHEMAInit( Registry & reg ) {
header_section_schemat_time_stamp_text->ReferentType( t_sdaiSTRING );
+1
View File
@@ -5,6 +5,7 @@
// regenerate it.
#include <SdaiSchemaInit.h>
#include "sc_memmgr.h"
void HeaderSchemaInit( Registry & reg ) {
HeaderInitSchemasAndEnts( reg );
+1 -10
View File
@@ -11,6 +11,7 @@
*/
#include <cmdmgr.h>
#include "sc_memmgr.h"
ReplicateLinkNode * ReplicateList::FindNode( MgrNode * mn ) {
ReplicateLinkNode * rln = ( ReplicateLinkNode * )GetHead();
@@ -71,16 +72,6 @@ CmdMgr::CmdMgr() {
replicateList = new ReplicateList();
}
CmdMgr::~CmdMgr() {
delete completeList;
delete incompleteList;
delete deleteList;
delete mappedWriteList;
delete mappedViewList;
delete closeList;
delete replicateList;
}
void CmdMgr::ReplicateCmdList( MgrNode * mn ) {
if( !( replicateList->IsOnList( mn ) ) ) {
replicateList->AddNode( mn );
-1
View File
@@ -145,7 +145,6 @@ class SC_EDITOR_EXPORT CmdMgr {
public:
CmdMgr();
~CmdMgr();
// STATE LIST OPERATIONS
MgrNode * GetHead( stateEnum listType );
+5 -11
View File
@@ -6,7 +6,6 @@ set( clLazyFile_SRCS
p21HeaderSectionReader.cc
sectionReader.cc
lazyP21DataSectionReader.cc
judy/src/judy.c
)
set( SC_CLLAZYFILE_HDRS
@@ -18,13 +17,7 @@ set( SC_CLLAZYFILE_HDRS
lazyInstMgr.h
lazyTypes.h
sectionReader.h
sectionReader.h
instMgrHelper.h
judy/src/judy.h
judy/src/judyLArray.h
judy/src/judyL2Array.h
judy/src/judySArray.h
judy/src/judyS2Array.h
)
include_directories(
@@ -33,10 +26,11 @@ include_directories(
${SC_SOURCE_DIR}/src/cldai
${SC_SOURCE_DIR}/src/clstepcore
${SC_SOURCE_DIR}/src/clutils
${CMAKE_CURRENT_SOURCE_DIR}/judy/src
${SC_SOURCE_DIR}/src/base
${SC_SOURCE_DIR}/src/base/judy/src
)
set(_libdeps stepcore stepdai steputils stepeditor)
set(_libdeps stepcore stepdai steputils base stepeditor)
if(BUILD_SHARED_LIBS)
SC_ADDLIB(steplazyfile SHARED SOURCES ${clLazyFile_SRCS} LINK_LIBRARIES ${_libdeps})
@@ -46,11 +40,11 @@ if(BUILD_SHARED_LIBS)
endif()
if(BUILD_STATIC_LIBS)
set(_libdeps stepcore-static stepdai-static steputils-static stepeditor-static)
set(_libdeps stepcore-static stepdai-static steputils-static base-static stepeditor-static)
SC_ADDLIB(steplazyfile-static STATIC SOURCES ${clLazyFile_SRCS} LINK_LIBRARIES ${_libdeps})
endif()
SC_ADDEXEC(lazy_test SOURCES "lazy_test.cc;sc_benchmark.cc" LINK_LIBRARIES steplazyfile stepeditor NO_INSTALL)
SC_ADDEXEC(lazy_test SOURCES lazy_test.cc LINK_LIBRARIES steplazyfile stepeditor NO_INSTALL)
target_compile_definitions(lazy_test PRIVATE NO_REGISTRY)
install(FILES ${SC_CLLAZYFILE_HDRS}
+1 -1
View File
@@ -8,6 +8,7 @@
#include "lazyFileReader.h"
#include "sectionReader.h"
#include "lazyTypes.h"
#include "sc_memmgr.h"
#include "sc_export.h"
@@ -30,7 +31,6 @@ class SC_LAZYFILE_EXPORT headerSectionReader: public sectionReader {
//FIXME delete each instance?! maybe add to clear, since it iterates over everything already
//enum clearHow { rawData, deletePointers }
_headerInstances->clear();
delete _headerInstances;
}
};
+1
View File
@@ -5,6 +5,7 @@
#include <iostream>
#include "sectionReader.h"
#include "lazyTypes.h"
#include "sc_memmgr.h"
#include "sc_export.h"
+2
View File
@@ -16,6 +16,8 @@
* #include "lazyP28DataSectionReader.h"
* #include "p28HeaderSectionReader.h"
*/
#include "sc_memmgr.h"
class lazyInstMgr;
class Registry;
class headerSectionReader;
+1
View File
@@ -10,6 +10,7 @@
#include "lazyTypes.h"
#include "Registry.h"
#include "sc_memmgr.h"
#include "sc_export.h"
#include "judyLArray.h"
@@ -49,7 +49,6 @@ const namedLazyInstance lazyP21DataSectionReader::nextInstance() {
namedLazyInstance i;
i.refs = 0;
i.loc.section = 0;
i.loc.begin = _file.tellg();
i.loc.instance = readInstanceNumber();
if( ( _file.good() ) && ( i.loc.instance > 0 ) ) {
@@ -3,6 +3,7 @@
#include "lazyDataSectionReader.h"
#include "lazyFileReader.h"
#include "sc_memmgr.h"
#include "sc_export.h"
class SC_LAZYFILE_EXPORT lazyP21DataSectionReader: public lazyDataSectionReader {
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef LAZYTYPES_H
#define LAZYTYPES_H
#include "config.h"
#include "sc_cf.h"
#include <iostream>
#include <vector>
+3 -2
View File
@@ -1,7 +1,8 @@
#include "lazyInstMgr.h"
#include "./sc_benchmark.h"
#include <sc_benchmark.h>
#include "SdaiSchemaInit.h"
#include "config.h"
#include "sc_memmgr.h"
#include <sc_cf.h>
#ifndef NO_REGISTRY
# include "schema.h"
-1
View File
@@ -33,7 +33,6 @@ const namedLazyInstance p21HeaderSectionReader::nextInstance() {
namedLazyInstance i;
static instanceID nextFreeInstance = 4; // 1-3 are reserved per 10303-21
i.refs = 0;
i.loc.begin = _file.tellg();
i.loc.section = _sectionID;
skipWS();
+1
View File
@@ -2,6 +2,7 @@
#define P21HEADERSECTIONREADER_H
#include "headerSectionReader.h"
#include "sc_memmgr.h"
#include "sc_export.h"
class SC_LAZYFILE_EXPORT p21HeaderSectionReader: public headerSectionReader {
-149
View File
@@ -1,149 +0,0 @@
/// \file sc_benchmark.cc memory info, timers, etc for benchmarking
#include "./sc_benchmark.h"
#ifdef _WIN32
#include <windows.h>
#include <psapi.h>
#else
#include <sys/time.h>
#include <ctime>
#include <unistd.h>
#endif
#include <assert.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <sstream>
#include <ios>
/// mem values in kb, times in ms (granularity may be higher than 1ms)
benchVals getMemAndTime( ) {
benchVals vals;
#ifdef __linux__
// adapted from http://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-run-time-in-c
std::ifstream stat_stream( "/proc/self/stat", std::ios_base::in );
// dummy vars for leading entries in stat that we don't care about
std::string pid, comm, state, ppid, pgrp, session, tty_nr;
std::string tpgid, flags, minflt, cminflt, majflt, cmajflt;
std::string /*utime, stime,*/ cutime, cstime, priority, nice;
std::string O, itrealvalue, starttime;
// the fields we want
unsigned long utime, stime, vsize;
long rss;
stat_stream >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr
>> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt
>> utime >> stime >> cutime >> cstime >> priority >> nice
>> O >> itrealvalue >> starttime >> vsize >> rss; // don't care about the rest
long page_size_kb = sysconf( _SC_PAGE_SIZE ) / 1024; // in case x86-64 is configured to use 2MB pages
vals.physMemKB = rss * page_size_kb;
vals.virtMemKB = ( vsize / 1024 ) - vals.physMemKB;
vals.userMilliseconds = ( utime * 1000 ) / sysconf( _SC_CLK_TCK );
vals.sysMilliseconds = ( stime * 1000 ) / sysconf( _SC_CLK_TCK );
#elif defined(__APPLE__)
// http://stackoverflow.com/a/1911863/382458
#elif defined(_WIN32)
// http://stackoverflow.com/a/282220/382458 and http://stackoverflow.com/a/64166/382458
PROCESS_MEMORY_COUNTERS MemoryCntrs;
FILETIME CreationTime, ExitTime, KernelTime, UserTime;
long page_size_kb = 1024;
ULARGE_INTEGER kTime, uTime;
if( GetProcessMemoryInfo( GetCurrentProcess(), &MemoryCntrs, sizeof( MemoryCntrs ) ) ) {
vals.physMemKB = MemoryCntrs.PeakWorkingSetSize / page_size_kb;
vals.virtMemKB = MemoryCntrs.PeakPagefileUsage / page_size_kb;
} else {
vals.physMemKB = 0;
vals.virtMemKB = 0;
}
if( GetProcessTimes( GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime ) ) {
assert( sizeof( FILETIME ) == sizeof( ULARGE_INTEGER ) );
memcpy( &kTime, &KernelTime, sizeof( FILETIME ) );
memcpy( &uTime, &UserTime, sizeof( FILETIME ) );
vals.userMilliseconds = ( long )( uTime.QuadPart / 100000L );
vals.sysMilliseconds = ( long )( kTime.QuadPart / 100000L );
} else {
vals.userMilliseconds = 0;
vals.sysMilliseconds = 0;
}
#else
#warning Unknown platform!
#endif // __linux__
return vals;
}
// --------------------- benchmark class ---------------------
benchmark::benchmark( std::string description, bool debugMessages, std::ostream & o_stream ): ostr( o_stream ),
descr( description ), debug( debugMessages ), stopped( false ) {
initialVals = getMemAndTime( );
}
benchmark::~benchmark() {
if( !stopped ) {
stop( );
if( debug ) {
ostr << "benchmark::~benchmark(): stop was not called before destructor!" << std::endl;
}
out( );
}
}
void benchmark::stop( ) {
if( stopped ) {
std::cerr << "benchmark::stop(): tried to stop a benchmark that was already stopped!" << std::endl;
} else {
laterVals = getMemAndTime( );
stopped = true;
}
}
benchVals benchmark::get( ) {
if( !stopped ) {
laterVals = getMemAndTime( );
}
benchVals delta;
delta.physMemKB = laterVals.physMemKB - initialVals.physMemKB;
delta.virtMemKB = laterVals.virtMemKB - initialVals.virtMemKB;
delta.sysMilliseconds = laterVals.sysMilliseconds - initialVals.sysMilliseconds;
delta.userMilliseconds = laterVals.userMilliseconds - initialVals.userMilliseconds;
//If vm is negative, the memory had been requested before initialVals was set. Don't count it
if( delta.virtMemKB < 0 ) {
delta.physMemKB -= delta.virtMemKB;
delta.virtMemKB = 0;
}
return delta;
}
void benchmark::reset( std::string description ) {
descr = description;
reset();
}
void benchmark::reset( ) {
stopped = false;
initialVals = getMemAndTime();
}
std::string benchmark::str( ) {
return str( get( ) );
}
void benchmark::out() {
ostr << str( ) << std::endl;
}
std::string benchmark::str( const benchVals & bv ) {
std::stringstream ss;
ss << descr << " Physical memory: " << bv.physMemKB << "kb; Virtual memory: " << bv.virtMemKB;
ss << "kb; User CPU time: " << bv.userMilliseconds << "ms; System CPU time: " << bv.sysMilliseconds << "ms";
return ss.str();
}
-74
View File
@@ -1,74 +0,0 @@
#ifndef SC_BENCHMARK_H
#define SC_BENCHMARK_H
/// \file sc_benchmark.h memory info, timers, etc for benchmarking
#ifdef __cplusplus
#include <iostream>
#include <iosfwd>
#include <string>
extern "C" {
#endif
typedef struct {
long virtMemKB, physMemKB, userMilliseconds, sysMilliseconds;
} benchVals;
/** return a benchVals struct with four current statistics for this process:
* virtual and physical memory use in kb,
* user and system cpu time in ms
*
* not yet implemented for OSX or Windows.
*/
benchVals getMemAndTime( );
#ifdef __cplusplus
}
/** reports the difference in memory and cpu use between when the
* constructor is called and when stop() or the destructor is called.
*
* if the destructor is called and stop() had not previously been
* called, the results are printed to the ostream given in the
* constructor, prefixed by the description.
*
* depends on getMemAndTime() above - may not work on all platforms.
*/
class benchmark {
protected:
benchVals initialVals, laterVals;
#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable: 4251 )
#endif
std::ostream & ostr;
std::string descr;
#ifdef _MSC_VER
#pragma warning( pop )
#endif
bool debug, stopped;
public:
benchmark( std::string description = "", bool debugMessages = true, std::ostream & o_stream = std::cout );
/// if 'stopped' is false, uses str(true) to print to ostream
~benchmark( );
void reset( );
void reset( std::string description );
benchVals get( );
void stop( );
/// converts data member 'laterVals' into a string and returns it
std::string str( );
/// outputs result of str() on ostream 'ostr'
void out( );
/// converts 'bv' into a string, prefixed by data member 'descr'
std::string str( const benchVals & bv );
};
#endif //__cplusplus
#endif //SC_BENCHMARK_H
+7 -15
View File
@@ -5,14 +5,9 @@
#include <set>
#include <string>
#include <assert.h>
#include <limits.h>
#ifdef _WIN32
# define strtoull _strtoui64
# define ULLONG_MAX _UI64_MAX
#endif
#include "Registry.h"
#include "sc_strtoull.h"
#include "sdaiApplication_instance.h"
#include "read_func.h"
#include "SdaiSchemaInit.h"
@@ -31,14 +26,11 @@ sectionReader::sectionReader( lazyFileReader * parent, std::ifstream & file, std
_error = new ErrorDescriptor();
}
sectionReader::~sectionReader() {
delete _error;
}
std::streampos sectionReader::findNormalString( const std::string & str, bool semicolon ) {
std::streampos found = -1, startPos = _file.tellg(), nextTry = startPos;
int i = 0, l = str.length();
int c;
char c;
//i is reset every time a character doesn't match; if i == l, this means that we've found the entire string
while( i < l || semicolon ) {
@@ -92,7 +84,7 @@ std::streampos sectionReader::findNormalString( const std::string & str, bool se
// returns pointer to the contents of a static std::string
const char * sectionReader::getDelimitedKeyword( const char * delimiters ) {
static std::string str;
int c;
char c;
str.clear();
str.reserve( 100 );
skipWS();
@@ -122,7 +114,7 @@ const char * sectionReader::getDelimitedKeyword( const char * delimiters ) {
/// be the opening parenthesis; otherwise, it is likely to fail.
///NOTE *must* check return value!
std::streampos sectionReader::seekInstanceEnd( instanceRefs ** refs ) {
int c;
char c;
int parenDepth = 0;
while( c = _file.get(), _file.good() ) {
switch( c ) {
@@ -184,7 +176,7 @@ void sectionReader::locateAllInstances() {
}
instanceID sectionReader::readInstanceNumber() {
int c;
char c;
size_t digits = 0;
instanceID id = 0;
@@ -229,7 +221,7 @@ instanceID sectionReader::readInstanceNumber() {
_error->UserMsg( "A very large instance ID encountered" );
_error->DetailMsg( errorMsg.str() );
delete[] buffer;
delete buffer;
return 0;
}
@@ -259,7 +251,7 @@ instanceID sectionReader::readInstanceNumber() {
*/
SDAI_Application_instance * sectionReader::getRealInstance( const Registry * reg, long int begin, instanceID instance,
const std::string & typeName, const std::string & schName, bool header ) {
int c;
char c;
const char * tName = 0, * sName = 0; //these are necessary since typeName and schName are const
std::string comment;
Severity sev = SEVERITY_NULL;
+1 -1
View File
@@ -4,6 +4,7 @@
#include <fstream>
#include <set>
#include "lazyTypes.h"
#include "sc_memmgr.h"
#include "sc_export.h"
#include "errordesc.h"
#include "STEPcomplex.h"
@@ -37,7 +38,6 @@ class SC_LAZYFILE_EXPORT sectionReader {
// protected member functions
sectionReader( lazyFileReader * parent, std::ifstream & file, std::streampos start, sectionID sid );
~sectionReader();
/** Find a string, ignoring occurrences in comments or Part 21 strings (i.e. 'string with \S\' control directive' )
* \param str string to find
+2 -1
View File
@@ -125,12 +125,13 @@ set(SC_CLSTEPCORE_HDRS
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${SC_SOURCE_DIR}/src/base
${SC_SOURCE_DIR}/src/cldai
${SC_SOURCE_DIR}/src/cleditor
${SC_SOURCE_DIR}/src/clutils
)
set(_libdeps steputils stepdai)
set(_libdeps steputils stepdai base)
if(BUILD_SHARED_LIBS)
SC_ADDLIB(stepcore SHARED SOURCES ${LIBSTEPCORE_SRCS} LINK_LIBRARIES ${_libdeps})
+4 -3
View File
@@ -11,6 +11,7 @@
#include <ExpDict.h>
#include <Registry.h>
#include "sc_memmgr.h"
/* these may be shared between multiple Registry instances, so don't create/destroy in Registry ctor/dtor
* Name, FundamentalType, Originating Schema, Description */
@@ -78,7 +79,7 @@ void Registry::DeleteContents() {
const EntityDescriptor * Registry::FindEntity( const char * e, const char * schNm, int check_case ) const {
const EntityDescriptor * entd;
const SchRename * altlist;
char schformat[BUFSIZ+1], altName[BUFSIZ+1];
char schformat[BUFSIZ], altName[BUFSIZ];
if( check_case ) {
entd = ( EntityDescriptor * )SC_HASHfind( primordialSwamp, ( char * )e );
@@ -234,13 +235,13 @@ void Registry::RemoveType( const char * n ) {
*/
void Registry::RemoveClones( const EntityDescriptor & e ) {
const SchRename * alts = e.AltNameList();
struct Element * tmp;
while( alts ) {
struct Element * tmp = new Element;
tmp = new Element;
tmp->key = ( char * ) alts->objName();
SC_HASHsearch( primordialSwamp, tmp, HASH_DELETE );
alts = alts->next;
delete tmp;
}
}
+1 -7
View File
@@ -21,10 +21,9 @@ Severity EntityAggregate::ReadValue( istream & in, ErrorDescriptor * err,
int addFileId, int assignVal,
int exchangeFileFormat, const char * ) {
ErrorDescriptor errdesc;
char errmsg[BUFSIZ+1];
char errmsg[BUFSIZ];
int value_cnt = 0;
std::string buf;
bool free_item = false;
if( assignVal ) {
Empty(); // read new values and discard existing ones
@@ -68,7 +67,6 @@ Severity EntityAggregate::ReadValue( istream & in, ErrorDescriptor * err,
// It is used to read the values
else if( !assignVal ) {
item = new EntityNode();
free_item = true;
}
while( in.good() && ( c != ')' ) ) {
@@ -116,12 +114,8 @@ Severity EntityAggregate::ReadValue( istream & in, ErrorDescriptor * err,
} else { // expectation for end paren delim has not been met
err->GreaterSeverity( SEVERITY_INPUT_ERROR );
err->AppendToUserMsg( "Missing close paren for aggregate value" );
if (free_item)
delete item;
return SEVERITY_INPUT_ERROR;
}
if (free_item)
delete item;
return err->severity();
}
+2 -2
View File
@@ -9,7 +9,7 @@
/**
* \class EnumAggregate
* This is a minimal representation for a collection of SDAI_Enum
* This is a minimal representions for a collection of SDAI_Enum
*/
class SC_CORE_EXPORT EnumAggregate : public STEPaggregate {
public:
@@ -55,7 +55,7 @@ SC_CORE_EXPORT BOOLEANS * create_BOOLEANS();
/**
* * \class EnumNode
** This is a minimal representation for node in lists of SDAI_Enum
** This is a minimal representions for node in lists of SDAI_Enum
*/
class SC_CORE_EXPORT EnumNode : public STEPnode {
public:
+1 -1
View File
@@ -94,7 +94,7 @@ const char * IntNode::asStr( std::string & s ) {
}
const char * IntNode::STEPwrite( std::string & s, const char * ) {
char tmp[BUFSIZ+1];
char tmp[BUFSIZ];
if( value != S_INT_NULL ) {
sprintf( tmp, "%ld", value );
s = tmp;
+1 -1
View File
@@ -19,7 +19,7 @@ Severity SelectAggregate::ReadValue( istream & in, ErrorDescriptor * err,
int addFileId, int assignVal,
int exchangeFileFormat, const char * currSch ) {
ErrorDescriptor errdesc;
char errmsg[BUFSIZ+1];
char errmsg[BUFSIZ];
int value_cnt = 0;
std::string buf;
+2 -2
View File
@@ -11,7 +11,7 @@
/**
* * \class SelectAggregate
** This is a minimal representation for a collection of SDAI_Select
** This is a minimal represention for a collection of SDAI_Select
*/
class SC_CORE_EXPORT SelectAggregate : public STEPaggregate {
public:
@@ -35,7 +35,7 @@ typedef SelectAggregate_ptr SelectAggregate_var;
/**
* * \class SelectNode
** This is a minimal representation for node in lists of SDAI_Select
** This is a minimal representions for node in lists of SDAI_Select
*/
class SC_CORE_EXPORT SelectNode : public STEPnode {
public:
+2 -1
View File
@@ -17,6 +17,7 @@
#include <STEPattribute.h>
#include <instmgr.h>
#include <ExpDict.h>
#include "sc_memmgr.h"
/**
@@ -105,7 +106,7 @@ Severity STEPaggregate::ReadValue( istream & in, ErrorDescriptor * err,
(void) addFileId; //not used in ReadValue() for this class
ErrorDescriptor errdesc;
char errmsg[BUFSIZ+1];
char errmsg[BUFSIZ];
int value_cnt = 0;
std::string buf;
+10 -9
View File
@@ -19,6 +19,7 @@
#include <STEPaggregate.h>
#include <ExpDict.h>
#include <sdai.h>
#include "sc_memmgr.h"
// REAL_NUM_PRECISION is defined in STEPattribute.h, and is also used
// in aggregate real handling (STEPaggregate.cc) -- IMS 6 Jun 95
@@ -1262,20 +1263,20 @@ ostream & operator<< ( ostream & out, STEPattribute & a ) {
* value.
******************************************************************/
void STEPattribute::AddErrorInfo() {
char errStr[BUFSIZ+1];
char errStr[BUFSIZ];
errStr[0] = '\0';
if( SEVERITY_INPUT_ERROR < _error.severity() &&
_error.severity() < SEVERITY_NULL ) {
sprintf( errStr, " Warning: ATTRIBUTE '%s : %s : %d' - ",
Name(), TypeName().c_str(), Type() );
Name(), TypeName(), Type() );
_error.PrependToDetailMsg( errStr );
} else if( _error.severity() == SEVERITY_INPUT_ERROR ) {
sprintf( errStr, " Error: ATTRIBUTE '%s : %s : %d' - ",
Name(), TypeName().c_str(), Type() );
Name(), TypeName(), Type() );
_error.PrependToDetailMsg( errStr );
} else if( _error.severity() <= SEVERITY_BUG ) {
sprintf( errStr, " BUG: ATTRIBUTE '%s : %s : %d' - ",
Name(), TypeName().c_str(), Type() );
Name(), TypeName(), Type() );
_error.PrependToDetailMsg( errStr );
}
}
@@ -1292,7 +1293,7 @@ char STEPattribute::SkipBadAttr( istream & in, char * StopChars ) {
// read bad data until end of this attribute or entity.
char * foundCh = 0;
char c = '\0';
char errStr[BUFSIZ+1];
char errStr[BUFSIZ];
errStr[0] = '\0';
_error.GreaterSeverity( SEVERITY_WARNING );
@@ -1303,12 +1304,12 @@ char STEPattribute::SkipBadAttr( istream & in, char * StopChars ) {
if( in.eof() ) {
_error.GreaterSeverity( SEVERITY_INPUT_ERROR );
sprintf( errStr, " Error: attribute '%s : %s : %d' - %s.\n",
Name(), TypeName().c_str(), Type(),
Name(), TypeName(), Type(),
"Unexpected EOF when skipping bad attr value" );
_error.AppendToDetailMsg( errStr );
} else {
sprintf( errStr, " Error: attribute '%s : %s : %d' - %s.\n",
Name(), TypeName().c_str(), Type(), "Invalid value" );
Name(), TypeName(), Type(), "Invalid value" );
_error.AppendToDetailMsg( errStr );
}
in.putback( c );
@@ -1464,11 +1465,11 @@ const char * STEPattribute::Name() const {
return aDesc->Name();
}
std::string STEPattribute::TypeName() const {
const char * STEPattribute::TypeName() const {
if( _redefAttr ) {
return _redefAttr->TypeName();
}
return aDesc->TypeName();
return aDesc->TypeName().c_str();
}
BASE_TYPE STEPattribute::Type() const {
+1 -1
View File
@@ -208,7 +208,7 @@ class SC_CORE_EXPORT STEPattribute {
}
const char * Name() const;
std::string TypeName() const;
const char * TypeName() const;
BASE_TYPE Type() const;
BASE_TYPE NonRefType() const;
BASE_TYPE BaseType() const;
+1
View File
@@ -12,6 +12,7 @@
#include <STEPattributeList.h>
#include <STEPattribute.h>
#include "sc_memmgr.h"
AttrListNode::AttrListNode( STEPattribute * a ) {
attr = a;
+5 -4
View File
@@ -6,6 +6,7 @@
#include <STEPattribute.h>
#include <STEPaggregate.h>
#include <sstream>
#include "sc_memmgr.h"
extern const char *
ReadStdKeyword( istream & in, std::string & buf, int skipInitWS );
@@ -19,7 +20,7 @@ STEPcomplex::STEPcomplex( Registry * registry, int fileid )
STEPcomplex::STEPcomplex( Registry * registry, const std::string ** names,
int fileid, const char * schnm )
: SDAI_Application_instance( fileid, true ), sc( 0 ), _registry( registry ), visited( 0 ) {
char * nms[BUFSIZ+1];
char * nms[BUFSIZ];
int j, k;
head = this;
@@ -60,7 +61,7 @@ void STEPcomplex::Initialize( const char ** names, const char * schnm ) {
EntNode * ents = new EntNode( names ),
*eptr = ents, *prev = NULL, *enext;
const EntityDescriptor * enDesc;
char nm[BUFSIZ+1];
char nm[BUFSIZ];
bool invalid = false, outOfOrder = false;
// Splice out the invalid names from our list:
@@ -658,7 +659,7 @@ const char * STEPcomplex::WriteExtMapEntities( std::string & buf, const char * c
void STEPcomplex::CopyAs( SDAI_Application_instance * se ) {
if( !se->IsComplex() ) {
char errStr[BUFSIZ+1];
char errStr[BUFSIZ];
cerr << "STEPcomplex::CopyAs() called with non-complex entity: "
<< __FILE__ << __LINE__ << "\n" << _POC_ "\n";
sprintf( errStr,
@@ -699,7 +700,7 @@ SDAI_Application_instance * STEPcomplex::Replicate() {
}
nameList[i] = ( std::string * )0;
if( i == 63 ) {
char errStr[BUFSIZ+1];
char errStr[BUFSIZ];
cerr << "STEPcomplex::Replicate() name buffer too small: "
<< __FILE__ << __LINE__ << "\n" << _POC_ "\n";
sprintf( errStr,

Some files were not shown because too many files have changed in this diff Show More