removed dependencies Phreeqc.h and Parser.h from Utils.h

git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6517 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
Scott R Charlton 2012-04-20 03:59:14 +00:00
parent aa8047e134
commit 74c97b0e76
4 changed files with 124 additions and 114 deletions

View File

@ -5,9 +5,13 @@
#include <map> // std::map
#include <vector>
#include <set>
#include "PHRQ_base.h"
#include "phrqtype.h" // LDBLE
#include "Parser.h" // CParser
#include "PHRQ_base.h" // PHRQ_base
// forward declarations
class cxxSolution;
class cxxISolution; // reqd for read and dump_xml
class PHRQ_io;
class cxxISolutionComp: public PHRQ_base
{

117
Phreeqc.h
View File

@ -1875,6 +1875,123 @@ public:
static const int count_iso_defaults;
};
namespace Utilities
{
LDBLE get_nan(void);
// operations on maps of entities (Solution, Exchange, ...)
template < typename T >
void Rxn_dump_raw(const T & b, std::ostream & s_oss, unsigned int indent)
{
typename T::const_iterator it;
for (it = b.begin(); it != b.end(); ++it)
{
it->second.dump_raw(s_oss, indent);
}
return;
}
template < typename T >
T * Rxn_find(std::map < int, T > &b, int i)
{
if (b.find(i) != b.end())
{
return (&(b.find(i)->second));
}
else
{
return (NULL);
}
}
template < typename T >
T * Rxn_copy(std::map < int, T > &b, int i, int j)
{
typename std::map < int, T >::iterator it;
it = b.find(i);
if (it != b.end())
{
b[j] = it->second;
it = b.find(j);
it->second.Set_n_user(j);
it->second.Set_n_user_end(j);
return &(it->second);
}
else
{
return (NULL);
}
}
template < typename T >
void Rxn_copies(std::map < int, T > &b, int n_user, int n_user_end)
{
if (n_user_end <= n_user) return;
typename std::map < int, T >::iterator it;
it = b.find(n_user);
if (it != b.end())
{
for (int j = n_user + 1; j <= n_user_end; j++)
{
b[j] = it->second;
it = b.find(j);
it->second.Set_n_user(j);
it->second.Set_n_user_end(j);
}
}
}
template < typename T >
int Rxn_read_raw(std::map < int, T > &m, Phreeqc * phreeqc_cookie)
{
typename std::map < int, T >::iterator it;
assert(!phreeqc_cookie->reading_database());
T entity(phreeqc_cookie->Get_phrq_io());
CParser parser(phreeqc_cookie->Get_phrq_io());
entity.read_raw(parser);
// Store
if (entity.Get_base_error_count() == 0)
{
m[entity.Get_n_user()] = entity;
}
// Make copies if necessary
Utilities::Rxn_copies(m, entity.Get_n_user(), entity.Get_n_user_end());
return phreeqc_cookie->cleanup_after_parser(parser);
}
template < typename T >
int Rxn_read_modify(std::map < int, T > &m, Phreeqc * phreeqc_cookie)
{
typename std::map < int, T >::iterator it;
CParser parser(phreeqc_cookie->Get_phrq_io());
std::string key_name;
std::string::iterator b = parser.line().begin();
std::string::iterator e = parser.line().end();
CParser::copy_token(key_name, b, e);
cxxNumKeyword nk;
nk.read_number_description(parser);
T * entity_ptr = Utilities::Rxn_find(m, nk.Get_n_user());
if (!entity_ptr)
{
std::ostringstream errstr;
errstr << "Could not find " << key_name << " " << nk.Get_n_user() << " to modify.\n";
phreeqc_cookie->error_msg(errstr.str().c_str(), PHRQ_io::OT_STOP);
}
entity_ptr->read_raw(parser, false);
return phreeqc_cookie->cleanup_after_parser(parser);
}
} // namespace Utilities
#if defined(PHREEQCI_GUI)
void PhreeqcIWait(Phreeqc *phreeqc);
#endif

1
SS.cxx
View File

@ -7,6 +7,7 @@
#include <cassert> // assert
#include <algorithm> // std::sort
#include "Phreeqc.h"
#include "Utils.h" // define first
#include "SS.h"
//#include "Dictionary.h"

114
Utils.h
View File

@ -1,12 +1,11 @@
#if !defined(UTILITIES_H_INCLUDED)
#define UTILITIES_H_INCLUDED
#include "Phreeqc.h"
#include <string>
#include <sstream> // std::istringstream std::ostringstream
#include <ostream> // std::ostream
#include <istream> // std::istream
#include <map> // std::map
#include "Parser.h"
namespace Utilities
{
@ -24,116 +23,5 @@ namespace Utilities
void squeeze_white(std::string & s_l);
LDBLE get_nan(void);
// operations on maps of entities (Solution, Exchange, ...)
template < typename T >
void Rxn_dump_raw(const T & b, std::ostream & s_oss, unsigned int indent)
{
typename T::const_iterator it;
for (it = b.begin(); it != b.end(); ++it)
{
it->second.dump_raw(s_oss, indent);
}
return;
}
template < typename T >
T * Rxn_find(std::map < int, T > &b, int i)
{
if (b.find(i) != b.end())
{
return (&(b.find(i)->second));
}
else
{
return (NULL);
}
}
template < typename T >
T * Rxn_copy(std::map < int, T > &b, int i, int j)
{
typename std::map < int, T >::iterator it;
it = b.find(i);
if (it != b.end())
{
b[j] = it->second;
it = b.find(j);
it->second.Set_n_user(j);
it->second.Set_n_user_end(j);
return &(it->second);
}
else
{
return (NULL);
}
}
template < typename T >
void Rxn_copies(std::map < int, T > &b, int n_user, int n_user_end)
{
if (n_user_end <= n_user) return;
typename std::map < int, T >::iterator it;
it = b.find(n_user);
if (it != b.end())
{
for (int j = n_user + 1; j <= n_user_end; j++)
{
b[j] = it->second;
it = b.find(j);
it->second.Set_n_user(j);
it->second.Set_n_user_end(j);
}
}
}
template < typename T >
int Rxn_read_raw(std::map < int, T > &m, Phreeqc * phreeqc_cookie)
{
typename std::map < int, T >::iterator it;
assert(!phreeqc_cookie->reading_database());
T entity(phreeqc_cookie->Get_phrq_io());
CParser parser(phreeqc_cookie->Get_phrq_io());
entity.read_raw(parser);
// Store
if (entity.Get_base_error_count() == 0)
{
m[entity.Get_n_user()] = entity;
}
// Make copies if necessary
Utilities::Rxn_copies(m, entity.Get_n_user(), entity.Get_n_user_end());
return phreeqc_cookie->cleanup_after_parser(parser);
}
template < typename T >
int Rxn_read_modify(std::map < int, T > &m, Phreeqc * phreeqc_cookie)
{
typename std::map < int, T >::iterator it;
CParser parser(phreeqc_cookie->Get_phrq_io());
std::string key_name;
std::string::iterator b = parser.line().begin();
std::string::iterator e = parser.line().end();
CParser::copy_token(key_name, b, e);
cxxNumKeyword nk;
nk.read_number_description(parser);
T * entity_ptr = Utilities::Rxn_find(m, nk.Get_n_user());
if (!entity_ptr)
{
std::ostringstream errstr;
errstr << "Could not find " << key_name << " " << nk.Get_n_user() << " to modify.\n";
phreeqc_cookie->error_msg(errstr.str().c_str(), PHRQ_io::OT_STOP);
}
entity_ptr->read_raw(parser, false);
return phreeqc_cookie->cleanup_after_parser(parser);
}
}
#endif // UTILITIES_H_INCLUDED