Permalink
Browse files

ZarzadcaZadan added

  • Loading branch information...
1 parent e5b6742 commit 3428c3e06700471599c6ff9070bcaf679bf9467f @fiedukow committed May 14, 2012
Showing with 103 additions and 0 deletions.
  1. +79 −0 src/ZarzadcaZadan.cpp
  2. +24 −0 src/ZarzadcaZadan.hpp
View
@@ -0,0 +1,79 @@
+#include "ZarzadcaZadan.hpp"
+#include "EvolException.hpp"
+#include <string>
+#include <fstream>
+
+typedef int time_type;
+
+ZarzadcaZadan& ZarzadcaZadan::getInstance( const std::string& fileName )
+{
+ static ZarzadcaZadan instance(fileName);
+ return instance;
+}
+
+/**
+ * Class that provides informations about time that each Machine spends doing each Task.
+ * This class can read informations from file if it is needed
+ **/
+ZarzadcaZadan::ZarzadcaZadan( std::string fileName ) throw (evol::CannotOpenFileException)
+{
+ std::ifstream fileToRead;
+ fileToRead.open( fileName.c_str(), std::ios::in );
+ if( fileToRead.is_open() )
+ {
+ fileToRead >> iloscMaszyn >> iloscZadan;
+ czasy = new time_type*[ iloscMaszyn ];
+ for ( int i = 0; i < iloscMaszyn; ++i )
+ {
+ czasy[i] = new time_type[iloscZadan];
+ }
+ for ( int i = 0; i < iloscMaszyn; ++i )
+ {
+ for( int j = 0; j < iloscZadan; ++j )
+ {
+ if( fileToRead.good() )
+ {
+ fileToRead >> czasy[i][j];
+ }
+ else
+ {
+ throw evol::FileException( fileName ); /*TODO: it should be another exception*/
+ }
+ }
+ }
+ }
+ else
+ {
+ throw evol::CannotOpenFileException(fileName);
+ }
+}
+
+ZarzadcaZadan::~ZarzadcaZadan()
+{
+ for( int i = 0; i < iloscMaszyn; ++i )
+ {
+ delete[] czasy[i];
+ }
+ delete[] czasy;
+}
+
+int ZarzadcaZadan::getIloscMaszyn()
+{
+ return iloscMaszyn;
+}
+
+int ZarzadcaZadan::getIloscZadan()
+{
+ return iloscZadan;
+}
+
+time_type ZarzadcaZadan::czasObrobki( int idMaszyny, int idZadania )
+{
+ if( idMaszyny >= iloscMaszyn || idZadania >= iloscZadan )
+ {
+ /*TODO: out of bound exception here */
+ }
+ return czasy[idMaszyny][idZadania];
+}
+
+
View
@@ -0,0 +1,24 @@
+#pragma once
+#include <string>
+#include "EvolException.hpp"
+
+typedef int time_type;
+
+class ZarzadcaZadan
+{
+ time_type **czasy;
+ int iloscMaszyn, iloscZadan;
+
+ private:
+ ZarzadcaZadan();
+ ZarzadcaZadan( std::string fileName ) throw ( evol::CannotOpenFileException );
+ ZarzadcaZadan(ZarzadcaZadan const&);
+ void operator=(ZarzadcaZadan const&);
+ public:
+ ~ZarzadcaZadan();
+ static ZarzadcaZadan& getInstance( const std::string& fileName = "zadania.dat");
+ int getIloscMaszyn();
+ int getIloscZadan();
+ time_type czasObrobki( int idMaszyny, int idZadania );
+};
+

0 comments on commit 3428c3e

Please sign in to comment.