00001 // Chemical.cpp: implementation of the Chemical class. 00002 // 00004 00005 #ifdef _WINDOWS 00006 #include "stdafx.h" 00007 #endif 00008 00009 #include "Chemical.h" 00010 #include <vector> 00011 00013 // Construction/Destruction 00015 00016 Chemical::Chemical(int chemicalNumber, double amount, std::string name) 00017 { 00018 this->chemicalNumber = chemicalNumber; 00019 SetAmount(amount); 00020 initialAmount = amount; 00021 if(initialAmount > 0.0 ) 00022 { 00023 errorInInitialAmount = initialAmount; 00024 } 00025 else 00026 { 00027 errorInInitialAmount = 1.0; 00028 } 00029 this->name = name; 00030 this->SetTeXName(); 00031 } 00032 00033 Chemical::Chemical(int chemicalNumber, double amount, double errorInInitialAmount, std::string name) 00034 { 00035 this->chemicalNumber = chemicalNumber; 00036 SetAmount(amount); 00037 initialAmount = amount; 00038 this->errorInInitialAmount = errorInInitialAmount; 00039 this->name = name; 00040 this->SetTeXName(); 00041 } 00042 00043 Chemical::Chemical() 00044 { 00045 00046 } 00047 00048 Chemical::~Chemical() 00049 { 00050 00051 } 00052 00053 double Chemical::GetAmount() const 00054 { 00055 return amount; 00056 } 00057 00058 double Chemical::GetInitialAmount() const 00059 { 00060 return initialAmount; 00061 } 00062 00063 double Chemical::GetErrorInInitialAmount() const 00064 { 00065 return errorInInitialAmount; 00066 } 00067 00068 void Chemical::SetInitialAmount(double initialAmount) 00069 { 00070 this->initialAmount = initialAmount; 00071 } 00072 00073 void Chemical::SetErrorInInitialAmount(double errorInInitialAmount) 00074 { 00075 this->errorInInitialAmount = errorInInitialAmount; 00076 } 00077 00078 const std::vector<Reaction *> *Chemical::GetReactions() const 00079 { 00080 return &reactions; 00081 } 00082 00083 void Chemical::IncrementAmount(double change) 00084 { 00085 amount += change; 00086 } 00087 00088 void Chemical::SetAmount(double amount) 00089 { 00090 this->amount = amount; 00091 } 00092 00093 void Chemical::Reset() 00094 { 00095 SetAmount(initialAmount); 00096 } 00097 00098 std::string Chemical::GetName() const 00099 { 00100 return name; 00101 } 00102 00103 int Chemical::GetChemicalNumber() 00104 { 00105 return chemicalNumber; 00106 } 00107 00108 void Chemical::SetTeXName() 00109 { 00110 // parse the name string into a TeX string 00111 std::ostringstream stream; 00112 //strstream stream; 00113 // make sure name does not appear in italics 00114 stream << "{\\mathrm{"; 00115 // write remaining characters into name array 00116 for(int i = 0; i < name.size(); i++) 00117 { 00118 stream << name[i]; 00119 } 00120 // now close the subscript bracket, along with a null character 00121 stream << "}}" << ends; 00122 // set the TeX string equal to what's in the stream 00123 m_sTeXName = stream.str(); 00124 // allow deletion of the stream 00125 // stream.rdbuf()->freeze(0); 00126 }