PhoenixLecture  2.0.0
Set of tools to make lectures
ptimtable_load.cpp File Reference
#include "platexobj_parse.h"
#include "ptimtable_load.h"
+ Include dependency graph for ptimtable_load.cpp:

Go to the source code of this file.

Functions

bool ptimetable_load (PTimeTable &timetable, const PPath &configFile)
 Load the PTimeTable with a toml configuration. More...
 
bool ptimetable_loadBlock (PTimeTable &timetable, const DicoValue &dico)
 Load the blocks of the PTimeTable. More...
 
bool ptimetable_loadSpeaker (std::vector< PLatexSpeaker > &vecOutputSpeaker, const DicoValue &dico)
 Load the speakers of the PTimeTable. More...
 
bool ptimetable_loadSpeaker (std::vector< PLatexSpeaker > &vecSpeaker, const PPath &configFile)
 Load the PTimeTable with a toml configuration. More...
 
PString ptimetable_loadString (const DicoValue &dico, const PString &attributeName)
 Load a string value. More...
 
bool ptimetable_parseLatexAttribute (PLatexObj &obj, const DicoValue &value, const PString &attributeName)
 Parse an attribute in PLatexObj. More...
 
PLatexDate ptimetable_parsePLatexDate (const PString &str)
 Load a PLatexDate with a string. More...
 
PLatexTime ptimetable_parsePLatexTime (const PString &str)
 Load a PLatexTime with a string. More...
 

Function Documentation

◆ ptimetable_load()

bool ptimetable_load ( PTimeTable timetable,
const PPath configFile 
)

Load the PTimeTable with a toml configuration.

Parameters
[out]timetable: PTimeTable to be updated
configFile: configuration file to be used
Returns
true on success, false otherwise

Definition at line 158 of file ptimtable_load.cpp.

158  {
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 }
Dictionnary of values.
Definition: DicoValue.h:17
const DicoValue * getMap(const PString &key) const
Get a DicoValue in the map of the current one.
Definition: DicoValue.cpp:116
const PLatexObj & getLocation() const
Gets the location of the PTimeTable.
Definition: PTimeTable.cpp:915
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 ptimetable_parseLatexAttribute(PLatexObj &obj, const DicoValue &value, const PString &attributeName)
Parse an attribute in PLatexObj.
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.
PLatexDate ptimetable_parsePLatexDate(const PString &str)
Load a PLatexDate with a string.

References PTimeTable::getLocation(), DicoValue::getMap(), PTimeTable::getName(), PTimeTable::getVecSpeaker(), parser_toml(), ptimetable_loadBlock(), ptimetable_loadSpeaker(), ptimetable_loadString(), ptimetable_parseLatexAttribute(), ptimetable_parsePLatexDate(), PTimeTable::setBeginDate(), PTimeTable::setEndDate(), PTimeTable::setInvitation(), and PTimeTable::setMainUrl().

Referenced by PConfigParser::parseTimeTable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ptimetable_loadBlock()

bool ptimetable_loadBlock ( PTimeTable timetable,
const DicoValue dico 
)

Load the blocks of the PTimeTable.

Parameters
[out]timetable: PTimeTable to be updated
dico: DicoValue of the PTimeTable configuration
Returns
true on success, false otherwise

Definition at line 110 of file ptimtable_load.cpp.

110  {
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 }
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
const std::vector< DicoValue > & getVecChild() const
Gets the vecChild of the DicoValue.
Definition: DicoValue.cpp:204
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
const std::vector< PTimeTableBlock > & getVecBlock() const
Gets the vecBlock of the PTimeTable.
Definition: PTimeTable.cpp:929
PLatexTime ptimetable_parsePLatexTime(const PString &str)
Load a PLatexTime with a string.

References eraseFirstLastChar(), PTimeTableBlock::getDescription(), PTimeTableBlock::getLocation(), DicoValue::getMap(), PTimeTableBlock::getTitle(), PTimeTable::getVecBlock(), DicoValue::getVecChild(), PTimeTableBlock::getWeekTitle(), ptimetable_loadString(), ptimetable_parseLatexAttribute(), ptimetable_parsePLatexDate(), ptimetable_parsePLatexTime(), PTimeTableBlock::setBeginTime(), PTimeTableBlock::setDate(), PTimeTableBlock::setDuration(), PTimeTableBlock::setInvitation(), PTimeTableBlock::setMainUrl(), PTimeTableBlock::setQuestionTime(), PTimeTableBlock::setStyle(), and PTimeTableBlock::setVecSpeaker().

Referenced by ptimetable_load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ptimetable_loadSpeaker() [1/2]

bool ptimetable_loadSpeaker ( std::vector< PLatexSpeaker > &  vecOutputSpeaker,
const DicoValue dico 
)

Load the speakers of the PTimeTable.

Parameters
[out]vecOutputSpeaker: vector of PLatexSpeaker to be updated
dico: DicoValue of the PTimeTable configuration
Returns
true on success, false otherwise

Definition at line 42 of file ptimtable_load.cpp.

42  {
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 }
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
Extends the std::string.
Definition: PString.h:16

References PLatexSpeaker::getAffiliation(), PLatexSpeaker::getDescription(), PLatexSpeaker::getJob(), DicoValue::getMap(), PLatexSpeaker::getName(), PLatexSpeaker::getTitle(), DicoValue::getVecChild(), ptimetable_loadString(), ptimetable_parseLatexAttribute(), and PLatexSpeaker::setLabel().

Referenced by PConfigParser::parseAddSpeaker(), ptimetable_load(), and ptimetable_loadSpeaker().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ptimetable_loadSpeaker() [2/2]

bool ptimetable_loadSpeaker ( std::vector< PLatexSpeaker > &  vecSpeaker,
const PPath configFile 
)

Load the PTimeTable with a toml configuration.

Parameters
[out]timetable: PTimeTable to be updated
configFile: configuration file to be used
Returns
true on success, false otherwise

Definition at line 140 of file ptimtable_load.cpp.

140  {
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 }

References parser_toml(), and ptimetable_loadSpeaker().

+ Here is the call graph for this function:

◆ ptimetable_loadString()

PString ptimetable_loadString ( const DicoValue dico,
const PString attributeName 
)

Load a string value.

Parameters
dico: DicoValue to be used
attributeName: name of the attribute to read
Returns
corresponding string

Definition at line 15 of file ptimtable_load.cpp.

15  {
16  return phoenix_load_value_from_config<PString>(dico, attributeName, "").eraseFirstLastChar("\"'\t\n ");
17 }

References PString::eraseFirstLastChar().

Referenced by ptimetable_load(), ptimetable_loadBlock(), ptimetable_loadSpeaker(), and ptimetable_parseLatexAttribute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ptimetable_parseLatexAttribute()

bool ptimetable_parseLatexAttribute ( PLatexObj obj,
const DicoValue value,
const PString attributeName 
)

Parse an attribute in PLatexObj.

Parameters
[out]obj: PLatexObj to be initialised
value: DicoValue with string to be parsed into obj
attributeName: name of the attribute to be parsed
Returns
true on success, false otherwise (or if the value is empty)

Definition at line 25 of file ptimtable_load.cpp.

25  {
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 }
bool platexobj_parseStr(PLatexObj &obj, const PString &latexStr)
Parse a str and convert it into a PLatexObj.

References platexobj_parseStr(), and ptimetable_loadString().

Referenced by ptimetable_load(), ptimetable_loadBlock(), and ptimetable_loadSpeaker().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ptimetable_parsePLatexDate()

PLatexDate ptimetable_parsePLatexDate ( const PString str)

Load a PLatexDate with a string.

Parameters
str: date in string
Returns
corresponding PLatexDate

Definition at line 73 of file ptimtable_load.cpp.

73  {
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 }
std::vector< PString > PVecString
Definition: PString.h:96
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
std::vector< PString > split(char separator) const
Cut a PString on the given separator char.
Definition: PString.cpp:420

References PLatexDate::setDay(), PLatexDate::setMonth(), PLatexDate::setYear(), and PString::split().

Referenced by ptimetable_load(), and ptimetable_loadBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ptimetable_parsePLatexTime()

PLatexTime ptimetable_parsePLatexTime ( const PString str)

Load a PLatexTime with a string.

Parameters
str: date in string
Returns
corresponding PLatexTime hour:minute or just minute

Definition at line 93 of file ptimtable_load.cpp.

93  {
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 }
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

References PLatexTime::setHour(), PLatexTime::setMinute(), and PString::split().

Referenced by ptimetable_loadBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: