00001 #include "GMatrixList_Manager.h"
00002 #include "io/GError_Output.h"
00003
00004 #include <sstream>
00005 #include <string>
00006
00007 using namespace GMathLib;
00008 using namespace GMathLib::Util;
00009 using namespace GMathLib::IO;
00010
00011 GMatrixList_Manager::GMatrixList_Manager()
00012 : GObject()
00013 {
00014 Class_Name("GMatrixList_Manager");
00015 }
00016
00017 GMatrixList_Manager::~GMatrixList_Manager()
00018 {
00019 GMatrixList::iterator itr;
00020 itr = matrix_list.begin();
00021
00022
00023
00024 while(itr != matrix_list.end()){
00025 delete itr->second;
00026 itr++;
00027 }
00028 }
00029
00030 bool GMatrixList_Manager::register_matrix(int id, GMatrix* p_matrix)
00031 {
00032 GMatrixList::iterator itr;
00033 itr = matrix_list.find(id);
00034
00035
00036 if(itr == matrix_list.end()){
00037 matrix_list.insert(std::pair<int, GMatrix*>(id, p_matrix));
00038 return true;
00039
00040 }else{
00041 return false;
00042 }
00043
00044 }
00045
00046 void GMatrixList_Manager::Register_Matrix(int id, GMatrix& mx)
00047 {
00048
00049
00050 GMatrix* p_created_mx = new GMatrix(mx.Row(), mx.Column());
00051 p_created_mx->Object_Name(mx.Object_Name());
00052 p_created_mx->Copy(mx);
00053
00054
00055
00056 if(!register_matrix(id, p_created_mx)){
00057 std::ostringstream oss;
00058 oss << id;
00059 std::string errorinfo = "Specified ID '" + oss.str() +"' has been previously used.";
00060 GError_Output::Puts(Class_Name() + "::Register_Matrix", errorinfo);
00061
00062
00063 delete p_created_mx;
00064 return;
00065 }
00066 }
00067
00068
00069 GMatrix* GMatrixList_Manager::Create_Register_Matrix(int id, int row, int column)
00070 {
00071
00072 GMatrix* p_created_mx = new GMatrix(row, column);
00073
00074
00075
00076 if(!register_matrix(id, p_created_mx)){
00077 std::ostringstream oss;
00078 oss << id;
00079 std::string errorinfo = "Specified ID '" + oss.str() +"' has been previously used.";
00080 GError_Output::Puts(Class_Name() + "::CreateRegister_Matrix", errorinfo);
00081
00082
00083 delete p_created_mx;
00084 return 0;
00085 }
00086
00087 return p_created_mx;
00088 }
00089
00090 void GMatrixList_Manager::Delete_Matrix(int id)
00091 {
00092 GMatrixList::iterator itr;
00093 itr = matrix_list.find(id);
00094
00095
00096
00097 if(itr != matrix_list.end()){
00098
00099 delete itr->second;
00100
00101
00102 matrix_list.erase(id);
00103 }else{
00104 std::ostringstream oss;
00105 oss << id;
00106 std::string errorinfo = "Specified ID '" + oss.str() +"' is not found in registered IDs.";
00107 GError_Output::Puts(Class_Name() + "::Delete", errorinfo);
00108
00109 }
00110
00111 }
00112
00113