Skip to content

Commit f3d7f49

Browse files
committed
amplcsv: add AMPLs fopen and fclose to FileHandler in order to fix issue with Visual Studio
1 parent 971f646 commit f3d7f49

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

src/ampltableconnector/examples/amplcsv/src/handler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using namespace amplt;
88

99
static std::string name = "amplcsv";
10-
static std::string version = "beta 0.0.4";
10+
static std::string version = "beta 0.0.5";
1111

1212
class Handler:
1313
public Connector{

src/ampltableconnector/include/ampltableconnector.hpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,7 @@ class FileHandler {
507507
){
508508
this->ae = ae;
509509
this->logger = logger;
510-
f = fopen(filename.c_str(), mode.c_str());
511-
closed = false;
510+
f = ampl_fopen(filename.c_str(), mode.c_str());
512511

513512
if (f == NULL){
514513
std::string log_msg = "FileHandler: could not open " + filename;
@@ -517,9 +516,7 @@ class FileHandler {
517516
}
518517
};
519518
~FileHandler(){
520-
if (!closed){
521-
fclose(f);
522-
}
519+
close();
523520
};
524521
void ampl_fprintf(const char *format, ...){
525522

@@ -534,9 +531,20 @@ class FileHandler {
534531
};
535532
};
536533

534+
FILE* ampl_fopen(const char * filename, const char * mode){
535+
return ae->Fopen(filename, mode);
536+
};
537+
538+
int ampl_fclose(FILE * stream){
539+
int res = ae->Fclose(stream);
540+
return res;
541+
};
542+
537543
void close(){
538-
fclose(f);
539-
closed = true;
544+
if (f){
545+
ampl_fclose(f);
546+
f = NULL;
547+
}
540548
};
541549
};
542550

@@ -1044,6 +1052,15 @@ class Connector {
10441052
// These functions should be used instead of of standart library ones to prevent errors derived
10451053
// from diferent compiler implementations.
10461054

1055+
FILE* ampl_fopen(const char * filename, const char * mode){
1056+
return ae->Fopen(filename, mode);
1057+
};
1058+
1059+
int ampl_fclose(FILE * stream){
1060+
int res = ae->Fclose(stream);
1061+
return res;
1062+
};
1063+
10471064
int ampl_fprintf(FILE *stream, const char *format, ...){
10481065

10491066
va_list va;

0 commit comments

Comments
 (0)