Skip to content

Commit

Permalink
(Hopefully) solved problems with returned const char * values running
Browse files Browse the repository at this point in the history
out of scope.
  • Loading branch information
AbelHeinsbroek committed Aug 10, 2016
1 parent 1861c75 commit 3959ec7
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/IPhreeqc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1915,7 +1915,7 @@ std::string IPhreeqc::GetElements(int solution)
{
return this->PhreeqcPtr->get_elements(solution);
}
std::string IPhreeqc::GetSolutionList()
std::string IPhreeqc::GetSolutionList2(int id)
{
return this->PhreeqcPtr->get_solution_list();
return this->PhreeqcPtr->get_solution_list(id);
}
2 changes: 1 addition & 1 deletion src/IPhreeqc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ class IPQ_DLL_EXPORT IPhreeqc : public PHRQ_io
/**
* Returns a comma separated list of all the solutions in the current runstate
*/
std::string GetSolutionList();
std::string GetSolutionList2(int id);

public:
// overrides
Expand Down
29 changes: 21 additions & 8 deletions src/IPhreeqcLib.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <cassert>
#include <iostream>
#include <map>
#include <sstream>

#include "IPhreeqc.h"
#include "IPhreeqc.hpp"
Expand Down Expand Up @@ -1139,8 +1140,11 @@ GetSpecies(int id, int solution)
IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
if (IPhreeqcPtr)
{
static std::string result = IPhreeqcPtr->GetSpecies(solution);
return result.c_str();
static std::string str;
std::stringstream stream;
stream << IPhreeqcPtr->GetSpecies(solution);
str = stream.str();
return str.c_str();
}
return err_msg;
}
Expand All @@ -1161,8 +1165,11 @@ GetPhases(int id, int solution)
IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
if (IPhreeqcPtr)
{
static std::string result = IPhreeqcPtr->GetPhases(solution);
return result.c_str();
static std::string str;
std::stringstream stream;
stream << IPhreeqcPtr->GetPhases(solution);
str = stream.str();
return str.c_str();
}
return err_msg;
}
Expand All @@ -1173,8 +1180,11 @@ GetElements(int id, int solution)
IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
if (IPhreeqcPtr)
{
static std::string result = IPhreeqcPtr->GetElements(solution);
return result.c_str();
static std::string str;
std::stringstream stream;
stream << IPhreeqcPtr->GetElements(solution);
str = stream.str();
return str.c_str();
}
return err_msg;
}
Expand All @@ -1185,8 +1195,11 @@ GetSolutionList(int id)
IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
if (IPhreeqcPtr)
{
static std::string result = IPhreeqcPtr->GetSolutionList();
return result.c_str();
static std::string str;
std::stringstream stream;
stream << IPhreeqcPtr->GetSolutionList2(0);
str = stream.str();
return str.c_str();
}
return err_msg;
}
Expand Down
4 changes: 2 additions & 2 deletions src/phreeqcpp/Phreeqc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ cxxSolution * Phreeqc::find_solution(int id){
}
}

std::string Phreeqc::get_solution_list() {
std::string Phreeqc::get_solution_list(int id) {

std::string output;
std::string output;
std::map<int, cxxSolution>::const_iterator cit = Rxn_solution_map.begin();

for(; cit != Rxn_solution_map.end(); cit++){
Expand Down
2 changes: 1 addition & 1 deletion src/phreeqcpp/Phreeqc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ class Phreeqc
std::string get_species(int solution);
std::string get_phases(int solution);
std::string get_elements(int solution);
std::string get_solution_list();
std::string get_solution_list(int id);
double get_si(int solution, const char *phase);

PHRQ_io * Get_phrq_io(void) {return this->phrq_io;}
Expand Down
Loading

0 comments on commit 3959ec7

Please sign in to comment.