From bc1198144870ac7771c7d59f2f1785be93f65a1e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 27 Feb 2006 21:24:28 +0000 Subject: [PATCH] Adding StorageBin git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@798 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBin.cxx | 189 +++++++++++++++++++++++++++++++++++++++++++++++++ StorageBin.h | 64 +++++++++++++++++ 2 files changed, 253 insertions(+) create mode 100644 StorageBin.cxx create mode 100644 StorageBin.h diff --git a/StorageBin.cxx b/StorageBin.cxx new file mode 100644 index 00000000..ec2a094f --- /dev/null +++ b/StorageBin.cxx @@ -0,0 +1,189 @@ +// StorageBin.cxx: implementation of the cxxStorageBin class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "StorageBin.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxStorageBin::cxxStorageBin() + // + // default constructor for cxxStorageBin + // +{ +} + +cxxStorageBin::~cxxStorageBin() +{ +} + + + +#ifdef SKIP +void cxxStorageBin::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // StorageBin element and attributes + s_oss << indent0; + s_oss << "pitzer_mix_gammas << "\"" << std::endl; + + // components + s_oss << indent1; + s_oss << "::const_iterator it = mixComps.begin(); it != mixComps.end(); ++it) { + it->dump_xml(s_oss, indent + 2); + } + + return; +} +#endif + +void cxxStorageBin::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; + s_oss.precision(DBL_DIG - 1); + + // Solutions + + // for (std::map::const_iterator it = this->Solutions.begin(); it != this->Solutions.end(); ++it) { + //it->second.dump_raw(s_oss, indent); + //} + // Exchange + for (std::map::const_iterator it = this->Exchangers.begin(); it != this->Exchangers.end(); ++it) { + it->second.dump_raw(s_oss, indent); + + } + // Gas Phases + for (std::map::const_iterator it = this->GasPhases.begin(); it != this->GasPhases.end(); ++it) { + it->second.dump_raw(s_oss, indent); + } + // Kinetics + for (std::map::const_iterator it = this->Kinetics.begin(); it != this->Kinetics.end(); ++it) { + it->second.dump_raw(s_oss, indent); + } + // PPassemblage + for (std::map::const_iterator it = this->PPassemblages.begin(); it != this->PPassemblages.end(); ++it) { + it->second.dump_raw(s_oss, indent); + } + // SSassemblage + for (std::map::const_iterator it = this->SSassemblages.begin(); it != this->SSassemblages.end(); ++it) { + it->second.dump_raw(s_oss, indent); + } + // Surface + for (std::map::const_iterator it = this->Surfaces.begin(); it != this->Surfaces.end(); ++it) { + it->second.dump_raw(s_oss, indent); + } +} + +void cxxStorageBin::read_raw(CParser& parser) +{ + CParser::LINE_TYPE i; + while ((i = parser.check_line("Subroutine Read", false, true, true, true)) != CParser::LT_KEYWORD) + { + if (i == CParser::LT_EOF) return; // CParser::LT_EOF; + } + + for (;;) { + switch(parser.next_keyword()) + { + case CParser::KT_END: + case CParser::KT_EOF: + case CParser::KT_NONE: + goto END_OF_SIMULATION_INPUT; + break; + /* + KT_SOLUTION_RAW = 5, + KT_EXCHANGE_RAW = 6, + KT_GASPHASE_RAW = 7, + KT_KINETICS_RAW = 8, + KT_PPASSEMBLAGE_RAW = 9, + KT_SSASSEMBLAGE_RAW = 10, + KT_SURFACE_RAW = 11 + */ + case CParser::KT_SOLUTION_RAW: + { + cxxSolution entity; + entity.read_raw(parser); + Solutions[entity.get_n_user()] = entity; + } + break; + + case CParser::KT_EXCHANGE_RAW: + { + cxxExchange entity; + entity.read_raw(parser); + Exchangers[entity.get_n_user()] = entity; + } + break; + + case CParser::KT_GASPHASE_RAW: + { + cxxGasPhase entity; + entity.read_raw(parser); + GasPhases[entity.get_n_user()] = entity; + } + break; + + case CParser::KT_KINETICS_RAW: + { + cxxKinetics entity; + entity.read_raw(parser); + Kinetics[entity.get_n_user()] = entity; + } + break; + + case CParser::KT_PPASSEMBLAGE_RAW: + { + cxxPPassemblage entity; + entity.read_raw(parser); + PPassemblages[entity.get_n_user()] = entity; + } + break; + + case CParser::KT_SSASSEMBLAGE_RAW: + { + cxxSSassemblage entity; + entity.read_raw(parser); + SSassemblages[entity.get_n_user()] = entity; + } + break; + + case CParser::KT_SURFACE_RAW: + { + cxxSurface entity; + entity.read_raw(parser); + Surfaces[entity.get_n_user()] = entity; + } + break; + + default: + break; + } + } + +END_OF_SIMULATION_INPUT: + return; //CParser::LT_OK; +} + diff --git a/StorageBin.h b/StorageBin.h new file mode 100644 index 00000000..0eb7a539 --- /dev/null +++ b/StorageBin.h @@ -0,0 +1,64 @@ +#if !defined(STORAGEBIN_H_INCLUDED) +#define STORAGEBIN_H_INCLUDED + +#include "Parser.h" +#include "Solution.h" +#include "Exchange.h" +#include "GasPhase.h" +#include "KineticsCxx.h" +#include "PPassemblage.h" +#include "SSassemblage.h" +#include "Surface.h" + +#include "Mix.h" +#include "Reaction.h" +#include "Temperature.h" + +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +template +bool exists (std::map b, int i){ + return (b.find(i) != b.end());} + +class cxxStorageBin +{ + +public: + cxxStorageBin(); + ~cxxStorageBin(); + + //void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void read_raw(CParser& parser); + +protected: + // Tidied classes + std::map Solutions; + std::map Exchangers; + std::map GasPhases; + std::map Kinetics; + std::map PPassemblages; + std::map SSassemblages; + std::map Surfaces; + + //bool b = exists (Solutions, 5); + // Initial classes + //std::map ISolutions; + + // Reaction classes + std::map Mixes; + std::map Reactions; + std::map Temperatures; + +public: + //static std::map& map; + +}; + +#endif // !defined(STORAGEBIN_H_INCLUDED)