88 lines
1.6 KiB
C++
88 lines
1.6 KiB
C++
//
|
|
// Parameters.cpp
|
|
// Parameters
|
|
//
|
|
// Created by Baranyai David on 2018. 06. 30..
|
|
// Copyright © 2018. Baranyai David. All rights reserved.
|
|
//
|
|
|
|
#include "Parameters.hpp"
|
|
|
|
Parameters* Parameters::GetInstance()
|
|
{
|
|
if (instance == 0)
|
|
{
|
|
instance = new Parameters();
|
|
}
|
|
|
|
return instance;
|
|
}
|
|
|
|
Parameters* Parameters::instance = 0;
|
|
|
|
Parameters::Parameters()
|
|
{
|
|
try
|
|
{
|
|
file.open("data.txt");
|
|
if(!file.is_open())
|
|
{
|
|
throw "File opening error";
|
|
}
|
|
|
|
int index_helper = 0;
|
|
double material_helper = 0;
|
|
|
|
//Read the data
|
|
file >> energy >> shape;
|
|
file >> length_x >> length_y >> length_z;
|
|
file >> n_x >> n_y >> n_z;
|
|
for(int i = 0; i < (n_x * n_y * n_z); i++)
|
|
{
|
|
file >> index_helper;
|
|
if(index_helper == i)
|
|
{
|
|
file >> material_helper;
|
|
material.push_back(material_helper);
|
|
}
|
|
else
|
|
{
|
|
throw "Index mismatch in file";
|
|
}
|
|
}
|
|
}
|
|
//Check if any errors happen when opening the file
|
|
catch(char param)
|
|
{
|
|
std::cout << param << std::endl;
|
|
}
|
|
}
|
|
|
|
double Parameters::GetMaterial(int x, int y, int z)
|
|
{
|
|
//To-Do
|
|
return 0;
|
|
}
|
|
|
|
double Parameters::GetMaterial(int index)
|
|
{
|
|
if(index > material.size() || index < 0)
|
|
{
|
|
return -1;
|
|
}
|
|
else
|
|
{
|
|
return material[index];
|
|
}
|
|
}
|
|
|
|
std::vector<double> Parameters::GetMaterialList()
|
|
{
|
|
return material;
|
|
}
|
|
|
|
double Parameters::GetListSize()
|
|
{
|
|
return material.size();
|
|
}
|