Skip to content

Commit

Permalink
Update to latest stepcode
Browse files Browse the repository at this point in the history
svn:revision:77972
svn:branch:extbuild
svn:account:starseeker
  • Loading branch information
starseeker committed Dec 15, 2020
1 parent 6718728 commit 57db755
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 99 deletions.
32 changes: 19 additions & 13 deletions src/other/ext/stepcode/src/base/sc_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#endif

#include <assert.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <iomanip>
Expand Down Expand Up @@ -83,8 +84,7 @@ benchVals getMemAndTime()

// --------------------- benchmark class ---------------------

benchmark::benchmark(std::string description, bool debugMessages, std::ostream &o_stream): ostr(o_stream),
descr(description), debug(debugMessages), stopped(false)
benchmark::benchmark(bool debugMessages): debug(debugMessages), stopped(false)
{
initialVals = getMemAndTime();
}
Expand All @@ -94,10 +94,14 @@ benchmark::~benchmark()
if(!stopped) {
stop();
if(debug) {
ostr << "benchmark::~benchmark(): stop was not called before destructor!" << std::endl;
std::cerr << "benchmark::~benchmark(): stop was not called before destructor!" << std::endl;
}
out();
}
if(benchVals_str) {
free((void *)benchVals_str);
benchVals_str = NULL;
}
}

void benchmark::stop()
Expand Down Expand Up @@ -129,32 +133,34 @@ benchVals benchmark::get()
return delta;
}

void benchmark::reset(std::string description)
{
descr = description;
reset();
}
void benchmark::reset()
{
stopped = false;
initialVals = getMemAndTime();
}

std::string benchmark::str()
const char *benchmark::str()
{
return str(get());
}

void benchmark::out()
{
ostr << str() << std::endl;
std::cout << str() << std::endl;
}

std::string benchmark::str(const benchVals &bv)
const char *benchmark::str(const benchVals &bv)
{
std::stringstream ss;
ss << descr << " Physical memory: " << bv.physMemKB << "kb; Virtual memory: " << bv.virtMemKB;
ss << " 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();
if(benchVals_str) {
free((void *)benchVals_str);
benchVals_str = NULL;
}
benchVals_str = (char *)calloc(ss.str().length() + 1, sizeof(char));
snprintf(benchVals_str, ss.str().length(), "%s", ss.str().c_str());
benchVals_str[ss.str().length()] = '\0';
return benchVals_str;
}

20 changes: 5 additions & 15 deletions src/other/ext/stepcode/src/base/sc_benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
#include "sc_export.h"

#ifdef __cplusplus
#include <iostream>
#include <iosfwd>
#include <string>

#include "sc_memmgr.h"
extern "C" {
Expand Down Expand Up @@ -43,34 +41,26 @@ class SC_BASE_EXPORT 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;
char *benchVals_str = NULL;

public:
benchmark(std::string description = "", bool debugMessages = true, std::ostream &o_stream = std::cout);
benchmark(bool debugMessages = true);

/// 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();
const char *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);
const char *str(const benchVals &bv);
};


Expand Down
60 changes: 54 additions & 6 deletions src/other/ext/stepcode/src/cldai/sdaiBinary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,91 @@
* and is not subject to copyright.
*/

#include <stdio.h>
#include <sstream>
#include <sdai.h>
#include "sc_memmgr.h"

SDAI_Binary::SDAI_Binary(const char *str, int max)
{
content = std::string(str, max);
if(content) {
free((void *)content);
}

content = (char *)calloc(max + 1, sizeof(char));
snprintf(content, max, "%s", str);
}

SDAI_Binary::SDAI_Binary(const char *s)
{
if(content) {
free((void *)content);
}

content = (char *)calloc(strlen(s) + 1, sizeof(char));
snprintf(content, strlen(s), "%s", s);
}

SDAI_Binary::SDAI_Binary(const std::string &s)
{
content = std::string(s);
if(content) {
free((void *)content);
}

content = (char *)calloc(s.length() + 1, sizeof(char));
snprintf(content, s.length(), "%s", s.c_str());
}

SDAI_Binary::SDAI_Binary(int i)
{
if(content) {
free((void *)content);
}

content = (char *)calloc(2, sizeof(char));
if(i) {
content[0] = '1';
} else {
content[0] = '0';
}
content[1] = '\0';
}

SDAI_Binary::~SDAI_Binary(void)
{
if(content) {
free((void *)content);
}
content = NULL;
}

SDAI_Binary &SDAI_Binary::operator= (const char *s)
{
content = std::string(s);
if(content) {
free((void *)content);
}

content = (char *)calloc(strlen(s) + 1, sizeof(char));
snprintf(content, strlen(s), "%s", s);
return *this;
}

void SDAI_Binary::clear(void)
{
content.clear();
if(content) {
free((void *)content);
}
content = NULL;
}

bool SDAI_Binary::empty(void) const
{
return content.empty();
return (!content) ? true : false;
}

const char *SDAI_Binary::c_str(void) const
{
return content.c_str();
return (const char *)content;
}

void SDAI_Binary::STEPwrite(ostream &out) const
Expand Down
18 changes: 8 additions & 10 deletions src/other/ext/stepcode/src/cldai/sdaiBinary.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#ifndef SDAIBINARY_H
#define SDAIBINARY_H 1

#include <string>
#include "sc_export.h"
#include "errordesc.h"

#include <iostream>

/*
* NIST STEP Core Class Library
Expand All @@ -16,20 +19,15 @@
class SC_DAI_EXPORT SDAI_Binary
{
private:
#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable: 4251 )
#endif
std::string content;
#ifdef _MSC_VER
#pragma warning( pop )
#endif
char *content = NULL;

public:

//constructor(s) & destructor
SDAI_Binary(const char *str = 0, int max = 0);
SDAI_Binary(const char *s);
SDAI_Binary(const std::string &s);
SDAI_Binary(int i);
~SDAI_Binary(void);

// operators
Expand All @@ -43,7 +41,7 @@ class SC_DAI_EXPORT SDAI_Binary
{
return c_str();
}
void STEPwrite(ostream &out = cout) const;
void STEPwrite(std::ostream &out = std::cout) const;
const char *STEPwrite(std::string &s) const;

Severity StrToVal(const char *s, ErrorDescriptor *err);
Expand Down
13 changes: 9 additions & 4 deletions src/other/ext/stepcode/src/cllazyfile/lazy_test.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <iostream>
#include <string>
#include "lazyInstMgr.h"
#include <sc_benchmark.h>
#include "SdaiSchemaInit.h"
#include "sc_memmgr.h"
#include "sc_benchmark.h"
#include <sc_cf.h>

#ifndef NO_REGISTRY
Expand Down Expand Up @@ -148,13 +150,15 @@ int main(int argc, char **argv)
#endif //NO_REGISTRY

instanceID instWithRef;
benchmark stats("================ p21 lazy load: scanning the file ================\n");
benchmark stats;
std::cout << "================ p21 lazy load: scanning the file ================\n";
mgr->openFile(argv[1]);
stats.stop();
benchVals scanStats = stats.get();
stats.out();

stats.reset("================ p21 lazy load: gathering statistics ================\n");
std::cout << "================ p21 lazy load: gathering statistics ================\n";
stats.reset();

int instances = mgr->totalInstanceCount();
std::cout << "Total instances: " << instances << " (" << (float)(scanStats.userMilliseconds * 1000) / instances << "us per instance, ";
Expand Down Expand Up @@ -197,7 +201,8 @@ int main(int argc, char **argv)
#endif //NO_REGISTRY

stats.out();
stats.reset("================ p21 lazy load: freeing memory ================\n");
std::cout << "================ p21 lazy load: freeing memory ================\n";
stats.reset();
delete mgr;
//stats will print from its destructor
}
Expand Down
4 changes: 2 additions & 2 deletions src/other/ext/stepcode/src/clstepcore/STEPattribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ class SC_CORE_EXPORT STEPattribute
ErrorDescriptor _error;
STEPattribute *_redefAttr;
public:
const AttrDescriptor *aDesc;
const AttrDescriptor *aDesc;

protected:
int refCount;
int refCount;

char SkipBadAttr(istream &in, char *StopChars);
void AddErrorInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,8 @@ SDAI_Application_instance *ReadEntityRef(istream &in, ErrorDescriptor *err, cons
case '@':
err->AppendToDetailMsg("Use of @ instead of # to identify entity.\n");
err->GreaterSeverity(SEVERITY_WARNING);
// no break statement here on purpose
[[gnu::fallthrough]];
// no break statement here on purpose
[[gnu::fallthrough]];
case '#': {
int id = -1;
in >> id;
Expand Down Expand Up @@ -914,11 +914,11 @@ Severity EntityValidLevel(const char *attrValue, // string contain entity ref
if((found1 > 0) || (found2 > 0)) {
if((found1 == 2) || (found2 == 2)) {
int ocnt = snprintf(messageBuf, BUFSIZ,
" Attribute's Entity Reference %s is %s data \'%s\'.\n",
attrValue, "followed by invalid", tmp);
if (ocnt < BUFSIZ) {
fprintf(stderr, "Warning - truncation of Attribute's Entry Reference msg\n");
}
" Attribute's Entity Reference %s is %s data \'%s\'.\n",
attrValue, "followed by invalid", tmp);
if(ocnt < BUFSIZ) {
fprintf(stderr, "Warning - truncation of Attribute's Entry Reference msg\n");
}
err->AppendToUserMsg(messageBuf);
err->AppendToDetailMsg(messageBuf);
err->GreaterSeverity(SEVERITY_WARNING);
Expand Down
Loading

0 comments on commit 57db755

Please sign in to comment.