merged 3750-3846 of plusify; system.cxx and system.h need to be formated

removed char * and used std::string's and std::map's

git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3847 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
Scott R Charlton 2009-12-03 01:49:56 +00:00
parent dd1c83edec
commit 07d5fa7413
42 changed files with 829 additions and 662 deletions

View File

@ -55,6 +55,9 @@ cxxDictionary::add_phreeqc()
}
}
}
this->putString(std::string(""));
}
int
@ -123,6 +126,21 @@ std::string * cxxDictionary::int2string(int i)
}
}
std::string & cxxDictionary::int2stdstring(int i)
{
std::map < int,
std::string >::iterator
it = intkey.find(i);
if (it != intkey.end())
{
return (it->second);
}
else
{
exit(4);
}
}
char *
cxxDictionary::int2char(int i)
{
@ -136,3 +154,4 @@ cxxDictionary::int2char(int i)
return (NULL);
}
}

View File

@ -32,6 +32,7 @@ class cxxDictionary
int string2int(char *str);
std::string * int2string(int i);
std::string & int2stdstring(int i);
char *int2char(int i);

View File

@ -30,9 +30,9 @@ cxxExchComp::cxxExchComp()
totals.type = cxxNameDouble::ND_ELT_MOLES;
la = 0.0;
charge_balance = 0.0;
phase_name = NULL;
//phase_name = NULL;
phase_proportion = 0.0;
rate_name = NULL;
//rate_name = NULL;
formula_z = 0.0;
}
@ -43,15 +43,15 @@ cxxExchComp::cxxExchComp(struct exch_comp * exch_comp_ptr)
:
formula_totals(exch_comp_ptr->formula_totals), totals(exch_comp_ptr->totals)
{
formula = exch_comp_ptr->formula;
this->set_formula(exch_comp_ptr->formula);
moles = exch_comp_ptr->moles;
// totals in constructor
//formula_totals in constructor
la = exch_comp_ptr->la;
charge_balance = exch_comp_ptr->charge_balance;
phase_name = exch_comp_ptr->phase_name;
this->set_phase_name(exch_comp_ptr->phase_name);
phase_proportion = exch_comp_ptr->phase_proportion;
rate_name = exch_comp_ptr->rate_name;
this->set_rate_name(exch_comp_ptr->rate_name);
formula_z = exch_comp_ptr->formula_z;
}
@ -125,12 +125,13 @@ struct master *
cxxExchComp::get_master()
{
struct master *master_ptr = NULL;
for (std::map < char *, double, CHARSTAR_LESS >::iterator it =
for (std::map < std::string, double >::iterator it =
totals.begin(); it != totals.end(); it++)
{
/* Find master species */
char *eltName = it->first;
char *eltName = string_hsave(it->first.c_str());
assert(it->first.size() != 0);
struct element *elt_ptr = element_store(eltName);
if (elt_ptr->master == NULL)
{
@ -148,12 +149,13 @@ cxxExchComp::get_master()
}
if (master_ptr == NULL)
{
for (std::map < char *, double, CHARSTAR_LESS >::iterator it =
for (std::map < std::string, double >::iterator it =
this->formula_totals.begin(); it != formula_totals.end(); it++)
{
/* Find master species */
char *eltName = it->first;
char *eltName = string_hsave(it->first.c_str());
assert(it->first.size() != 0);
struct element *elt_ptr = element_store(eltName);
if (elt_ptr->master == NULL)
{
@ -203,16 +205,25 @@ struct exch_comp *
for (std::map < std::string, cxxExchComp >::iterator it = el.begin(); it != el.end();
++it)
{
exch_comp_ptr[i].formula = (*it).second.formula;
if ((*it).second.formula.size() == 0)
exch_comp_ptr[i].formula = NULL;
else
exch_comp_ptr[i].formula = string_hsave((*it).second.formula.c_str());
exch_comp_ptr[i].formula_z = (*it).second.formula_z;
exch_comp_ptr[i].totals = (*it).second.totals.elt_list();
exch_comp_ptr[i].moles = (*it).second.moles;
exch_comp_ptr[i].formula_totals = (*it).second.formula_totals.elt_list();
exch_comp_ptr[i].la = (*it).second.la;
exch_comp_ptr[i].charge_balance = (*it).second.charge_balance;
exch_comp_ptr[i].phase_name = (*it).second.phase_name;
if ((*it).second.phase_name.size() == 0)
exch_comp_ptr[i].phase_name = NULL;
else
exch_comp_ptr[i].phase_name = string_hsave((*it).second.phase_name.c_str());
exch_comp_ptr[i].phase_proportion = (*it).second.phase_proportion;
exch_comp_ptr[i].rate_name = (*it).second.rate_name;
if ((*it).second.rate_name.size() == 0)
exch_comp_ptr[i].rate_name = NULL;
else
exch_comp_ptr[i].rate_name = string_hsave((*it).second.rate_name.c_str());
exch_comp_ptr[i].master = (*it).second.get_master();
i++;
}
@ -242,12 +253,11 @@ cxxExchComp::dump_xml(std::ostream & s_oss, unsigned int indent) const
s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl;
s_oss << indent0 << "charge_balance=\"" << this->
charge_balance << "\"" << std::endl;
if (this->phase_name != NULL)
if (this->phase_name.size() != 0)
{
s_oss << indent0 << "phase_name=\"" << this->
phase_name << "\"" << std::endl;
s_oss << indent0 << "phase_name=\"" << this->phase_name << "\"" << std::endl;
}
if (this->rate_name != NULL)
if (this->rate_name.size() != 0)
{
s_oss << indent0 << "rate_name=\"" << this->
rate_name << "\"" << std::endl;
@ -297,11 +307,11 @@ cxxExchComp::dump_raw(std::ostream & s_oss, unsigned int indent) const
s_oss << indent1 << "-moles " << this->moles << std::endl;
s_oss << indent1 << "-la " << this->la << std::endl;
if (this->phase_name != NULL)
if (this->phase_name.size() != 0)
{
s_oss << indent1 << "-phase_name " << this->phase_name << std::endl;
}
if (this->rate_name != NULL)
if (this->rate_name.size() != 0)
{
s_oss << indent1 << "-rate_name " << this->rate_name << std::endl;
}
@ -373,14 +383,14 @@ cxxExchComp::read_raw(CParser & parser, bool check)
case 0: // formula
if (!(parser.get_iss() >> str))
{
this->formula = NULL;
this->formula.clear();
parser.incr_input_error();
parser.error_msg("Expected string value for formula.",
CParser::OT_CONTINUE);
}
else
{
this->formula = string_hsave(str.c_str());
this->formula = str;
}
formula_defined = true;
break;
@ -421,28 +431,28 @@ cxxExchComp::read_raw(CParser & parser, bool check)
case 4: // phase_name
if (!(parser.get_iss() >> str))
{
this->phase_name = NULL;
this->phase_name.clear();
parser.incr_input_error();
parser.error_msg("Expected string value for phase_name.",
CParser::OT_CONTINUE);
}
else
{
this->phase_name = string_hsave(str.c_str());
this->phase_name = str;
}
break;
case 5: // rate_name
if (!(parser.get_iss() >> str))
{
this->rate_name = NULL;
this->rate_name.clear();
parser.incr_input_error();
parser.error_msg("Expected string value for rate_name.",
CParser::OT_CONTINUE);
}
else
{
this->rate_name = string_hsave(str.c_str());
this->rate_name = str;
}
break;
@ -538,7 +548,7 @@ cxxExchComp::add(const cxxExchComp & addee, double extensive)
double ext1, ext2, f1, f2;
if (extensive == 0.0)
return;
if (addee.formula == NULL)
if (addee.formula.size() == 0)
return;
// this and addee must have same formula
// otherwise generate a new exchcomp with multiply
@ -558,13 +568,13 @@ cxxExchComp::add(const cxxExchComp & addee, double extensive)
//char * formula;
//cxxNameDouble formula_totals;
if (this->formula == NULL && addee.formula == NULL)
if (this->formula.size() == 0 && addee.formula.size() == 0)
{
return;
}
assert(this->formula == addee.formula);
assert(this->formula_z == addee.formula_z);
if (this->formula == NULL && addee.formula != NULL)
if (this->formula.size() == 0 && addee.formula.size() != 0)
{
this->formula = addee.formula;
this->formula_totals = addee.formula_totals;
@ -589,7 +599,7 @@ cxxExchComp::add(const cxxExchComp & addee, double extensive)
input_error++;
return;
}
else if (this->phase_name != NULL)
else if (this->phase_name.size() != 0)
{
this->phase_proportion =
this->phase_proportion * f1 + addee.phase_proportion * f2;
@ -605,14 +615,14 @@ cxxExchComp::add(const cxxExchComp & addee, double extensive)
input_error++;
return;
}
else if (this->rate_name != NULL)
else if (this->rate_name.size() != 0)
{
//double phase_proportion;
this->phase_proportion =
this->phase_proportion * f1 + addee.phase_proportion * f2;
}
if ((this->rate_name != NULL && addee.phase_name != NULL) ||
(this->phase_name != NULL && addee.rate_name != NULL))
if ((this->rate_name.size() != 0 && addee.phase_name.size() != 0) ||
(this->phase_name.size() != 0 && addee.rate_name.size() != 0))
{
std::ostringstream oss;
oss <<
@ -665,15 +675,15 @@ cxxExchComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
extern cxxDictionary dictionary;
int i = *ii;
int d = *dd;
this->formula = dictionary.int2char(ints[i++]);
this->formula = dictionary.int2stdstring(ints[i++]);
this->moles = doubles[d++];
this->formula_totals.mpi_unpack(ints, &i, doubles, &d);
this->totals.mpi_unpack(ints, &i, doubles, &d);
this->la = doubles[d++];
this->charge_balance = doubles[d++];
this->phase_name = dictionary.int2char(ints[i++]);
this->phase_name = dictionary.int2stdstring(ints[i++]);
this->phase_proportion = doubles[d++];
this->rate_name = dictionary.int2char(ints[i++]);
this->rate_name = dictionary.int2stdstring(ints[i++]);
this->formula_z = doubles[d++];
*ii = i;
*dd = d;

View File

@ -10,8 +10,6 @@
#include <list> // std::list
#include <vector> // std::vector
#include "char_star.h"
class cxxExchComp
{
@ -31,13 +29,16 @@ class cxxExchComp
void read_raw(CParser & parser, bool check=true);
char *get_formula() const
const std::string &get_formula() const
{
return this->formula;
}
void set_formula(char *cstring)
{
this->formula = cstring;
if (cstring != NULL)
this->formula = std::string(cstring);
else
this->formula.clear();
}
double get_moles() const
{
@ -63,13 +64,16 @@ class cxxExchComp
{
this->charge_balance = d;
}
char *get_phase_name() const
const std::string &get_phase_name() const
{
return this->phase_name;
}
void set_phase_name(char *cstring)
{
this->phase_name = cstring;
if (cstring != NULL)
this->phase_name = std::string(cstring);
else
this->phase_name.clear();
}
double get_phase_proportion() const
{
@ -79,13 +83,16 @@ class cxxExchComp
{
this->phase_proportion = d;
}
char *get_rate_name() const
const std::string &get_rate_name() const
{
return this->rate_name;
}
void set_rate_name(char *cstring)
{
this->rate_name = cstring;
if (cstring != NULL)
this->rate_name = std::string(cstring);
else
this->rate_name.clear();
}
double get_formula_z() const
{
@ -135,15 +142,15 @@ class cxxExchComp
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
#endif
protected:
char *formula;
std::string formula;
double moles;
cxxNameDouble formula_totals;
cxxNameDouble totals;
double la;
double charge_balance;
char *phase_name;
std::string phase_name;
double phase_proportion;
char *rate_name;
std::string rate_name;
double formula_z; // charge on formula
public:

View File

@ -177,7 +177,7 @@ cxxExchange::get_related_phases()
for (std::map < std::string, cxxExchComp >::const_iterator it =
this->exchComps.begin(); it != this->exchComps.end(); ++it)
{
if ((*it).second.get_phase_name() == NULL)
if ((*it).second.get_phase_name().size() == 0)
continue;
return (true);
}
@ -190,7 +190,7 @@ cxxExchange::get_related_rate()
for (std::map < std::string, cxxExchComp >::const_iterator it =
this->exchComps.begin(); it != this->exchComps.end(); ++it)
{
if ((*it).second.get_rate_name() == NULL)
if ((*it).second.get_rate_name().size() == 0)
continue;
return (true);
}

View File

@ -58,16 +58,16 @@ class cxxExchange:public cxxNumKeyword
void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles);
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
#endif
private:
private:
void add(const cxxExchange & addee, double extensive);
// not written
void dump_xml(std::ostream & os, unsigned int indent = 0) const;
protected:
std::map < std::string, cxxExchComp > exchComps;
protected:
std::map < std::string, cxxExchComp > exchComps;
bool pitzer_exchange_gammas;
cxxNameDouble totals;
public:
public:
};

View File

@ -136,8 +136,9 @@ cxxGasPhase::cxxGasPhaseComp2gas_comp()
for (cxxNameDouble::iterator it = this->gasPhaseComps.begin();
it != this->gasPhaseComps.end(); it++)
{
gas_comp_ptr[i].name = it->first;
gas_comp_ptr[i].phase = phase_bsearch(it->first, &n, TRUE);
gas_comp_ptr[i].name = string_hsave(it->first.c_str());
assert(it->first.size() != 0);
gas_comp_ptr[i].phase = phase_bsearch(it->first.c_str(), &n, TRUE);
gas_comp_ptr[i].p_read = 0;
gas_comp_ptr[i].moles = it->second;
gas_comp_ptr[i].initial_moles = 0;
@ -446,7 +447,7 @@ cxxGasPhase::totalize()
{
struct phase *phase_ptr;
int l;
phase_ptr = phase_bsearch(it->first, &l, FALSE);
phase_ptr = phase_bsearch(it->first.c_str(), &l, FALSE);
if (phase_ptr != NULL)
{
cxxNameDouble phase_formula(phase_ptr->next_elt);

View File

@ -11,7 +11,6 @@
#include <list> // std::list
#include <vector> // std::vector
#include "char_star.h"
#include "cxxMix.h"
class cxxGasPhase:public cxxNumKeyword
@ -52,17 +51,17 @@ class cxxGasPhase:public cxxNumKeyword
return this->totals;
};
private:
private:
void add(const cxxGasPhase & addee, double extensive);
protected:
protected:
cxxNameDouble gasPhaseComps;
GP_TYPE type;
double total_p;
double volume;
cxxNameDouble totals;
public:
public:
//static std::map<int, cxxGasPhase>& map;
};

View File

@ -39,7 +39,7 @@ cxxSolution(solution_ptr)
//, pe(cxxPe_Data::alloc())
{
density = solution_ptr->density;
units = solution_ptr->units;
this->set_units(solution_ptr->units);
// totals
for (int i = 0; solution_ptr->totals[i].description != NULL; i++)
{
@ -66,7 +66,10 @@ cxxISolution::cxxISolution2solution()
struct solution *soln_ptr = this->cxxSolution2solution();
soln_ptr->new_def = TRUE;
soln_ptr->density = this->density;
soln_ptr->units = string_hsave(this->units.c_str());
if (this->units.size() == 0)
soln_ptr->units = NULL;
else
soln_ptr->units = string_hsave(this->units.c_str());
soln_ptr->default_pe = this->default_pe;
// pe
soln_ptr->pe = (struct pe_data *) pe_data_free(soln_ptr->pe);
@ -85,16 +88,16 @@ cxxISolution::ConvertUnits()
{
double sum_solutes = 0;
// foreach conc
std::map < char *, cxxISolutionComp, CHARSTAR_LESS >::iterator iter =
std::map < std::string, cxxISolutionComp >::iterator iter =
this->comps.begin();
for (; iter != this->comps.end(); ++iter)
{
struct master *master_ptr = master_bsearch(iter->first);
struct master *master_ptr = master_bsearch(iter->first.c_str());
if (master_ptr != NULL && (master_ptr->minor_isotope == TRUE))
continue;
//if (iter->second.get_description() == "H(1)" || iter->second.get_description() == "E") continue;
if (strcmp(iter->second.get_description(), "H(1)") == 0
|| strcmp(iter->second.get_description(), "E"))
if (strcmp(iter->second.get_description().c_str(), "H(1)") == 0
|| strcmp(iter->second.get_description().c_str(), "E"))
continue;
if (iter->second.get_input_conc() <= 0.0)
continue;

View File

@ -47,6 +47,13 @@ class cxxISolution:public cxxSolution
{
units = units;
}
void set_units(char * units)
{
if (units != NULL)
this->units = std::string(units);
else
this->units.clear();
}
//char * get_redox()const {return this->pe[this->default_pe].get_name();}
@ -72,7 +79,8 @@ class cxxISolution:public cxxSolution
friend class cxxISolutionComp; // for this->pe access
double density;
std::string units;
std::map < char *, cxxISolutionComp, CHARSTAR_LESS > comps;
//std::map < char *, cxxISolutionComp, CHARSTAR_LESS > comps;
std::map < std::string, cxxISolutionComp > comps;
struct pe_data *pes;
int default_pe;

View File

@ -21,14 +21,14 @@ gfw(0.0)
}
cxxISolutionComp::cxxISolutionComp(struct conc *conc_ptr)
{
description = conc_ptr->description;
this->set_description(conc_ptr->description);
moles = conc_ptr->moles;
input_conc = conc_ptr->input_conc;
units = conc_ptr->units;
equation_name = conc_ptr->equation_name;
this->set_units(conc_ptr->units);
this->set_equation_name(conc_ptr->equation_name);
phase_si = conc_ptr->phase_si;
n_pe = conc_ptr->n_pe;
as = conc_ptr->as;
this->set_as(conc_ptr->as);
gfw = conc_ptr->gfw;
//skip = conc_ptr->skip;
//phase = conc_ptr->phase;
@ -67,9 +67,8 @@ struct conc *cxxISolutionComp::concarray(std::map <char *, double, CHARSTAR_LESS
}
*/
struct conc *
cxxISolutionComp::cxxISolutionComp2conc(const std::map < char *,
cxxISolutionComp,
CHARSTAR_LESS > &totals)
cxxISolutionComp::cxxISolutionComp2conc(const std::map < std::string,
cxxISolutionComp > &totals)
// for ISolutions
// takes a std::vector cxxISolutionComp structures
// returns list of conc structures
@ -80,18 +79,23 @@ cxxISolutionComp::cxxISolutionComp2conc(const std::map < char *,
if (c == NULL)
malloc_error();
int i = 0;
for (std::map < char *, cxxISolutionComp,
CHARSTAR_LESS >::const_iterator it = totals.begin();
for (std::map < std::string, cxxISolutionComp >::const_iterator it = totals.begin();
it != totals.end(); ++it)
{
c[i].description = it->second.description;
c[i].description = string_duplicate(it->second.description.c_str());
c[i].moles = it->second.moles;
c[i].input_conc = it->second.input_conc;
c[i].units = it->second.units;
c[i].equation_name = it->second.equation_name;
if (it->second.units.size() == 0)
c[i].units = NULL;
else
c[i].units = string_hsave(it->second.units.c_str());
if (it->second.equation_name.size() == 0)
c[i].equation_name = NULL;
else
c[i].equation_name = string_hsave(it->second.equation_name.c_str());
c[i].phase_si = it->second.phase_si;
c[i].n_pe = it->second.n_pe;
c[i].as = it->second.as;
c[i].as = string_hsave(it->second.as.c_str());
c[i].gfw = it->second.gfw;
//c[i].skip = 0;
c[i].phase = NULL;
@ -108,11 +112,11 @@ cxxISolutionComp::set_gfw()
if (this->gfw > 0.0)
return;
// calculate gfw from as or from master species gfw
if (this->as != NULL)
if (this->as.size() != 0)
{
/* use given chemical formula to calculate gfw */
double gfw;
if (compute_gfw(this->as, &gfw) == ERROR)
if (compute_gfw(this->as.c_str(), &gfw) == ERROR)
{
std::ostringstream oss;
oss << "Could not compute gfw, " << this->as;
@ -121,8 +125,8 @@ cxxISolutionComp::set_gfw()
return;
}
//if (this->description == "Alkalinity" && this->as == "CaCO3")
if (strcmp(this->description, "Alkalinity") == 0
&& strcmp(this->as, "CaCO3"))
if (strcmp(this->description.c_str(), "Alkalinity") == 0
&& strcmp(this->as.c_str(), "CaCO3"))
{
gfw /= 2.;
}

View File

@ -12,7 +12,6 @@
#include <map> // std::map
#include <vector>
#include <set>
#include "char_star.h"
// forward declarations
class cxxISolution; // reqd for read and dump_xml
@ -30,13 +29,16 @@ class cxxISolutionComp
void dump_xml(std::ostream & os, unsigned int indent = 0) const;
char *get_description() const
const std::string &get_description() const
{
return this->description;
}
void set_description(char *description)
{
this->description = description;
if (description != NULL)
this->description = std::string(description);
else
this->description.clear();
}
double get_moles() const
@ -63,16 +65,23 @@ class cxxISolutionComp
}
void set_units(char *units)
{
this->units = units;
if (units != NULL)
this->units = std::string(units);
else
this->units.clear();
}
char *get_equation_name() const
const std::string &get_equation_name() const
{
return this->equation_name;
}
void set_equation_name(char *equation_name)
{
this->equation_name = equation_name;
if (equation_name != NULL)
this->equation_name = std::string(equation_name);
else
this->equation_name.clear();
}
double get_phase_si() const
@ -93,13 +102,16 @@ class cxxISolutionComp
this->n_pe = n_pe;
}
char *get_as() const
const std::string &get_as() const
{
return this->as;
}
void set_as(char *as)
{
this->as = as;
if (as != NULL)
this->as = std::string(as);
else
this->as.clear();
}
//double get_gfw()const {return this->gfw;}
@ -115,23 +127,21 @@ class cxxISolutionComp
bool operator<(const cxxISolutionComp & conc) const
{
return::strcmp(this->description, conc.description) < 0;
return ::strcmp(this->description.c_str(), conc.description.c_str()) < 0;
}
static struct conc *cxxISolutionComp2conc(const std::map < char *,
cxxISolutionComp,
CHARSTAR_LESS > &t);
static struct conc *cxxISolutionComp2conc(const std::map < std::string, cxxISolutionComp > &t);
private:
char *description;
double moles;
double input_conc;
char *units;
char *equation_name;
double phase_si;
int n_pe;
char *as;
double gfw;
std::string description;
double moles;
double input_conc;
std::string units;
std::string equation_name;
double phase_si;
int n_pe;
std::string as;
double gfw;
};
#endif // ISOLUTIONCOMP_H_INCLUDED

View File

@ -24,7 +24,6 @@ cxxKineticsComp::cxxKineticsComp()
// default constructor for cxxKineticsComp
//
{
rate_name = NULL;
tol = 1e-8;
m = 0.0;
m0 = 0.0;
@ -39,7 +38,7 @@ cxxKineticsComp::cxxKineticsComp(struct kinetics_comp *kinetics_comp_ptr)
:
namecoef(kinetics_comp_ptr->list, kinetics_comp_ptr->count_list)
{
rate_name = kinetics_comp_ptr->rate_name;
this->set_rate_name(kinetics_comp_ptr->rate_name);
tol = kinetics_comp_ptr->tol;
m = kinetics_comp_ptr->m;
m0 = kinetics_comp_ptr->m0;
@ -71,7 +70,10 @@ struct kinetics_comp *
for (std::map < std::string, cxxKineticsComp >::iterator it = el.begin();
it != el.end(); ++it)
{
kinetics_comp_ptr[i].rate_name = (*it).second.rate_name;
if ((*it).second.rate_name.size() == 0)
kinetics_comp_ptr[i].rate_name = NULL;
else
kinetics_comp_ptr[i].rate_name = string_hsave((*it).second.rate_name.c_str());
kinetics_comp_ptr[i].list = (*it).second.namecoef.name_coef();
kinetics_comp_ptr[i].count_list = (int) (*it).second.namecoef.size();
kinetics_comp_ptr[i].tol = (*it).second.tol;
@ -255,14 +257,14 @@ cxxKineticsComp::read_raw(CParser & parser, bool check)
case 0: // rate_name
if (!(parser.get_iss() >> str))
{
this->rate_name = NULL;
this->rate_name.clear();
parser.incr_input_error();
parser.error_msg("Expected string value for rate_name.",
CParser::OT_CONTINUE);
}
else
{
this->rate_name = string_hsave(str.c_str());
this->rate_name = str;
}
rate_name_defined = true;
break;
@ -401,7 +403,7 @@ cxxKineticsComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
extern cxxDictionary dictionary;
int i = *ii;
int d = *dd;
this->rate_name = dictionary.int2char(ints[i++]);
this->rate_name = dictionary.int2stdstring(ints[i++]);
this->namecoef.mpi_unpack(ints, &i, doubles, &d);
this->tol = doubles[d++];
this->m = doubles[d++];
@ -422,11 +424,11 @@ cxxKineticsComp::add(const cxxKineticsComp & addee, double extensive)
{
if (extensive == 0.0)
return;
if (addee.rate_name == NULL)
if (addee.rate_name.size() == 0)
return;
// this and addee must have same name
// otherwise generate a new KineticsComp with multiply
if (this->rate_name == NULL && addee.rate_name == NULL)
if (this->rate_name.size() == 0 && addee.rate_name.size() == 0)
{
return;
}

View File

@ -10,8 +10,6 @@
#include <list> // std::list
#include <vector> // std::vector
#include "char_star.h"
class cxxKineticsComp
{
@ -28,10 +26,17 @@ public:
void read_raw(CParser & parser, bool check = true);
char *get_rate_name() const
const std::string &get_rate_name() const
{
return this->rate_name;
}
void set_rate_name(char * s)
{
if (s != NULL)
this->rate_name = std::string(s);
else
this->rate_name.clear();
}
#ifdef USE_MPI
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
@ -41,13 +46,13 @@ public:
void multiply(double extensive);
protected:
char *rate_name;
cxxNameDouble namecoef; //stoichiometry of reaction
double tol;
double m;
double m0;
double moles;
std::vector < double >d_params;
std::string rate_name;
cxxNameDouble namecoef; //stoichiometry of reaction
double tol;
double m;
double m0;
double moles;
std::vector < double >d_params;
public:

View File

@ -144,7 +144,7 @@ cxxNameDouble::elt_list()
int i = 0;
for (iterator it = this->begin(); it != this->end(); ++it)
{
elt_list_ptr[i].elt = element_store(it->first);
elt_list_ptr[i].elt = element_store(it->first.c_str());
elt_list_ptr[i].coef = it->second;
i++;
}
@ -177,7 +177,7 @@ cxxNameDouble::master_activity() const
for (const_iterator it = (*this).begin(); it != (*this).end();
it++)
{
master_activity_ptr[i].description = (char *) it->first;
master_activity_ptr[i].description = string_hsave(it->first.c_str());
master_activity_ptr[i].la = it->second;
i++;
}
@ -198,7 +198,7 @@ cxxNameDouble::master_activity() const
for (const_iterator it = (*this).begin(); it != (*this).end();
it++)
{
master_activity_ptr[i].description = (char *) it->first;
master_activity_ptr[i].description = string_hsave(it->first.c_str());
master_activity_ptr[i].la = it->second;
i++;
}
@ -227,7 +227,7 @@ cxxNameDouble::conc() const
int i = 0;
for (const_iterator it = (*this).begin(); it != (*this).end(); ++it)
{
c[i].description = (char *) it->first;
c[i].description = string_hsave(it->first.c_str());
c[i].moles = it->second;
c[i].input_conc = it->second;
c[i].units = NULL;
@ -259,7 +259,7 @@ cxxNameDouble::name_coef() const
int i = 0;
for (const_iterator it = (*this).begin(); it != (*this).end(); ++it)
{
name_coef_ptr[i].name = it->first;
name_coef_ptr[i].name = string_hsave(it->first.c_str());
name_coef_ptr[i].coef = it->second;
i++;
}
@ -468,7 +468,6 @@ cxxNameDouble::mpi_pack(std::vector < int >&ints,
ints.push_back((int) (*this).size());
for (const_iterator it = (*this).begin(); it != (*this).end(); it++)
{
assert(it->first != NULL);
int n = dictionary.string2int(it->first);
ints.push_back(n);
doubles.push_back(it->second);
@ -500,6 +499,28 @@ cxxNameDouble::mpi_pack(int *ints, int *ii, double *doubles, int *dd)
*dd = d;
}
//void
//cxxNameDouble::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
//{
// int i = *ii;
// int d = *dd;
// extern cxxDictionary dictionary;
// this->clear();
// int count = ints[i++];
// for (int j = 0; j < count; j++)
// {
// int n = ints[i++];
// assert(n >= 0);
// std::string * str = dictionary.int2string(n);
// if (str != NULL)
// {
// char *cstr = string_hsave(str->c_str());
// (*this)[cstr] = doubles[d++];
// }
// }
// *ii = i;
// *dd = d;
//}
void
cxxNameDouble::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
{
@ -512,11 +533,10 @@ cxxNameDouble::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
{
int n = ints[i++];
assert(n >= 0);
std::string * str = dictionary.int2string(n);
if (str != NULL)
std::string str = dictionary.int2stdstring(n);
if (str.size() != 0)
{
char *cstr = string_hsave(str->c_str());
(*this)[cstr] = doubles[d++];
(*this)[str] = doubles[d++];
}
}
*ii = i;

View File

@ -8,12 +8,9 @@
#include <list> // std::list
#include <vector> // std::vector
//#include "global.h"
#include "char_star.h"
#include "Parser.h"
class cxxNameDouble:public
std::map < char *, double,
CHARSTAR_LESS >
std::map < std::string, double >
{
public:

View File

@ -10,7 +10,6 @@
#include <list> // std::list
#include <vector> // std::vector
#include "char_star.h"
#include "PPassemblageComp.h"
#include "cxxMix.h"
@ -53,18 +52,18 @@ class cxxPPassemblage:public cxxNumKeyword
void ORCH_store_global(std::map < std::string, double >output_map);
#endif
private:
private:
void add(const cxxPPassemblage & addee, double extensive);
// not written
void dump_xml(std::ostream & os, unsigned int indent = 0) const;
protected:
protected:
//std::list < cxxPPassemblageComp > ppAssemblageComps;
std::map <std::string, cxxPPassemblageComp > ppAssemblageComps;
std::map <std::string, cxxPPassemblageComp > ppAssemblageComps;
cxxNameDouble eltList;
cxxNameDouble totals;
public:
public:
//static std::map<int, cxxPPassemblage>& map;
};

View File

@ -25,8 +25,6 @@ cxxPPassemblageComp::cxxPPassemblageComp()
// default constructor for cxxPPassemblageComp
//
{
name = NULL;
add_formula = NULL;
si = 0;
moles = 0;
delta = 0;
@ -41,8 +39,8 @@ cxxPPassemblageComp::cxxPPassemblageComp(struct pure_phase * pure_phase_ptr)
// constructor for cxxPPassemblageComp from struct pure_phase
//
{
name = pure_phase_ptr->name;
add_formula = pure_phase_ptr->add_formula;
this->set_name(pure_phase_ptr->name);
this->set_add_formula(pure_phase_ptr->add_formula);
si = pure_phase_ptr->si;
moles = pure_phase_ptr->moles;
delta = pure_phase_ptr->delta;
@ -60,7 +58,7 @@ struct phase *
cxxPPassemblageComp::get_phase()
{
int i;
return phase_bsearch(this->name, &i, FALSE);
return phase_bsearch(this->name.c_str(), &i, FALSE);
}
struct pure_phase *
@ -80,8 +78,14 @@ struct pure_phase *
it != el.end(); ++it)
{
pure_phase_ptr[i].phase = (*it).second.get_phase();
pure_phase_ptr[i].name = (*it).second.name;
pure_phase_ptr[i].add_formula = (*it).second.add_formula;
if ((*it).second.name.size() == 0)
pure_phase_ptr[i].name = NULL;
else
pure_phase_ptr[i].name = string_hsave((*it).second.name.c_str());
if ((*it).second.add_formula.size() == 0)
pure_phase_ptr[i].add_formula = NULL;
else
pure_phase_ptr[i].add_formula = string_hsave((*it).second.add_formula.c_str());
pure_phase_ptr[i].si = (*it).second.si;
pure_phase_ptr[i].moles = (*it).second.moles;
pure_phase_ptr[i].delta = (*it).second.delta;
@ -143,12 +147,10 @@ cxxPPassemblageComp::dump_raw(std::ostream & s_oss, unsigned int indent) const
// Pure_Phase element and attributes
if (this->name != NULL)
s_oss << indent0 << "-name " << this->
name << std::endl;
if (this->add_formula != NULL)
s_oss << indent1 << "-add_formula " << this->
add_formula << std::endl;
if (this->name.size() != 0)
s_oss << indent0 << "-name " << this->name << std::endl;
if (this->add_formula.size() != 0)
s_oss << indent1 << "-add_formula " << this->add_formula << std::endl;
s_oss << indent1 << "-si " << this->si << std::endl;
s_oss << indent1 << "-moles " << this->moles << std::endl;
s_oss << indent1 << "-delta " << this->delta << std::endl;
@ -218,14 +220,14 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check)
case 0: // name
if (!(parser.get_iss() >> str))
{
this->name = NULL;
this->name.clear();
parser.incr_input_error();
parser.error_msg("Expected string value for name.",
CParser::OT_CONTINUE);
}
else
{
this->name = string_hsave(str.c_str());
this->name = str;
}
name_defined = true;
break;
@ -233,14 +235,14 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check)
case 1: // add_formula
if (!(parser.get_iss() >> str))
{
this->add_formula = NULL;
this->add_formula.clear();
parser.incr_input_error();
parser.error_msg("Expected string value for add_formula.",
CParser::OT_CONTINUE);
}
else
{
this->add_formula = string_hsave(str.c_str());
this->add_formula = str;
}
break;
@ -418,8 +420,8 @@ cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
extern cxxDictionary dictionary;
int i = *ii;
int d = *dd;
this->name = dictionary.int2char(ints[i++]);
this->add_formula = dictionary.int2char(ints[i++]);
this->name = dictionary.int2stdstring(ints[i++]);
this->add_formula = dictionary.int2stdstring(ints[i++]);
this->si = doubles[d++];
this->moles = doubles[d++];
this->delta = doubles[d++];
@ -437,11 +439,11 @@ cxxPPassemblageComp::totalize()
{
this->totals.clear();
// component structures
if (this->add_formula != NULL)
if (this->add_formula.size() != 0)
return;
struct phase *phase_ptr;
int l;
phase_ptr = phase_bsearch(this->name, &l, FALSE);
phase_ptr = phase_bsearch(this->name.c_str(), &l, FALSE);
if (phase_ptr != NULL)
{
cxxNameDouble phase_formula(phase_ptr->next_elt);
@ -461,7 +463,7 @@ cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, double extensive)
double ext1, ext2, f1, f2;
if (extensive == 0.0)
return;
if (addee.name == NULL)
if (addee.name.size() == 0)
return;
// this and addee must have same name
// otherwise generate a new PPassemblagComp with multiply
@ -481,7 +483,7 @@ cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, double extensive)
//char * name;
//char *add_formula;
if (this->name == NULL && addee.name == NULL)
if (this->name.size() == 0 && addee.name.size() == 0)
{
return;
}

View File

@ -10,8 +10,6 @@
#include <list> // std::list
#include <vector> // std::vector
#include "char_star.h"
class cxxPPassemblageComp
{
@ -29,11 +27,28 @@ class cxxPPassemblageComp
void read_raw(CParser & parser, bool check = true);
char *get_name() const
const std::string &get_name() const
{
return this->name;
}
void set_name(char * s)
{
if(s != NULL)
this->name = std::string(s);
else
this->name.clear();
}
const std::string &get_add_formula() const
{
return this->add_formula;
}
void set_add_formula(char * s)
{
if(s != NULL)
this->add_formula = std::string(s);
else
this->add_formula.clear();
}
struct phase *get_phase();
void totalize();
@ -49,9 +64,9 @@ class cxxPPassemblageComp
void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles);
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
#endif
protected:
char *name;
char *add_formula;
protected:
std::string name;
std::string add_formula;
double si;
double moles;
double delta;
@ -61,7 +76,7 @@ class cxxPPassemblageComp
bool precipitate_only;
cxxNameDouble totals;
public:
public:
};

View File

@ -12,7 +12,7 @@
#include <map> // std::map
#include <cassert> // assert
#include <iostream> // std::cout std::cerr
#include "char_star.h"
extern char *string_hsave(const char *str);
//////////////////////////////////////////////////////////////////////
@ -1078,40 +1078,39 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token)
return PARSER_OK;
}
CParser::STATUS_TYPE CParser::addPair(std::map < char *, double,
CHARSTAR_LESS > &totals,
//CParser::STATUS_TYPE CParser::addPair(std::map < char *, double,
// CHARSTAR_LESS > &totals,
// std::istream::pos_type & pos)
//{
// std::string token;
// char *
// ctoken;
// double
// d;
//
// CParser::TOKEN_TYPE j;
//
// m_line_iss.seekg(pos);
//
// j = copy_token(token, pos);
//
// if (j == TT_EMPTY)
// return PARSER_OK;
//
// if (!(m_line_iss >> d))
// {
// return PARSER_ERROR;
// }
// ctoken = string_hsave(token.c_str());
// totals[ctoken] = d;
// return PARSER_OK;
//}
CParser::STATUS_TYPE CParser::addPair(std::map < std::string, double >&totals,
std::istream::pos_type & pos)
{
std::string token;
char *
ctoken;
double
d;
CParser::TOKEN_TYPE j;
m_line_iss.seekg(pos);
j = copy_token(token, pos);
if (j == TT_EMPTY)
return PARSER_OK;
if (!(m_line_iss >> d))
{
return PARSER_ERROR;
}
ctoken = string_hsave(token.c_str());
totals[ctoken] = d;
return PARSER_OK;
}
CParser::STATUS_TYPE CParser::addPair(std::map < char *, double >&totals,
std::istream::pos_type & pos)
{
std::string token;
char *
ctoken;
//char * ctoken;
double
d;
CParser::TOKEN_TYPE j;
@ -1127,8 +1126,9 @@ CParser::STATUS_TYPE CParser::addPair(std::map < char *, double >&totals,
{
return PARSER_ERROR;
}
ctoken = string_hsave(token.c_str());
totals[ctoken] = d;
//ctoken = string_hsave(token.c_str());
//totals[ctoken] = d;
totals[token] = d;
return PARSER_OK;
}

View File

@ -8,7 +8,6 @@ extern int input_error;
#include <sstream> // std::istringstream std::ostringstream
#include <ostream> // std::ostream
#include <istream> // std::istream
#include "char_star.h"
class CParser
{
@ -281,9 +280,9 @@ class CParser
STATUS_TYPE parse_couple(std::string & token);
STATUS_TYPE addPair(std::map < char *, double, CHARSTAR_LESS > &totals,
std::istream::pos_type & pos);
STATUS_TYPE addPair(std::map < char *, double >&totals,
//STATUS_TYPE addPair(std::map < char *, double, CHARSTAR_LESS > &totals,
// std::istream::pos_type & pos);
STATUS_TYPE addPair(std::map < std::string, double >&totals,
std::istream::pos_type & pos);
protected:

View File

@ -24,7 +24,7 @@ cxxReaction::cxxReaction()
//
: cxxNumKeyword()
{
units = string_hsave("Mol");
this->set_units("Mol");
countSteps = 0;
equalIncrements = false;
reactantList.type = cxxNameDouble::ND_NAME_COEF;
@ -45,7 +45,7 @@ elementList(irrev_ptr->elts)
this->set_description(irrev_ptr->description);
this->n_user = irrev_ptr->n_user;
this->n_user_end = irrev_ptr->n_user_end;
this->units = irrev_ptr->units;
this->set_units(irrev_ptr->units);
// steps
if (irrev_ptr->count_steps < 0)
{
@ -117,7 +117,10 @@ cxxReaction::cxxReaction2irrev()
{
irrev_ptr->count_steps = (int) this->steps.size();
}
irrev_ptr->units = this->units;
if (this->units.size() == 0)
irrev_ptr->units = NULL;
else
irrev_ptr->units = string_hsave(this->units.c_str());
return (irrev_ptr);
}
@ -282,7 +285,7 @@ cxxReaction::read_raw(CParser & parser)
j = parser.copy_token(token, next_char);
if (j == CParser::TT_EMPTY)
break;
this->units = string_hsave(token.c_str());
this->set_units(token.c_str());
opt_save = CParser::OPT_DEFAULT;
useLastLine = false;
units_defined = true;

View File

@ -11,8 +11,6 @@
#include <list> // std::list
#include <vector> // std::vector
#include "char_star.h"
class cxxReaction:public cxxNumKeyword
{
@ -29,15 +27,23 @@ class cxxReaction:public cxxNumKeyword
void read_raw(CParser & parser);
protected:
cxxNameDouble reactantList;
void set_units(const char * s)
{
if (s != NULL)
this->units = std::string(s);
else
this->units.clear();
}
protected:
cxxNameDouble reactantList;
cxxNameDouble elementList;
std::vector < double >steps;
std::vector < double >steps;
int countSteps;
bool equalIncrements;
char *units;
std::string units;
public:
public:
//static std::map<int, cxxReaction>& map;
};

View File

@ -10,7 +10,6 @@
#include <list> // std::list
#include <vector> // std::vector
#include "char_star.h"
#include "SSassemblageSS.h"
#include "cxxMix.h"

View File

@ -25,7 +25,6 @@ cxxSSassemblageSS::cxxSSassemblageSS()
// default constructor for cxxSSassemblageSS
//
{
name = NULL;
//total_moles = 0;
a0 = 0;
a1 = 0;
@ -45,7 +44,7 @@ cxxSSassemblageSS::cxxSSassemblageSS(struct s_s *s_s_ptr)
// constructor for cxxSSassemblageSS from struct s_s
//
{
name = s_s_ptr->name;
this->set_name(s_s_ptr->name);
//total_moles = s_s_ptr->total_moles;
a0 = s_s_ptr->a0;
a1 = s_s_ptr->a1;
@ -91,7 +90,8 @@ struct s_s *
for (std::map < std::string, cxxSSassemblageSS >::iterator it = el.begin();
it != el.end(); ++it)
{
s_s_ptr[j].name = (*it).second.name;
s_s_ptr[j].name = string_hsave((*it).second.name.c_str());
assert((*it).second.name.size() > 0);
//s_s_ptr[j].total_moles = it->total_moles;
s_s_ptr[j].total_moles = 0;
s_s_ptr[j].dn = 0;
@ -132,8 +132,9 @@ struct s_s *
for (cxxNameDouble::iterator itc = (*it).second.comps.begin();
itc != (*it).second.comps.end(); ++itc)
{
s_s_comp_ptr[i].name = itc->first;
s_s_comp_ptr[i].phase = phase_bsearch(itc->first, &n, TRUE);
s_s_comp_ptr[i].name = string_hsave(itc->first.c_str());
assert(itc->first.size() > 0);
s_s_comp_ptr[i].phase = phase_bsearch(itc->first.c_str(), &n, TRUE);
s_s_comp_ptr[i].initial_moles = 0;
s_s_comp_ptr[i].moles = itc->second;
s_s_comp_ptr[i].init_moles = 0;
@ -277,14 +278,14 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check)
case 0: // name
if (!(parser.get_iss() >> str))
{
this->name = NULL;
this->name.clear();
parser.incr_input_error();
parser.error_msg("Expected string value for name.",
CParser::OT_CONTINUE);
}
else
{
this->name = string_hsave(str.c_str());
this->name = str;
}
name_defined = true;
opt_save = CParser::OPT_DEFAULT;
@ -521,7 +522,7 @@ cxxSSassemblageSS::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
extern cxxDictionary dictionary;
int i = *ii;
int d = *dd;
this->name = dictionary.int2char(ints[i++]);
this->name = dictionary.int2stdstring(ints[i++]);
this->comps.mpi_unpack(ints, &i, doubles, &d);
this->a0 = doubles[d++];
this->a1 = doubles[d++];
@ -545,7 +546,7 @@ cxxSSassemblageSS::totalize()
{
struct phase *phase_ptr;
int l;
phase_ptr = phase_bsearch(it->first, &l, FALSE);
phase_ptr = phase_bsearch(it->first.c_str(), &l, FALSE);
if (phase_ptr != NULL)
{
cxxNameDouble phase_formula(phase_ptr->next_elt);
@ -564,7 +565,7 @@ cxxSSassemblageSS::add(const cxxSSassemblageSS & addee, double extensive)
{
if (extensive == 0.0)
return;
if (addee.name == NULL)
if (addee.name.size() == 0)
return;
// this and addee must have same name
// otherwise generate a new PPassemblagComp with multiply

View File

@ -10,8 +10,6 @@
#include <list> // std::list
#include <vector> // std::vector
#include "char_star.h"
class cxxSSassemblageSS
{
@ -44,10 +42,17 @@ class cxxSSassemblageSS
void read_raw(CParser & parser, bool check = true);
char *get_name() const
const std::string &get_name() const
{
return this->name;
}
void set_name (const char * s)
{
if (s != NULL)
this->name = std::string(s);
else
this->name.clear();
}
void totalize();
const cxxNameDouble & get_totals() const
@ -63,8 +68,8 @@ class cxxSSassemblageSS
void add(const cxxSSassemblageSS & comp, double extensive);
void multiply(double extensive);
protected:
char *name;
protected:
std::string name;
cxxNameDouble comps;
double a0, a1;
double ag0, ag1;
@ -72,7 +77,7 @@ class cxxSSassemblageSS
double xb1, xb2;
cxxNameDouble totals;
public:
public:
};

View File

@ -670,7 +670,7 @@ cxxSolution::read_raw(CParser & parser, bool check)
}
else
{
if (iso.get_isotope_name() != NULL)
if (iso.get_isotope_name().size() != 0)
{
this->isotopes.push_back(iso);
}
@ -968,7 +968,7 @@ cxxSolution::get_total_element(char *string) const
char token[MAX_LENGTH];
if (it->first[0] == string[0])
{
strcpy(token, it->first);
strcpy(token, it->first.c_str());
replace("(", "\0", token);
if (strcmp(token, string) == 0)
{

View File

@ -14,8 +14,6 @@
#include <vector> // std::vector
#include <iostream>
#include "char_star.h"
class cxxSolution:public cxxNumKeyword
{

View File

@ -19,8 +19,8 @@ isotope_number(0.0)
cxxSolutionIsotope::cxxSolutionIsotope(struct isotope *isotope_ptr)
{
isotope_number = isotope_ptr->isotope_number;
elt_name = isotope_ptr->elt_name;
isotope_name = isotope_ptr->isotope_name;
this->set_elt_name(isotope_ptr->elt_name);
this->set_isotope_name(isotope_ptr->isotope_name);
total = isotope_ptr->total;
ratio = isotope_ptr->ratio;
ratio_uncertainty = isotope_ptr->ratio_uncertainty;
@ -53,7 +53,7 @@ cxxSolutionIsotope::list2isotope(std::list < cxxSolutionIsotope > &isolist)
it != isolist.end(); ++it)
{
iso[i].isotope_number = it->isotope_number;
iso[i].elt_name = it->elt_name;
iso[i].elt_name = string_hsave(it->elt_name.c_str());
iso[i].total = it->total;
iso[i].ratio = it->ratio;
iso[i].ratio_uncertainty = it->ratio_uncertainty;
@ -148,10 +148,10 @@ CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser)
if (j == CParser::TT_EMPTY)
{
this->isotope_name = NULL;
this->isotope_name.clear();
return (CParser::PARSER_OK);
}
this->isotope_name = string_hsave(token.c_str());
this->set_isotope_name(token.c_str());
// isotope_number
if (!(parser.get_iss() >> isotope_number))
@ -164,7 +164,7 @@ CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser)
{
return CParser::PARSER_ERROR;
}
this->elt_name = string_hsave(token.c_str());
this->set_elt_name(token.c_str());
// total
if (!(parser.get_iss() >> this->total))
@ -202,7 +202,7 @@ CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser)
bool
cxxSolutionIsotope::operator<(const cxxSolutionIsotope & isotope) const
{
int i = Utilities::strcmp_nocase(this->elt_name, isotope.elt_name);
int i = Utilities::strcmp_nocase(this->elt_name.c_str(), isotope.elt_name.c_str());
if (i != 0)
return (i < 0);
return (this->isotope_number < isotope.isotope_number);
@ -211,13 +211,14 @@ cxxSolutionIsotope::operator<(const cxxSolutionIsotope & isotope) const
struct master *
cxxSolutionIsotope::master(void)
{
return (master_bsearch(this->elt_name));
return (master_bsearch(this->elt_name.c_str()));
}
struct master *
cxxSolutionIsotope::primary(void)
{
return (master_bsearch_primary(this->elt_name));
char * str = string_hsave(this->elt_name.c_str());
return (master_bsearch_primary(str));
}
void

View File

@ -35,21 +35,27 @@ class cxxSolutionIsotope
{
this->isotope_number = d;
}
char *get_elt_name() const
const std::string &get_elt_name() const
{
return this->elt_name;
}
void set_elt_name(char *cstring)
void set_elt_name(const char *cstring)
{
this->elt_name = cstring;
if (cstring != NULL)
this->elt_name = std::string(cstring);
else
this->elt_name.clear();
}
char *get_isotope_name() const
const std::string &get_isotope_name() const
{
return this->isotope_name;
}
void set_isotope_name(char *cstring)
void set_isotope_name(const char *cstring)
{
this->isotope_name = cstring;
if (cstring != NULL)
this->isotope_name = std::string(cstring);
else
this->isotope_name.clear();
}
double get_total() const
{
@ -87,13 +93,11 @@ class cxxSolutionIsotope
protected:
friend class cxxSolutionIsotopeList;
double isotope_number;
char *elt_name;
char *isotope_name;
std::string elt_name;
std::string isotope_name;
double total;
double ratio;
double ratio_uncertainty;
//struct master *master;
//struct master *primary;
bool ratio_uncertainty_defined;
};
#endif // SOLUTIONISOTOPE_H_INCLUDED

View File

@ -98,7 +98,7 @@ cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope()
it != this->end(); ++it)
{
iso[i].isotope_number = it->isotope_number;
iso[i].elt_name = it->elt_name;
iso[i].elt_name = string_hsave(it->elt_name.c_str());
iso[i].total = it->total;
iso[i].ratio = it->ratio;
iso[i].ratio_uncertainty = it->ratio_uncertainty;

View File

@ -8,7 +8,6 @@
#include <string> // std::string
#include <list> // std::list
#include "char_star.h"
#include "Parser.h"
class cxxSolutionIsotopeList:public
@ -16,23 +15,18 @@ class cxxSolutionIsotopeList:public
cxxSolutionIsotope >
{
public:
public:
cxxSolutionIsotopeList();
cxxSolutionIsotopeList(struct solution *solution_ptr);
~
cxxSolutionIsotopeList();
~cxxSolutionIsotopeList();
struct isotope *
cxxSolutionIsotopeList2isotope();
struct isotope * cxxSolutionIsotopeList2isotope();
void add(cxxSolutionIsotopeList oldlist, double intensive, double extensive);
void multiply(double extensive);
void
add(cxxSolutionIsotopeList oldlist, double intensive, double extensive);
void
multiply(double extensive);
protected:
protected:
public:

View File

@ -118,7 +118,7 @@ cxxSurface::get_related_phases()
for (std::map < std::string, cxxSurfaceComp >::const_iterator it =
this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it)
{
if ((*it).second.get_phase_name() == NULL)
if ((*it).second.get_phase_name().size() == 0)
continue;
return (true);
}
@ -131,7 +131,7 @@ cxxSurface::get_related_rate()
for (std::map < std::string, cxxSurfaceComp >::const_iterator it =
this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it)
{
if ((*it).second.get_rate_name() == NULL)
if ((*it).second.get_rate_name().size() == 0)
continue;
return (true);
}
@ -195,9 +195,9 @@ cxxSurface::cxxSurface2surface()
int i, j;
for (i = 0; i < surface_ptr->count_comps; i++)
{
char *charge_name =
char *charge_name = string_hsave(
cxxSurfaceComp::get_charge_name(surface_ptr->comps[i].
formula);
formula).c_str());
for (j = 0; j < surface_ptr->count_charge; j++)
{
if (charge_name == surface_ptr->charge[j].name)

View File

@ -10,7 +10,6 @@
#include <list> // std::list
#include <vector> // std::vector
#include "char_star.h"
#include "SurfaceComp.h"
#include "SurfaceCharge.h"
#include "cxxMix.h"
@ -54,12 +53,12 @@ class cxxSurface:public cxxNumKeyword
void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles);
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
#endif
private:
private:
void add(const cxxSurface & addee, double extensive);
protected:
std::map < std::string, cxxSurfaceComp > surfaceComps;
std::map < std::string, cxxSurfaceCharge > surfaceCharges;
protected:
std::map < std::string, cxxSurfaceComp > surfaceComps;
std::map < std::string, cxxSurfaceCharge > surfaceCharges;
enum SURFACE_TYPE type;
enum DIFFUSE_LAYER_TYPE dl_type;
enum SITES_UNITS sites_units;
@ -71,7 +70,7 @@ class cxxSurface:public cxxNumKeyword
bool transport;
cxxNameDouble totals;
public:
public:
//static std::map<int, cxxSurface>& map;
};

View File

@ -25,7 +25,6 @@ cxxSurfaceCharge::cxxSurfaceCharge()
// default constructor for cxxSurfaceCharge
//
{
name = NULL;
specific_area = 0.0;
grams = 0.0;
charge_balance = 0.0;
@ -45,7 +44,7 @@ cxxSurfaceCharge::cxxSurfaceCharge(struct surface_charge *surf_charge_ptr)
:
diffuse_layer_totals(surf_charge_ptr->diffuse_layer_totals)
{
name = surf_charge_ptr->name;
this->set_name(surf_charge_ptr->name);
specific_area = surf_charge_ptr->specific_area;
grams = surf_charge_ptr->grams;
charge_balance = surf_charge_ptr->charge_balance;
@ -96,7 +95,8 @@ struct surface_charge *
for (std::map < std::string, cxxSurfaceCharge >::iterator it = el.begin();
it != el.end(); ++it)
{
surf_charge_ptr[i].name = (*it).second.name;
surf_charge_ptr[i].name = string_hsave((*it).second.name.c_str());
assert((*it).second.name.size() > 0);
surf_charge_ptr[i].specific_area = (*it).second.specific_area;
surf_charge_ptr[i].grams = (*it).second.grams;
surf_charge_ptr[i].charge_balance = (*it).second.charge_balance;
@ -262,14 +262,14 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check)
case 0: // name
if (!(parser.get_iss() >> str))
{
this->name = NULL;
this->name.clear();
parser.incr_input_error();
parser.error_msg("Expected string value for name.",
CParser::OT_CONTINUE);
}
else
{
this->name = string_hsave(str.c_str());
this->name = str;
}
name_defined = true;
break;
@ -486,7 +486,7 @@ cxxSurfaceCharge::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
extern cxxDictionary dictionary;
int i = *ii;
int d = *dd;
this->name = dictionary.int2char(ints[i++]);
this->name = dictionary.int2stdstring(ints[i++]);
this->specific_area = doubles[d++];
this->grams = doubles[d++];
this->charge_balance = doubles[d++];
@ -515,7 +515,7 @@ cxxSurfaceCharge::add(const cxxSurfaceCharge & addee, double extensive)
//double capacitance[2];
//char * name;
if (this->name == NULL && addee.name == NULL)
if (this->name.size() == 0 && addee.name.size() == 0)
{
return;
}

View File

@ -10,8 +10,6 @@
#include <list> // std::list
#include <vector> // std::vector
#include "char_star.h"
class cxxSurfaceCharge
{
@ -32,11 +30,19 @@ class cxxSurfaceCharge
void read_raw(CParser & parser, bool check = true);
char *get_name() const
const std::string &get_name() const
{
return this->name;
}
void set_name(const char * s)
{
if (s != NULL)
this->name = std::string(s);
else
this->name.clear();
}
void add(const cxxSurfaceCharge & comp, double extensive);
void multiply(double extensive);
@ -45,8 +51,8 @@ class cxxSurfaceCharge
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
#endif
protected:
char *name;
protected:
std::string name;
double specific_area;
double grams;
double charge_balance;
@ -57,7 +63,7 @@ class cxxSurfaceCharge
//char * psi_master_name;
cxxNameDouble diffuse_layer_totals;
public:
public:
};

View File

@ -25,7 +25,6 @@ cxxSurfaceComp::cxxSurfaceComp()
// default constructor for cxxSurfaceComp
//
{
formula = NULL;
formula_totals.type = cxxNameDouble::ND_ELT_MOLES;
formula_z = 0.0;
moles = 0.0;
@ -33,9 +32,7 @@ cxxSurfaceComp::cxxSurfaceComp()
la = 0.0;
//charge_number = -99;
charge_balance = 0;
phase_name = NULL;
phase_proportion = 0.0;
rate_name = NULL;
Dw = 0.0;
}
@ -47,15 +44,15 @@ cxxSurfaceComp::cxxSurfaceComp(struct surface_comp *surf_comp_ptr)
formula_totals(surf_comp_ptr->formula_totals),
totals(surf_comp_ptr->totals)
{
formula = surf_comp_ptr->formula;
this->set_formula(surf_comp_ptr->formula);
formula_z = surf_comp_ptr->formula_z;
moles = surf_comp_ptr->moles;
la = surf_comp_ptr->la;
//charge_number = surf_comp_ptr->charge;
charge_balance = surf_comp_ptr->cb;
phase_name = surf_comp_ptr->phase_name;
this->set_phase_name(surf_comp_ptr->phase_name);
phase_proportion = surf_comp_ptr->phase_proportion;
rate_name = surf_comp_ptr->rate_name;
this->set_rate_name(surf_comp_ptr->rate_name);
Dw = surf_comp_ptr->Dw;
}
@ -72,7 +69,8 @@ cxxSurfaceComp::get_master()
it != this->totals.end(); it++)
{
/* Find master species */
char *eltName = it->first;
char *eltName = string_hsave(it->first.c_str());
assert(it->first.size() > 0);
struct element *elt_ptr = element_store(eltName);
if (elt_ptr->master == NULL)
{
@ -116,7 +114,8 @@ struct surface_comp *
for (std::map < std::string, cxxSurfaceComp >::iterator it = el.begin();
it != el.end(); ++it)
{
surf_comp_ptr[i].formula = (*it).second.formula;
surf_comp_ptr[i].formula = string_hsave((*it).second.formula.c_str());
assert((*it).second.formula.size() > 0);
surf_comp_ptr[i].formula_totals = (*it).second.formula_totals.elt_list();
surf_comp_ptr[i].formula_z = (*it).second.formula_z;
surf_comp_ptr[i].moles = (*it).second.moles;
@ -125,9 +124,15 @@ struct surface_comp *
surf_comp_ptr[i].la = (*it).second.la;
//surf_comp_ptr[i].charge = it->charge_number;
surf_comp_ptr[i].cb = (*it).second.charge_balance;
surf_comp_ptr[i].phase_name = (*it).second.phase_name;
if ((*it).second.phase_name.size() == 0)
surf_comp_ptr[i].phase_name = NULL;
else
surf_comp_ptr[i].phase_name = string_hsave((*it).second.phase_name.c_str());
surf_comp_ptr[i].phase_proportion = (*it).second.phase_proportion;
surf_comp_ptr[i].rate_name = (*it).second.rate_name;
if ((*it).second.rate_name.size() == 0)
surf_comp_ptr[i].rate_name = NULL;
else
surf_comp_ptr[i].rate_name = string_hsave((*it).second.rate_name.c_str());
surf_comp_ptr[i].Dw = (*it).second.Dw;
surf_comp_ptr[i].master = (*it).second.get_master();
i++;
@ -159,12 +164,12 @@ cxxSurfaceComp::dump_xml(std::ostream & s_oss, unsigned int indent) const
//s_oss << indent0 << "charge_number=\"" << this->charge_number << "\"" << std::endl;
s_oss << indent0 << "charge_balance=\"" << this->
charge_balance << "\"" << std::endl;
if (this->phase_name != NULL)
if (this->phase_name.size() != 0)
{
s_oss << indent0 << "phase_name=\"" << this->
phase_name << "\"" << std::endl;
}
if (this->rate_name != NULL)
if (this->rate_name.size() != 0)
{
s_oss << indent0 << "rate_name=\"" << this->
rate_name << "\"" << std::endl;
@ -210,12 +215,12 @@ cxxSurfaceComp::dump_raw(std::ostream & s_oss, unsigned int indent) const
//s_oss << indent1 << "-charge_number " << this->charge_number << std::endl;
s_oss << indent1 << "-charge_balance " << this->
charge_balance << std::endl;
if (this->phase_name != NULL)
if (this->phase_name.size() != 0)
{
s_oss << indent1 << "-phase_name " << this->
phase_name << std::endl;
}
if (this->rate_name != NULL)
if (this->rate_name.size() != 0)
{
s_oss << indent1 << "-rate_name " << this->
rate_name << std::endl;
@ -298,14 +303,14 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check)
case 0: // formula
if (!(parser.get_iss() >> str))
{
this->formula = NULL;
this->formula.clear();
parser.incr_input_error();
parser.error_msg("Expected string value for formula.",
CParser::OT_CONTINUE);
}
else
{
this->formula = string_hsave(str.c_str());
this->formula = str;
}
formula_defined = true;
break;
@ -357,28 +362,28 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check)
case 5: // phase_name
if (!(parser.get_iss() >> str))
{
this->phase_name = NULL;
this->phase_name.clear();
parser.incr_input_error();
parser.error_msg("Expected string value for phase_name.",
CParser::OT_CONTINUE);
}
else
{
this->phase_name = string_hsave(str.c_str());
this->phase_name = str;
}
break;
case 6: // rate_name
if (!(parser.get_iss() >> str))
{
this->rate_name = NULL;
this->rate_name.clear();
parser.incr_input_error();
parser.error_msg("Expected string value for rate_name.",
CParser::OT_CONTINUE);
}
else
{
this->rate_name = string_hsave(str.c_str());
this->rate_name = str;
}
break;
@ -521,7 +526,7 @@ cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
extern cxxDictionary dictionary;
int i = *ii;
int d = *dd;
this->formula = dictionary.int2char(ints[i++]);
this->formula = dictionary.int2stdstring(ints[i++]);
this->formula_z = doubles[d++];
this->formula_totals.mpi_unpack(ints, &i, doubles, &d);
this->moles = doubles[d++];
@ -529,9 +534,9 @@ cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
this->la = doubles[d++];
//this->charge_number = ints[i++];
this->charge_balance = doubles[d++];
this->phase_name = dictionary.int2char(ints[i++]);
this->phase_name = dictionary.int2stdstring(ints[i++]);
this->phase_proportion = doubles[d++];
this->rate_name = dictionary.int2char(ints[i++]);
this->rate_name = dictionary.int2stdstring(ints[i++]);
this->Dw = doubles[d++];
*ii = i;
*dd = d;
@ -542,18 +547,18 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive)
{
if (extensive == 0.0)
return;
if (addee.formula == NULL)
if (addee.formula.size() == 0)
return;
//char * formula;
//cxxNameDouble formula_totals;
if (this->formula == NULL && addee.formula == NULL)
if (this->formula.size() == 0 && addee.formula.size() == 0)
{
return;
}
assert(this->formula == addee.formula);
assert(this->formula_z == addee.formula_z);
if (this->formula == NULL && addee.formula != NULL)
if (this->formula.size() == 0 && addee.formula.size() != 0)
{
this->formula = addee.formula;
this->formula_totals = addee.formula_totals;
@ -597,7 +602,7 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive)
input_error++;
return;
}
else if (this->phase_name != NULL)
else if (this->phase_name.size() != 0)
{
this->phase_proportion =
this->phase_proportion * f1 + addee.phase_proportion * f2;
@ -614,14 +619,14 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive)
input_error++;
return;
}
else if (this->rate_name != NULL)
else if (this->rate_name.size() != 0)
{
//double phase_proportion;
this->phase_proportion =
this->phase_proportion * f1 + addee.phase_proportion * f2;
}
if ((this->rate_name != NULL && addee.phase_name != NULL) ||
(this->phase_name != NULL && addee.rate_name != NULL))
if ((this->rate_name.size() != 0 && addee.phase_name.size() != 0) ||
(this->phase_name.size() != 0 && addee.rate_name.size() != 0))
{
std::ostringstream oss;
oss <<

View File

@ -11,8 +11,6 @@
#include <list> // std::list
#include <vector> // std::vector
#include "char_star.h"
class cxxSurfaceComp
{
@ -24,18 +22,39 @@ class cxxSurfaceComp
struct master *get_master();
char *get_phase_name() const
const std::string &get_phase_name() const
{
return this->phase_name;
}
char *get_rate_name() const
void set_phase_name(char * f)
{
if (f != NULL)
this->phase_name = std::string(f);
else
this->phase_name.clear();
}
const std::string &get_rate_name() const
{
return this->rate_name;
}
char *get_formula() const
void set_rate_name(char * f)
{
if (f != NULL)
this->rate_name = std::string(f);
else
this->rate_name.clear();
}
const std::string &get_formula() const
{
return this->formula;
}
void set_formula(char * f)
{
if (f != NULL)
this->formula = std::string(f);
else
this->formula.clear();
}
double get_charge_balance() const
{
return this->charge_balance;
@ -61,12 +80,26 @@ class cxxSurfaceComp
void add(const cxxSurfaceComp & comp, double extensive);
void multiply(double extensive);
char *charge_name()
std::string charge_name()
{
return (get_charge_name(this->formula));
char * str = string_hsave(this->formula.c_str());
return (get_charge_name(str));
};
static char *get_charge_name(char *token)
//static std::string &get_charge_name(char *token)
//{
// char name[100];
// int l;
// char *ptr1 = token;
// get_elt(&ptr1, name, &l);
// ptr1 = strchr(name, '_');
// if (ptr1 != NULL)
// {
// ptr1[0] = '\0';
// }
// return (string_hsave(name));
//};
static std::string get_charge_name(char *token)
{
char name[100];
int l;
@ -77,27 +110,26 @@ class cxxSurfaceComp
{
ptr1[0] = '\0';
}
return (string_hsave(name));
return (std::string(name));
};
#ifdef USE_MPI
void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles);
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
#endif
protected:
char *formula;
cxxNameDouble formula_totals;
double formula_z;
double moles;
cxxNameDouble totals;
double la;
//int charge_number;
double charge_balance;
char *phase_name;
double phase_proportion;
char *rate_name;
double Dw;
std::string formula;
cxxNameDouble formula_totals;
double formula_z;
double moles;
cxxNameDouble totals;
double la;
//int charge_number;
double charge_balance;
std::string phase_name;
double phase_proportion;
std::string rate_name;
double Dw;
public:
};

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,7 @@
#include "cxxMix.h"
#include "Reaction.h"
#include "Temperature.h"
class cxxSystem
class cxxSystem
{
public:cxxSystem(void);
public: ~cxxSystem(void);
@ -46,7 +46,7 @@ class cxxSystem
{
this->temperature = entity;
} void totalize();
#ifdef ORCHESTRA
void ORCH_components();
void ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat,
@ -56,9 +56,10 @@ class cxxSystem
void ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat);
void ORCH_write_output_vars(std::ostream & outstream);
void ORCH_write_input(std::ostream & input_dat);
#endif /* */
private:cxxSolution * solution;
private:
cxxSolution * solution;
cxxExchange * exchange;
cxxPPassemblage * ppassemblage;
cxxGasPhase * gasphase;

View File

@ -10,8 +10,6 @@
#include <list> // std::list
#include <vector> // std::vector
#include "char_star.h"
class cxxTemperature:public cxxNumKeyword
{
@ -28,12 +26,12 @@ class cxxTemperature:public cxxNumKeyword
void read_raw(CParser & parser);
protected:
std::vector < double >temps;
protected:
std::vector < double >temps;
int countTemps;
bool equalIncrements;
public:
public:
//static std::map<int, cxxTemperature>& map;
};

View File

@ -6,7 +6,6 @@
#include <ostream> // std::ostream
#include <istream> // std::istream
#include <map> // std::map
#include "char_star.h"
namespace Utilities
{