PhoenixLecture  2.0.0
Set of tools to make lectures
ptimtable_load.cpp
Go to the documentation of this file.
1 /***************************************
2  Auteur : Pierre Aubert
3  Mail : pierre.aubert@lapp.in2p3.fr
4  Licence : CeCILL-C
5 ****************************************/
6 
7 #include "platexobj_parse.h"
8 #include "ptimtable_load.h"
9 
11 
15 PString ptimetable_loadString(const DicoValue & dico, const PString & attributeName){
16  return phoenix_load_value_from_config<PString>(dico, attributeName, "").eraseFirstLastChar("\"'\t\n ");
17 }
18 
20 
25 bool ptimetable_parseLatexAttribute(PLatexObj & obj, const DicoValue & value, const PString & attributeName){
26  PString valueStr(ptimetable_loadString(value, attributeName));
27  if(valueStr == ""){
28  return false;
29  }
30  if(!platexobj_parseStr(obj, valueStr)){
31  std::cerr << "ptimetable_parseLatexAttribute : cannot parse value of attribute '"<<attributeName<<"'" << std::endl;
32  return false;
33  }
34  return true;
35 }
36 
38 
42 bool ptimetable_loadSpeaker(std::vector<PLatexSpeaker> & vecOutputSpeaker, const DicoValue & dico){
43  const DicoValue * mapSpeaker = dico.getMap("speaker");
44  if(mapSpeaker == NULL){return true;} //If there is no speaker, this is not a problem
45  const VecDicoValue & vecSpeaker = mapSpeaker->getVecChild();
46  for(VecDicoValue::const_iterator it(vecSpeaker.begin()); it != vecSpeaker.end(); ++it){
47  PLatexSpeaker speaker;
48  PString name(ptimetable_loadString(*it, "name"));
49  if(!ptimetable_parseLatexAttribute(speaker.getName(), *it, "name")){
50  std::cerr << "ptimetable_loadSpeaker : missing 'name'" << std::endl;
51  }
52  ptimetable_parseLatexAttribute(speaker.getTitle(), *it, "title");
53  if(!ptimetable_parseLatexAttribute(speaker.getJob(), *it, "function")){
54  std::cerr << "ptimetable_loadSpeaker : missing 'function' in speaker '"<<name<<"'" << std::endl;
55  }
56  if(!ptimetable_parseLatexAttribute(speaker.getAffiliation(), *it, "affiliation")){
57  std::cerr << "ptimetable_loadSpeaker : missing 'affiliation' in speaker '"<<name<<"'" << std::endl;
58  }
59  if(!ptimetable_parseLatexAttribute(speaker.getDescription(), *it, "description")){
60  std::cerr << "ptimetable_loadSpeaker : missing 'description' in speaker '"<<name<<"'" << std::endl;
61  }
62  speaker.setLabel(ptimetable_loadString(*it, "label"));
63  //TODO : find a way to bark if the label is empty
64  vecOutputSpeaker.push_back(speaker);
65  }
66  return true;
67 }
68 
70 
74  PVecString vecValue(str.split('/'));
75  PLatexDate date;
76  if(vecValue.size() >= 1lu){
77  date.setDay(atol(vecValue[0lu].c_str()));
78  }
79  if(vecValue.size() >= 2lu){
80  date.setMonth(atol(vecValue[1lu].c_str()));
81  }
82  if(vecValue.size() >= 3lu){
83  date.setYear(atol(vecValue[2lu].c_str()));
84  }
85  return date;
86 }
87 
89 
94  PVecString vecValue(str.split(':'));
95  PLatexTime duration;
96  if(vecValue.size() == 1lu){
97  duration.setMinute(atol(vecValue[0lu].c_str()));
98  }else if(vecValue.size() == 2lu){
99  duration.setHour(atol(vecValue[0lu].c_str()));
100  duration.setMinute(atol(vecValue[1lu].c_str()));
101  }
102  return duration;
103 }
104 
106 
110 bool ptimetable_loadBlock(PTimeTable & timetable, const DicoValue & dico){
111  const DicoValue * mapBlock = dico.getMap("block");
112  if(mapBlock == NULL){return true;}
113  const VecDicoValue & vecBlock = mapBlock->getVecChild();
114  for(VecDicoValue::const_iterator it(vecBlock.begin()); it != vecBlock.end(); ++it){
115  PTimeTableBlock block;
116  if(!ptimetable_parseLatexAttribute(block.getTitle(), *it, "title")){}
117  if(!ptimetable_parseLatexAttribute(block.getWeekTitle(), *it, "week_title")){}
118  if(!ptimetable_parseLatexAttribute(block.getDescription(), *it, "description")){}
119 
120  block.setVecSpeaker(eraseFirstLastChar(phoenix_load_vecValue_from_config<PString>(*it, "speakers"), "\"' \n\t"));
121  block.setInvitation(ptimetable_loadString(*it, "invitation"));
122  block.setStyle(ptimetable_loadString(*it, "style"));
125 
128  block.setMainUrl(ptimetable_loadString(*it, "main_url"));
129  ptimetable_parseLatexAttribute(block.getLocation(), *it, "location");
130  timetable.getVecBlock().push_back(block);
131  }
132  return true;
133 }
134 
136 
140 bool ptimetable_loadSpeaker(std::vector<PLatexSpeaker> & vecSpeaker, const PPath & configFile){
141  DicoValue dico;
142  if(!parser_toml(dico, configFile)){
143  std::cerr << "ptimetable_loadSpeaker : cannot load toml file '"<<configFile<<"'" << std::endl;
144  return false;
145  }
146  if(!ptimetable_loadSpeaker(vecSpeaker, dico)){
147  std::cerr << "ptimetable_loadSpeaker : cannot load speakers from file '"<<configFile<<"'" << std::endl;
148  return false;
149  }
150  return true;
151 }
152 
154 
158 bool ptimetable_load(PTimeTable & timetable, const PPath & configFile){
159  DicoValue dico;
160  if(!parser_toml(dico, configFile)){
161  std::cerr << "ptimetable_load : cannot load toml file '"<<configFile<<"'" << std::endl;
162  return false;
163  }
164  if(!ptimetable_loadSpeaker(timetable.getVecSpeaker(), dico)){
165  std::cerr << "ptimetable_load : cannot load speakers from file '"<<configFile<<"'" << std::endl;
166  return false;
167  }
168 
169  DicoValue * dicoTimetable = dico.getMap("timetable");
170  if(dicoTimetable != NULL){
171  if(!ptimetable_parseLatexAttribute(timetable.getName(), *dicoTimetable, "name")){
172  std::cerr << "ptimetable_load : missing 'name' of the event" << std::endl;
173  }
174  if(!ptimetable_parseLatexAttribute(timetable.getLocation(), *dicoTimetable, "location")){
175  std::cerr << "ptimetable_load : missing 'location' of the event" << std::endl;
176  }
177  timetable.setInvitation(ptimetable_loadString(*dicoTimetable, "invitation"));
178  timetable.setBeginDate(ptimetable_parsePLatexDate(ptimetable_loadString(*dicoTimetable, "begin_date")));
179  timetable.setEndDate(ptimetable_parsePLatexDate(ptimetable_loadString(*dicoTimetable, "end_date")));
180  timetable.setMainUrl(ptimetable_loadString(*dicoTimetable, "main_url"));
181  }
182  if(!ptimetable_loadBlock(timetable, dico)){
183  std::cerr << "ptimetable_load : cannot load blocks from file '"<<configFile<<"'" << std::endl;
184  return false;
185  }
186  return true;
187 }
188 
189 
std::vector< DicoValue > VecDicoValue
Vector of DicoValue.
Definition: DicoValue.h:77
void eraseFirstLastChar(PVecString &vecOut, const PVecString &vecStr, const PString &vecChar)
Erase first and last characters of all PString in given vector.
Definition: PString.cpp:52
std::vector< PString > PVecString
Definition: PString.h:96
Dictionnary of values.
Definition: DicoValue.h:17
const std::vector< DicoValue > & getVecChild() const
Gets the vecChild of the DicoValue.
Definition: DicoValue.cpp:204
const DicoValue * getMap(const PString &key) const
Get a DicoValue in the map of the current one.
Definition: DicoValue.cpp:116
Describes a date.
Definition: PTimeTable.h:58
void setMonth(size_t month)
Sets the month of the PLatexDate.
Definition: PTimeTable.cpp:217
void setYear(size_t year)
Sets the year of the PLatexDate.
Definition: PTimeTable.cpp:210
void setDay(size_t day)
Sets the day of the PLatexDate.
Definition: PTimeTable.cpp:224
Describe a latex object.
Definition: PLatexObj.h:40
Describe a speaker in a timetable.
Definition: PTimeTable.h:15
void setLabel(const PString &label)
Sets the label of the PLatexSpeaker.
Definition: PTimeTable.cpp:55
const PLatexObj & getTitle() const
Gets the title of the PLatexSpeaker.
Definition: PTimeTable.cpp:97
const PLatexObj & getName() const
Gets the name of the PLatexSpeaker.
Definition: PTimeTable.cpp:83
const PLatexObj & getAffiliation() const
Gets the affiliation of the PLatexSpeaker.
Definition: PTimeTable.cpp:139
const PLatexObj & getDescription() const
Gets the description of the PLatexSpeaker.
Definition: PTimeTable.cpp:153
const PLatexObj & getJob() const
Gets the job of the PLatexSpeaker.
Definition: PTimeTable.cpp:125
Describes a date.
Definition: PTimeTable.h:86
void setMinute(size_t minute)
Sets the minute of the PLatexTime.
Definition: PTimeTable.cpp:322
void setHour(size_t hour)
Sets the hour of the PLatexTime.
Definition: PTimeTable.cpp:315
Path of a directory or a file.
Definition: PPath.h:17
Extends the std::string.
Definition: PString.h:16
std::vector< PString > split(char separator) const
Cut a PString on the given separator char.
Definition: PString.cpp:420
PString eraseFirstLastChar(const PString &vecChar) const
Erase first and last char in a string.
Definition: PString.cpp:545
Block of a Timetable.
Definition: PTimeTable.h:109
void setDate(const PLatexDate &date)
Sets the date of the PTimeTableBlock.
Definition: PTimeTable.cpp:439
const PLatexObj & getTitle() const
Gets the title of the PTimeTableBlock.
Definition: PTimeTable.cpp:516
const PLatexObj & getDescription() const
Gets the description of the PTimeTableBlock.
Definition: PTimeTable.cpp:572
void setBeginTime(const PLatexTime &beginTime)
Sets the beginTime of the PTimeTableBlock.
Definition: PTimeTable.cpp:446
void setQuestionTime(const PLatexTime &questionTime)
Sets the questionTime of the PTimeTableBlock.
Definition: PTimeTable.cpp:467
void setMainUrl(const PString &mainUrl)
Sets the mainUrl of the PTimeTableBlock.
Definition: PTimeTable.cpp:397
const PLatexObj & getLocation() const
Gets the location of the PTimeTableBlock.
Definition: PTimeTable.cpp:656
void setDuration(const PLatexTime &duration)
Sets the duration of the PTimeTableBlock.
Definition: PTimeTable.cpp:460
void setVecSpeaker(const std::vector< PString > &vecSpeaker)
Sets the vecSpeaker of the PTimeTableBlock.
Definition: PTimeTable.cpp:418
void setInvitation(const PString &invitation)
Sets the invitation of the PTimeTableBlock.
Definition: PTimeTable.cpp:425
void setStyle(const PString &style)
Sets the style of the PTimeTableBlock.
Definition: PTimeTable.cpp:481
const PLatexObj & getWeekTitle() const
Gets the weekTitle of the PTimeTableBlock.
Definition: PTimeTable.cpp:530
Timetable.
Definition: PTimeTable.h:197
const PLatexObj & getLocation() const
Gets the location of the PTimeTable.
Definition: PTimeTable.cpp:915
const std::vector< PTimeTableBlock > & getVecBlock() const
Gets the vecBlock of the PTimeTable.
Definition: PTimeTable.cpp:929
const PLatexObj & getName() const
Gets the name of the PTimeTable.
Definition: PTimeTable.cpp:845
void setInvitation(const PString &invitation)
Sets the invitation of the PTimeTable.
Definition: PTimeTable.cpp:782
void setBeginDate(const PLatexDate &beginDate)
Sets the beginDate of the PTimeTable.
Definition: PTimeTable.cpp:789
void setEndDate(const PLatexDate &endDate)
Sets the endDate of the PTimeTable.
Definition: PTimeTable.cpp:796
void setMainUrl(const PString &mainUrl)
Sets the mainUrl of the PTimeTable.
Definition: PTimeTable.cpp:768
const std::vector< PLatexSpeaker > & getVecSpeaker() const
Gets the vecSpeaker of the PTimeTable.
Definition: PTimeTable.cpp:943
bool parser_toml(DicoValue &dico, const PPath &fileName)
bool platexobj_parseStr(PLatexObj &obj, const PString &latexStr)
Parse a str and convert it into a PLatexObj.
bool ptimetable_parseLatexAttribute(PLatexObj &obj, const DicoValue &value, const PString &attributeName)
Parse an attribute in PLatexObj.
bool ptimetable_load(PTimeTable &timetable, const PPath &configFile)
Load the PTimeTable with a toml configuration.
PString ptimetable_loadString(const DicoValue &dico, const PString &attributeName)
Load a string value.
bool ptimetable_loadSpeaker(std::vector< PLatexSpeaker > &vecOutputSpeaker, const DicoValue &dico)
Load the speakers of the PTimeTable.
bool ptimetable_loadBlock(PTimeTable &timetable, const DicoValue &dico)
Load the blocks of the PTimeTable.
PLatexTime ptimetable_parsePLatexTime(const PString &str)
Load a PLatexTime with a string.
PLatexDate ptimetable_parsePLatexDate(const PString &str)
Load a PLatexDate with a string.