#ifndef _PROJECT_DESC_H_
#define _PROJECT_DESC_H_
#include <iostream>
#include <string>
#include <vector>
class Project_desc {
public:
Project_desc (std::string * name, std::string * description)
: _name(name), _description(description) {
if (_name->find_first_of("{") != std::string::npos && _name->find_last_of("}") != std::string::npos)
*_name = _name->substr(_name->find_first_of("{") + 1,
_name->find_last_of("}") - _name->find_first_of("{") - 1
);
};
~Project_desc () {
delete _name;
delete _description;
};
const std::string project_name() {
return *_name;
}
void view_full() {
char **argv = 0;
argv = new char*[3];
std::string execute = "./Project/" + (*_name);
argv[0] = new char[execute.length() + 1];
strcpy(argv[0], execute.c_str());
argv[1] = new char[_name->length() + 1];
strcpy(argv[1], _name->c_str());
argv[2] = static_cast<char *> (0);
execv(argv[0], argv + 1);
}
friend std::ostream& operator<< (std::ostream& o, const Project_desc& project);
private:
std::string * _name;
std::string * _description;
};
class Project_list {
public:
Project_list () {};
~Project_list () {
};
void add_project(Project_desc * project) {
_Projects.push_back(project);
}
void list_projects() {
for(std::vector<Project_desc *>::iterator a = _Projects.begin(), b = _Projects.end();
a!=b; a++) {
std::cout << *(*a) << std::endl;
}
std::cout << "Which project would like more information about: " << std::endl;
int i = 0;
for(std::vector<Project_desc *>::iterator a = _Projects.begin(), b = _Projects.end();
a!=b; a++) {
std::cout << "\t" << i++ << ". " << (*a)->project_name() << std::endl;
}
int input;
std::cout << "Enter your selection: " << std::flush;
std::cin >> input;
try {
Project_desc * selected = (_Projects.at(input));
selected->view_full();
}
catch (std::exception e) {
std::cout << "Bad selection" << std::endl;
}
}
private:
std::vector<Project_desc *> _Projects;
};
std::ostream& operator<< (std::ostream& o, const Project_desc& project) {
o << "Name: " << *project._name << std::endl;
o << "Description: " << std::endl << "\t" << *project._description << std::endl;
return o;
}
#endif /* _PROJECT_DESC_H_ */