Skip to content

Commit

Permalink
gsl: Add include guard to header file generated by the gsl command.
Browse files Browse the repository at this point in the history
[test gsl] [test cvode7]
  • Loading branch information
WarrenWeckesser committed Sep 10, 2024
1 parent 28fd73f commit 0eba7c3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/codegen_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
using namespace std;
using namespace GiNaC;


string to_upper(string s)
{
string t = s;
transform(t.begin(), t.end(), t.begin(), ::toupper);
return t;
}


static const char *datetimefmt = "Generated on %2d-%3s-%04d at %02d:%02d";
static char datetimebuf[48]; // Must be enough space to hold a copy of datetimefmt

Expand Down
5 changes: 3 additions & 2 deletions src/codegen_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//

#ifndef CODEGEN_UTILS
#define CODEGEN_UTILS 1
#ifndef CODEGEN_UTILS_H
#define CODEGEN_UTILS_H 1

std::string to_upper(std::string s);
char *DateTimeMsg();
void PrintVFGENComment(std::ofstream &fout, const char *prefix);
void Declare(std::ofstream &fout, std::string prefixstr, std::string typestr, GiNaC::lst name, std::string termstr);
Expand Down
7 changes: 0 additions & 7 deletions src/vf_cvode7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ using namespace std;
using namespace GiNaC;


string to_upper(string s)
{
string t = s;
transform(t.begin(), t.end(), t.begin(), ::toupper);
return t;
}

//
// PrintCVODE -- The CVODE Code Generator
//
Expand Down
8 changes: 8 additions & 0 deletions src/vf_gsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ using namespace GiNaC;
void VectorField::PrintGSL(map<string,string> options)
{
int nc, np, nv, na, nf;
string include_guard_name;

symbol t(IndependentVariable);
nc = conname_list.nops();
Expand Down Expand Up @@ -79,6 +80,11 @@ void VectorField::PrintGSL(map<string,string> options)
PrintVFGENComment(pout," * ");
pout << " */" << endl;
pout << endl;
include_guard_name = to_upper(Name());
include_guard_name.append("_GVF_H");
pout << "#ifndef " << include_guard_name << endl;
pout << "#define " << include_guard_name << endl;
pout << endl;

fout << "#include <math.h>" << endl;
fout << "#include <gsl/gsl_errno.h>" << endl;
Expand Down Expand Up @@ -252,6 +258,8 @@ void VectorField::PrintGSL(map<string,string> options)
}

fout.close();
pout << endl;
pout << "#endif /* " << include_guard_name << " */" << endl;
pout.close();

if (options["demo"] == "yes") {
Expand Down

0 comments on commit 0eba7c3

Please sign in to comment.