summaryrefslogtreecommitdiff
path: root/Option
diff options
context:
space:
mode:
authorGaspard Coulet <gaspard.coulet@mines-ales.org>2021-04-28 23:12:36 +0200
committerGaspard Coulet <gaspard.coulet@mines-ales.org>2021-04-28 23:12:36 +0200
commitb4c345e6a5fa929ba20eac19183b9c777055f52d (patch)
tree23a0232f2526c5ab7f53391609a8a0a5960865f0 /Option
Initial commit
Diffstat (limited to 'Option')
-rw-r--r--Option/Option.cpp71
-rw-r--r--Option/Option.h25
-rw-r--r--Option/OptionTab.cpp98
-rw-r--r--Option/OptionTab.h20
-rw-r--r--Option/Type.cpp63
-rw-r--r--Option/Type.h24
6 files changed, 301 insertions, 0 deletions
diff --git a/Option/Option.cpp b/Option/Option.cpp
new file mode 100644
index 0000000..41f3792
--- /dev/null
+++ b/Option/Option.cpp
@@ -0,0 +1,71 @@
+#include<string>
+#include"./Option.h"
+#include".//Type.h"
+#include<iostream>
+using namespace std;
+/**
+* Constructeur d'option vide
+* @method Option::Option
+*/
+Option::Option() : m_id(-1), m_intitul(), m_rac(), m_type(), m_description(){}
+/**
+ * Constructeur par arguments
+ * @method Option::Option
+ * @param id ID de l'option
+ * @param intitul Intitulé de l'option
+ * @param rac Raccourci de l'option
+ * @param type Type d'option
+ * @param description Description de l'option
+ */
+Option::Option(int id, const string &intitul, const string &rac, const Type::TypeEnum type, const string &description) : m_id(id), m_intitul(intitul), m_rac(rac), m_type(type), m_description(description) {}
+/**
+ * @method Option::GetOptionId
+ * @return ID de l'option
+ */
+int Option::getOptionID() const { return m_id; }
+/**
+ * @method Option::GetOptionType
+ * @return Type d'option
+ */
+Type::TypeEnum Option::getOptionType() const { return m_type.getType(); }
+/**
+ * @method Option::GetOptionInt
+ * @return Intitulé de l'option
+ */
+string Option::getOptionInt() const { return m_intitul; }
+/**
+ * @method Option::GetOptionRac
+ * @return Raccourci de l'option
+ */
+string Option::getOptionRac() const { return m_rac; }
+
+/**
+ * @method Option::SetOptionType
+ * @param t Nouveau type d'option
+ */
+void Option::setOptionType(Type::TypeEnum t ) { m_type.setType(t); }
+/**
+ * @method Option::SetOptionInt
+ * @param intitul Nouveau Intitulé
+ */
+void Option::setOptionInt(std::string &intitul) { m_intitul = intitul; }
+/**
+ * @method Option::SetOptionRac
+ * @param rac Nouveau Raccourci
+ */
+void Option::setOptionRac(std::string &rac) { m_rac = rac; }
+
+/**
+ * Méthode d'affichage en complément de <<
+ * @method print
+ * @param os Flux
+ */
+void Option::print(std::ostream& os) const{
+ os << m_intitul << " (" << m_rac <<")"<<" <" << m_type <<"> ""\t"<<m_description<<std::endl;
+}
+
+std::ostream& operator<<(std::ostream& os, Option o )
+{
+ o.print(os);
+ return os;
+}
diff --git a/Option/Option.h b/Option/Option.h
new file mode 100644
index 0000000..f30d5de
--- /dev/null
+++ b/Option/Option.h
@@ -0,0 +1,25 @@
+#ifndef _OPTION_H_
+#define _OPTION_H_
+#include<string>
+#include"Type.h"
+class Option {
+ private :
+ int m_id;
+ std::string m_intitul;
+ std::string m_rac;
+ Type m_type;
+ std::string m_description;
+ public :
+ Option();
+ Option(int id, const std::string &intitul, const std::string &m_rac, const Type::TypeEnum type, const std::string &m_description);
+ int getOptionID() const;
+ Type::TypeEnum getOptionType() const;
+ std::string getOptionInt() const;
+ std::string getOptionRac() const;
+ void setOptionType(Type::TypeEnum t);
+ void setOptionInt(std::string &intitul);
+ void setOptionRac(std::string &rac);
+ void print(std::ostream& os) const;
+};
+std::ostream& operator<<(std::ostream& os, Option o);
+#endif
diff --git a/Option/OptionTab.cpp b/Option/OptionTab.cpp
new file mode 100644
index 0000000..8e35606
--- /dev/null
+++ b/Option/OptionTab.cpp
@@ -0,0 +1,98 @@
+#include"./OptionTab.h"
+#include"./Option.h"
+#include<exception>
+#include<string>
+#include<iostream>
+/**
+ * Constructeur par défauts
+ * @method OptionTab::OptionTab
+ */
+OptionTab::OptionTab() : m_Tab(), m_nb_options(0) {}
+/**
+ * Ajoute une option
+ * @method OptionTab::AddOption
+ * @param opt [description]
+ */
+void OptionTab::addOption(const Option &opt) {
+ if (m_nb_options == 10) {
+ std::cerr << "\033[0;31m ERROR [ "<< "Error when trying to create an option, to many options created" << " IN FILE " << __FILE__ << " AT LINE " << __LINE__ << " ] \n \033[0m";
+ std::terminate();
+ }
+ else {
+ m_Tab[m_nb_options] = opt;
+ m_nb_options++;
+ }
+}
+/**
+ * Affiche les options
+ * @method OptionTab::PrintOptions
+ */
+void OptionTab::printOptions() const {
+ for (size_t i = 0; i < m_nb_options; i++) {
+ std::cout << m_Tab[i] << '\n';
+ }
+}
+/**
+ * @method OptionTab::GetOptionID
+ * @param opt Nom de l'option
+ * @return ID de cette option
+ */
+int OptionTab::getOptionID(const std::string &opt) const{
+ int i = 0;
+ bool trouve = false;
+ while (i < 10 && trouve == false ) {
+ if (m_Tab[i].getOptionInt() == opt || m_Tab[i].getOptionRac() == opt) {
+ trouve = true;
+ }
+ i++;
+ }
+ return m_Tab[i-1].getOptionID();
+}
+/**
+ * @method OptionTab::GetArgument
+ * @param opt Nom de l'option
+ * @return Argument de cette option
+ */
+Type::TypeEnum OptionTab::getArgument(const std::string &opt) const {
+ int i = 0;
+ bool trouve = false;
+ while (i < 10 && trouve == false ) {
+ if (m_Tab[i].getOptionInt() == opt || m_Tab[i].getOptionRac() == opt ) {
+ trouve = true;
+ }
+ i++;
+ }
+ return m_Tab[i-1].getOptionType();
+}
+/**
+ * @method OptionTab::getRaccour
+ * @param opt Nom de l'option
+ * @return Raccourci de cette option
+ */
+std::string OptionTab::getRaccour(const std::string &opt) const {
+ int i = 0;
+ bool trouve = false;
+ while (i < 10 && trouve == false ) {
+ if (m_Tab[i].getOptionRac() == opt || m_Tab[i].getOptionInt() == opt ) {
+ trouve = true;
+ }
+ i++;
+ }
+ return m_Tab[i-1].getOptionRac();
+}
+/**
+ * @method OptionTab::getIntitul
+ * @param opt Nom de l'option
+ * @return Intitulé de cette option
+ */
+std::string OptionTab::getIntitul(const std::string &opt) const {
+ int i = 0;
+ bool trouve = false;
+ while (i < 10 && trouve == false ) {
+ if (m_Tab[i].getOptionInt() == opt || m_Tab[i].getOptionRac() == opt) {
+ trouve = true;
+ }
+ i++;
+ }
+ return m_Tab[i-1].getOptionInt();
+}
diff --git a/Option/OptionTab.h b/Option/OptionTab.h
new file mode 100644
index 0000000..0e45aaf
--- /dev/null
+++ b/Option/OptionTab.h
@@ -0,0 +1,20 @@
+#ifndef _OPTION_TAB_H_
+#define _OPTION_TAB_H_
+#include"Option.h"
+#include"Type.h"
+#include<string>
+class OptionTab {
+ private:
+ Option m_Tab[10];
+ size_t m_nb_options;
+ public:
+ OptionTab();
+ void addOption(const Option &opt);
+ void printOptions() const;
+ int getOptionID(const std::string &opt) const;
+ Type::TypeEnum getArgument(const std::string &opt) const;
+ std::string getRaccour(const std::string &opt) const;
+ std::string getTypeOption(const std::string &opt) const;
+ std::string getIntitul(const std::string &opt) const;
+};
+#endif
diff --git a/Option/Type.cpp b/Option/Type.cpp
new file mode 100644
index 0000000..3fa2052
--- /dev/null
+++ b/Option/Type.cpp
@@ -0,0 +1,63 @@
+#include"./Type.h"
+#include<iostream>
+#include<string>
+/**
+* Constructeur par défaut
+* @method Type::Type
+*/
+Type::Type() : m_type() {}
+
+/**
+* Constructeur avec arguments
+* @method Type::Type
+* @param type Nom du type
+*/
+Type::Type(Type::TypeEnum type) {
+ m_type = type;
+}
+
+/**
+ * Affiche dans le flux une chaine de caractére décrivant le type
+ * @method Type::print
+ * @param os Flux
+ */
+void Type::print(std::ostream& os) const {
+ switch (m_type) {
+ case NONE:
+ os << "NONE";
+ break;
+ case INT:
+ os << "ENTIER";
+ break;
+ case FLOAT:
+ os << "REEL";
+ break;
+ case STRING:
+ os << "STRING";
+ break;
+ default :
+ std::cerr << "\033[0;31m ERROR [ "<< "Can't recognize option type" << " IN FILE " << __FILE__ << " AT LINE " << __LINE__ << " ] \n \033[0m";
+ break;
+ };
+}
+
+/**
+* @method Type::setType
+* @param type Nouveau type
+*/
+void Type::setType(Type::TypeEnum type) {
+ m_type = type;
+}
+
+/**
+* @method Type::getType
+* @return Type
+*/
+Type::TypeEnum Type::getType() const {
+ return m_type;
+}
+
+std::ostream& operator<<(std::ostream& os, Type t){
+ t.print(os);
+ return os;
+}
diff --git a/Option/Type.h b/Option/Type.h
new file mode 100644
index 0000000..eff732b
--- /dev/null
+++ b/Option/Type.h
@@ -0,0 +1,24 @@
+#ifndef _TYPE_H
+#define _TYPE_H
+#include<string>
+#include<iostream>
+
+class Type {
+public:
+ enum TypeEnum {
+ NONE,
+ INT,
+ FLOAT,
+ STRING
+ };
+ private :
+ Type::TypeEnum m_type;
+ public :
+ Type();
+ Type(Type::TypeEnum type);
+ void print(std::ostream& os) const;
+ void setType(Type::TypeEnum type);
+ Type::TypeEnum getType() const;
+};
+std::ostream& operator<<(std::ostream& os, Type t);
+#endif