pelib  2.0.0
src/schedule-tetris.cpp
Go to the documentation of this file.
00001 /*
00002  Copyright 2015 Nicolas Melot
00003 
00004  This file is part of Pelib.
00005 
00006  Pelib is free software: you can redistribute it and/or modify
00007  it under the terms of the GNU General Public License as published by
00008  the Free Software Foundation, either version 3 of the License, or
00009  (at your option) any later version.
00010 
00011  Pelib is distributed in the hope that it will be useful,
00012  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  GNU General Public License for more details.
00015 
00016  You should have received a copy of the GNU General Public License
00017  along with Pelib. If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 
00021 #include <iostream>
00022 
00023 #include <pelib/parser.h>
00024 #include <pelib/output.h>
00025 
00026 #include <pelib/TetrisSchedule.hpp>
00027 #include <pelib/Taskgraph.hpp>
00028 
00029 using namespace std;
00030 using namespace pelib;
00031 
00032 #ifdef __cplusplus
00033 extern "C" {
00034 #endif
00035 
00036 #ifndef debug
00037 #define debug(expr) cerr << "[" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "] " << #expr << " = \"" << expr << "\"." << endl;
00038 #endif
00039 
00040 // /!\ the content of argv is freed after this function is run
00041 void
00042 pelib_dump(std::ostream& cout, std::map<const char*, Record*> records, size_t argc, char **argv)
00043 {
00044         Schedule *sc = (Schedule*)records.find(typeid(Schedule).name())->second;
00045         Taskgraph *tg = (Taskgraph*)records.find(typeid(Taskgraph).name())->second;
00046         Platform *pt = (Platform*)records.find(typeid(Platform).name())->second;
00047 
00048         if(argv[0] != NULL)
00049         {
00050                 float ratio = TetrisSchedule::defaultRatio();
00051                 float stroke_size = TetrisSchedule::defaultStrokeSize();
00052                 vector<unsigned int> colors = TetrisSchedule::defaultFrequencyColors();
00053                 bool showFrequencies = true;
00054                 bool useTaskName = false;
00055                 bool showTaskId = true;
00056                 
00057                 for(; argv[0] != NULL; argv++)
00058                 {
00059                         if(strcmp(argv[0], "--ratio") == 0)
00060                         {
00061                                 argv++;
00062                                 std::istringstream converter(argv[0]);
00063                                 converter >> ratio;
00064                                 if(converter.fail())
00065                                 {
00066                                         ratio = TetrisSchedule::defaultRatio();
00067                                 }
00068 
00069                                 continue;
00070                         }
00071 
00072                         if(strcmp(argv[0], "--no-legend") == 0)
00073                         {
00074                                 showFrequencies = false;
00075                                 continue;
00076                         }
00077 
00078                         if(strcmp(argv[0], "--no-task-id") == 0)
00079                         {
00080                                 showTaskId = false;
00081                         }
00082 
00083                         if(strcmp(argv[0], "--use-task-name") == 0)
00084                         {
00085                                 useTaskName = true;
00086                                 continue;
00087                         }
00088 
00089                         if(strcmp(argv[0], "--stroke-size") == 0)
00090                         {
00091                                 argv++;
00092                                 std::istringstream converter(argv[0]);
00093                                 converter >> stroke_size;       
00094                                 if(converter.fail())
00095                                 {
00096                                         stroke_size = TetrisSchedule::defaultStrokeSize();
00097                                 }
00098                                 continue;
00099                         }
00100 
00101                         if(strcmp(argv[0], "--gradient") == 0)
00102                         {
00103                                 colors.clear();
00104                                 argv++;
00105                                 if(argv[0] != NULL)
00106                                 {
00107                                         unsigned int color;
00108                                         bool isInt = true;
00109                                         stringstream converter;
00110                                         converter << hex << argv[0];
00111                                         converter >> color;
00112                                         isInt = !converter.fail();
00113 
00114                                         // Read all integers
00115                                         while(argv[0] != NULL && isInt)
00116                                         {
00117                                                 colors.push_back(color);
00118                                                 argv++;
00119                                                 if(argv[0] != NULL)
00120                                                 {
00121                                                         converter.str("");
00122                                                         converter.clear();
00123                                                         converter << hex << argv[0];
00124                                                         converter >> color;
00125                                                         isInt = !converter.fail();
00126                                                 }
00127                                         }
00128                                         argv--;
00129                                 }
00130 
00131                                 if(colors.size() < 2)
00132                                 {
00133                                         colors = TetrisSchedule::defaultFrequencyColors();
00134                                 }
00135 
00136                                 continue;
00137                         }
00138                 }
00139 
00140                 TetrisSchedule(ratio, showFrequencies, showTaskId, useTaskName, colors, stroke_size).dump(cout, sc, tg, pt);
00141         }
00142         else    
00143         {
00144                 TetrisSchedule().dump(cout, sc, tg, pt);
00145         }
00146 }
00147 
00148 void
00149 pelib_delete(Record *obj)
00150 {
00151         delete obj;
00152 }
00153 
00154 #ifdef __cplusplus
00155 }
00156 #endif
00157