Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "MatryceRzadkie.h"
- class CSparseCell;
- class CSparseMatrix {
- private:
- std::string name;
- int numberOfDimension; //liczba wymiarów
- std::vector <int> dimensionRanges; //zakresy wymiarów
- int defaultValue; //wartość domyślna
- std::vector <CSparseCell **> sparseCells; //komórki rzadkie
- public:
- CSparseMatrix() {
- name = "def_name";
- numberOfDimension = 0;
- defaultValue = 0;
- std::cout << "create: " << name;
- }
- CSparseMatrix(std::string matrixName) {
- name = matrixName;
- numberOfDimension = 0;
- defaultValue = 0;
- std::cout << "create: " << name << std::endl;
- }
- CSparseMatrix(CSparseMatrix &pOther) {
- name = pOther.name + "_copy";
- numberOfDimension = pOther.numberOfDimension;
- dimensionRanges = pOther.dimensionRanges;
- defaultValue = pOther.defaultValue;
- sparseCells = pOther.sparseCells;
- std::cout << "create: " << name << std::endl;
- }
- ~CSparseMatrix() {
- std::cout << "destroy: " << name << std::endl;
- }
- void setNumberOfDimension(int number) {
- numberOfDimension = number;
- }
- void addDimensionRange(int range) {
- dimensionRanges.push_back(range); //Dodaje nowy element na końcu kontenera vector.
- }
- void setDefaultValue(int value) {
- defaultValue = value;
- }
- void addSparseCells(CSparseCell **cell) {
- sparseCells.push_back(cell);
- }
- void setName(std::string matrixName) {
- name = matrixName;
- }
- std::string getName() {
- return name;
- }
- int getRange(int index) {
- return dimensionRanges[index];
- }
- int getNumberOfDimension() {
- return numberOfDimension;
- }
- };
- class CSparseCell {
- private:
- friend class CSparseMatrix; //CSparseMatrix ma dostęp do części prywatnej CSparseCell
- int sparseValue;
- std::vector <int> cellCoordinates; //współrzędne komórki
- public:
- void setSparseValue(int value) {
- sparseValue = value;
- }
- void addCellCoordinate(int coordinate) {
- cellCoordinates.push_back(coordinate); //Dodaje nowy element na końcu kontenera vector.
- }
- };
- class Manager {
- private:
- std::vector <CSparseMatrix *> vectorOfMatrices;
- std::vector <int> ranges;
- public:
- void addRange(int range) {
- ranges.push_back(range);
- }
- void addMatrix(int numberOfDimension, std::string matrixName, int def) {
- CSparseMatrix *pMatrix = new CSparseMatrix(matrixName);
- vectorOfMatrices.push_back(pMatrix);
- pMatrix->setNumberOfDimension(numberOfDimension);
- int bound = ranges.size();
- for (int i = 0; i < bound; i++) {
- pMatrix->addDimensionRange(ranges[i]);
- }
- pMatrix->setDefaultValue(def);
- ranges.clear();
- }
- void list() {
- std::cout << vectorOfMatrices.size() << " matrices: " << std::endl;
- int bound = vectorOfMatrices.size();
- for (int i = 0; i < bound; i++) {
- std::string name = (*vectorOfMatrices[i]).getName();
- std::cout << "[" << i << "] - \"" << name << "\" size: [";
- for (int j = 0; j < (*vectorOfMatrices[i]).getNumberOfDimension(); j++) {
- std::cout << (*vectorOfMatrices[i]).getRange(j) << " ";
- }
- std::cout << "]" << std::endl;
- }
- }
- };
- int main()
- {
- /*std::vector <CSparseMatrix **> vectorOfMatrices;
- CSparseMatrix *pMatrix = new CSparseMatrix();
- vectorOfMatrices.push_back(&pMatrix);*/
- Manager m;
- m.addRange(5);
- m.addRange(10);
- m.addRange(15);
- m.addMatrix(3, "test", 1);
- m.addRange(100);
- m.addRange(10);
- m.addRange(15);
- m.addRange(10);
- m.addRange(20);
- m.addMatrix(5, "test2", 1);
- m.list();
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement