Skip to content

Commit d27564c

Browse files
committed
Switch SdaiBinary content container to a plain C string to avoid the 4251 warning.
1 parent 3068398 commit d27564c

File tree

2 files changed

+62
-16
lines changed

2 files changed

+62
-16
lines changed

src/cldai/sdaiBinary.cc

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,91 @@
99
* and is not subject to copyright.
1010
*/
1111

12+
#include <stdio.h>
1213
#include <sstream>
1314
#include <sdai.h>
1415
#include "sc_memmgr.h"
1516

1617
SDAI_Binary::SDAI_Binary(const char *str, int max)
1718
{
18-
content = std::string(str, max);
19+
if(content) {
20+
free((void *)content);
21+
}
22+
23+
content = (char *)calloc(max + 1, sizeof(char));
24+
snprintf(content, max, "%s", str);
25+
}
26+
27+
SDAI_Binary::SDAI_Binary(const char *s)
28+
{
29+
if(content) {
30+
free((void *)content);
31+
}
32+
33+
content = (char *)calloc(strlen(s) + 1, sizeof(char));
34+
snprintf(content, strlen(s), "%s", s);
1935
}
2036

2137
SDAI_Binary::SDAI_Binary(const std::string &s)
2238
{
23-
content = std::string(s);
39+
if(content) {
40+
free((void *)content);
41+
}
42+
43+
content = (char *)calloc(s.length() + 1, sizeof(char));
44+
snprintf(content, s.length(), "%s", s.c_str());
45+
}
46+
47+
SDAI_Binary::SDAI_Binary(int i)
48+
{
49+
if(content) {
50+
free((void *)content);
51+
}
52+
53+
content = (char *)calloc(2, sizeof(char));
54+
if(i) {
55+
content[0] = '1';
56+
} else {
57+
content[0] = '0';
58+
}
59+
content[1] = '\0';
2460
}
2561

2662
SDAI_Binary::~SDAI_Binary(void)
2763
{
64+
if(content) {
65+
free((void *)content);
66+
}
67+
content = NULL;
2868
}
2969

3070
SDAI_Binary &SDAI_Binary::operator= (const char *s)
3171
{
32-
content = std::string(s);
72+
if(content) {
73+
free((void *)content);
74+
}
75+
76+
content = (char *)calloc(strlen(s) + 1, sizeof(char));
77+
snprintf(content, strlen(s), "%s", s);
3378
return *this;
3479
}
3580

3681
void SDAI_Binary::clear(void)
3782
{
38-
content.clear();
83+
if(content) {
84+
free((void *)content);
85+
}
86+
content = NULL;
3987
}
4088

4189
bool SDAI_Binary::empty(void) const
4290
{
43-
return content.empty();
91+
return (!content) ? true : false;
4492
}
4593

4694
const char *SDAI_Binary::c_str(void) const
4795
{
48-
return content.c_str();
96+
return (const char *)content;
4997
}
5098

5199
void SDAI_Binary::STEPwrite(ostream &out) const

src/cldai/sdaiBinary.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#ifndef SDAIBINARY_H
22
#define SDAIBINARY_H 1
33

4-
#include <string>
4+
#include "sc_export.h"
5+
#include "errordesc.h"
6+
7+
#include <iostream>
58

69
/*
710
* NIST STEP Core Class Library
@@ -16,20 +19,15 @@
1619
class SC_DAI_EXPORT SDAI_Binary
1720
{
1821
private:
19-
#ifdef _MSC_VER
20-
#pragma warning( push )
21-
#pragma warning( disable: 4251 )
22-
#endif
23-
std::string content;
24-
#ifdef _MSC_VER
25-
#pragma warning( pop )
26-
#endif
22+
char *content = NULL;
2723

2824
public:
2925

3026
//constructor(s) & destructor
3127
SDAI_Binary(const char *str = 0, int max = 0);
28+
SDAI_Binary(const char *s);
3229
SDAI_Binary(const std::string &s);
30+
SDAI_Binary(int i);
3331
~SDAI_Binary(void);
3432

3533
// operators
@@ -43,7 +41,7 @@ class SC_DAI_EXPORT SDAI_Binary
4341
{
4442
return c_str();
4543
}
46-
void STEPwrite(ostream &out = cout) const;
44+
void STEPwrite(std::ostream &out = std::cout) const;
4745
const char *STEPwrite(std::string &s) const;
4846

4947
Severity StrToVal(const char *s, ErrorDescriptor *err);

0 commit comments

Comments
 (0)