From 45581d3d376e8deed84952cb838ae330549e5241 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 12 May 2009 23:18:17 +0200 Subject: my cpu design --- ue3/mycpu/cmem.h | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 ue3/mycpu/cmem.h (limited to 'ue3/mycpu/cmem.h') diff --git a/ue3/mycpu/cmem.h b/ue3/mycpu/cmem.h new file mode 100644 index 0000000..5045c34 --- /dev/null +++ b/ue3/mycpu/cmem.h @@ -0,0 +1,109 @@ +/** + * @module cmem + * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) + * @brief Memory template and memory definition for CCPU + * @date 10.05.2009 + */ + +#ifndef CMEM_H +#define CMEM_H 1 + +#include +#include +#include +#include +#include +#ifdef DEBUG +# include +# include +#endif +#include "cdat.h" + +/** + * @class CVectorMem + * + * Extends std::vector template for use as memory for CCPU. + */ +template > +class CVectorMem + : public std::vector +{ + public: + using std::vector::size; + using std::vector::at; + + /** + * @method initialize + * @brief initialize the vector with the content of istream. istream is + * read per line. empty lines will add unitialized elements. + * @param in inputstream to read from + * @return void + * @globalvars none + * @exception std::runtime_error + * @conditions none + */ + void initialize(std::istream& in) + { + if (!in.good()) + return; + + std::string line; + unsigned i = 0; + while (!in.eof() && in.good()) + { + ++i; + std::getline(in, line); + + /* skip last line if it's empty */ + if (line.empty() && in.eof()) + break; + + T value; + try + { + if (!line.empty()) + value = boost::lexical_cast(line); + } + catch(boost::bad_lexical_cast& ex) + { + std::stringstream sstr; + sstr << "Unable to convert input (line " << i << "): " << ex.what(); + throw std::runtime_error(sstr.str()); + } + + push_back(value); + } + } + +#if DEBUG + /** + * @method dump + * @brief dumps contents of vector to outputstream + * @param out outputstream to write to + * @return void + * @globalvars none + * @exception none + * @conditions none + */ + void dump(std::ostream& out) + { + out << "[MEMORY DUMP]" << std::endl; + for(unsigned i = 0; i < size(); ++i) + { + out << "[" << std::setw(4) << std::setfill('0') << i << "] " + << at(i) << std::endl; + } + } +#endif +}; + +/** + * @class CMem + * + * Memory definition for CCPU + */ +typedef CVectorMem CMem; + +#endif + +/* vim: set et sw=2 ts=2: */ -- cgit v1.2.3