Pagina Principale | Lista dei namespace | Strutture dati | Lista dei file | Campi dei dati | Elementi globali

ui.cpp

Vai alla documentazione di questo file.
00001 /* Tennis Tournament Management System 2005 by Silvio Moioli
00002    and Davide Gottini (moio@tiscali.it, davide.gottini@virgilio.it). */
00003 #include <string>
00004 #include <iostream>
00005 #include "liste.h"
00006 #include "ui.h"
00007 using namespace std;
00008 
00009 /* Per i commenti sulle funzioni pubbliche e i loro i parametri (che sono 
00010   stati eliminati per  evitare inutili duplicazioni e spreco di spazio)
00011   si rimanda all'header  della libreria. */
00012 
00013 void uiStampaLinea(){
00014     cout << "--------------------"<< endl << endl;
00015 }
00016 
00017 void uiStampaMenu(Lista* voci){
00018         for (int i = 0; i < voci->n; i++){
00019         char* s = (char*) listeLeggiElemento(voci, i);
00020         cout << (i + 1) << '-' << s << endl;
00021     }
00022     cout << endl;
00023 }
00024 
00025 int uiChiediScelta(int sceltaMax){
00026         int result = -1;
00027 
00028     cout << "Digita una scelta tra 1 e " << sceltaMax;
00029     cout << " e premi INVIO: " << endl;
00030     while (result <= 0 || result > sceltaMax){
00031         cin >> result;
00032         if (cin.fail()){
00033             /* Errore nel parsing del numero. Probabilmente è stato immesso
00034                un carattere non-numerico. Salto il carattere e riprovo
00035                (non si può usare cin.ignore() in questo caso). */
00036             cin.clear();
00037             char ch;
00038             cin >> ch;
00039         }
00040     }
00041     return result;
00042 }
00043 
00044 void uiChiediConferma(){
00045     /*L'algoritmo è praticamente identico al successivo,
00046     putroppo la libreria standard del C++ non lascia scelta...*/
00047     char* tmp = new char[MAXCONSOLEINPUT];
00048     strncpy(tmp, "", MAXCONSOLEINPUT);
00049     cout << "Premi un tasto e batti INVIO..." << endl;
00050     while (strncmp(tmp, "\n", MAXCONSOLEINPUT) == 0 ||
00051             strncmp(tmp, "", MAXCONSOLEINPUT) == 0){
00052         cin.getline(tmp, MAXCONSOLEINPUT);
00053     }
00054     delete[] tmp;
00055 }
00056 
00057 char* uiChiediStringa(){
00058     char* result = new char[MAXCONSOLEINPUT];
00059     strncpy(result, "", MAXCONSOLEINPUT);
00060     cout << "Immetti il dato e premi INVIO: " << endl;
00061     while (strncmp(result, "\n", MAXCONSOLEINPUT) == 0 ||
00062             strncmp(result, "", MAXCONSOLEINPUT) == 0){
00063         cin.getline(result, MAXCONSOLEINPUT);
00064     }
00065     return result;
00066 }
00067 
00068 void uiStampaBanner(){
00069     char* s[13] =
00070             //Fa un po' schifo... Pace Amen ;)
00071 {" _______               _                                  \
00072                     ",
00073 "|__   __|             (_)                                 \
00074                     ", 
00075 "   | | ___ _ __  _ __  _ ___          Tennis Tournament 1.\
00076 0                   ", 
00077 "   | |/ _ \\ '_ \\| '_ \\| / __|         Copyleft 2004-200\
00078 5 Gotto&Moio           ", 
00079 "   | |  __/ | | | | | | \\__ \\                           \
00080                       ", 
00081 "   |_|\\___|_| |_|_| |_|_|___/                            \
00082                      ", 
00083 "      ,-----.     _______                                 \
00084                _    ", 
00085 "     /\\     /\\   |__   __|                              \
00086                 | |   ", 
00087 "    /  \\   /  \\     | | ___  _   _ _ __ _ __   __ _ _ __\
00088  ___   ___ _ __ | |_  ", 
00089 "   (    : :    )    | |/ _ \\| | | | '__| '_ \\ / _` | '_ \
00090 ` _ \\ / _ \\ '_ \\| __| ", 
00091 "    \\   +-+   /     | | (_) | |_| | |  | | | | (_| | | | \
00092 | | |  __/ | | | |_  ", 
00093 "     +-'   `-+      |_|\\___/ \\__,_|_|  |_| |_|\\__,_|_| \
00094 |_| |_|\\___|_| |_|\\__| ",
00095 "      `-----'"};
00096 
00097     for (int i =0; i<13; i++){
00098         cout<<s[i]<<endl;
00099     }
00100     cout<<endl;
00101 }

Generato il Fri Jan 28 11:43:15 2005 per TennisTournament da doxygen 1.3.6