CComponentsText: use separated function to get text fro a file

This commit is contained in:
2013-10-19 01:11:02 +02:00
parent 11d77c3030
commit a1e5a60184
2 changed files with 16 additions and 4 deletions

View File

@@ -199,8 +199,7 @@ void CComponentsText::setText(const int digit, const int mode, Font* font_text)
setText(s_digit, mode, font_text); setText(s_digit, mode, font_text);
} }
//set text lines directly from a file, returns true on succsess string CComponentsText::getTextFromFile(const string& path_to_textfile)
bool CComponentsText::setTextFromFile(const string& path_to_textfile, const int mode, Font* font_text)
{ {
string file = path_to_textfile; string file = path_to_textfile;
string txt = ""; string txt = "";
@@ -208,7 +207,7 @@ bool CComponentsText::setTextFromFile(const string& path_to_textfile, const int
ifstream in (file.c_str(), ios::in); ifstream in (file.c_str(), ios::in);
if (!in){ if (!in){
printf("[CComponentsText] [%s - %d] error while open %s -> %s\n", __FUNCTION__, __LINE__, file.c_str(), strerror(errno)); printf("[CComponentsText] [%s - %d] error while open %s -> %s\n", __FUNCTION__, __LINE__, file.c_str(), strerror(errno));
return false; return "";
} }
string line; string line;
@@ -217,6 +216,17 @@ bool CComponentsText::setTextFromFile(const string& path_to_textfile, const int
} }
in.close(); in.close();
return txt;
}
//set text lines directly from a file, returns true on succsess
bool CComponentsText::setTextFromFile(const string& path_to_textfile, const int mode, Font* font_text)
{
string txt = getTextFromFile(path_to_textfile);
if (txt.empty())
return false;
setText(txt, mode, font_text); setText(txt, mode, font_text);
return true; return true;

View File

@@ -118,6 +118,8 @@ class CComponentsText : public CComponentsItem, public CBox
virtual void setText(const int digit, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL); virtual void setText(const int digit, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL);
///set text directly from a textfile, path as string is required ///set text directly from a textfile, path as string is required
virtual bool setTextFromFile(const std::string& path_to_textfile, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL); virtual bool setTextFromFile(const std::string& path_to_textfile, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL);
///get text directly from a textfile, path as string is required
virtual std::string getTextFromFile(const std::string& path_to_textfile);
///helper to remove linebreak chars from a string if needed ///helper to remove linebreak chars from a string if needed
virtual void removeLineBreaks(std::string& str); virtual void removeLineBreaks(std::string& str);