ot::OTQtConfigFileEditor Class Reference
[OTQt Classes]
Simple line-based file editor.
More...
#include <OTQtConfigFileEditor.h>
Public Types | |
| typedef std::list< std::string > | LineList |
| typedef LineList::iterator | LineIterator |
| typedef LineList::const_iterator | ConstLineIterator |
Public Member Functions | |
| OTQtConfigFileEditor (std::string &input_filename) | |
| ~OTQtConfigFileEditor () | |
| OTQtConfigFileEditor (OTQtConfigFileEditor const &ref) | |
| void | init () |
| bool | isInitialized () const |
| bool | containsExpr (std::string expr) const |
| int | firstLineNoOfExpr (std::string expr, int start_index=0) const |
| int | countOfExpr (std::string expr) const |
| bool | insertLines (int index_at, LineList &ins_lines, int num_indent_spaces=0) |
| bool | killLine (int index) |
| void | writeToStdOut () const |
| void | writeToFile (std::string const &output_filename) const |
| int | getLineCount () const |
| std::string const & | getLine (int index) const |
Private Member Functions | |
| OTQtConfigFileEditor () | |
| OTQtConfigFileEditor | operator= (OTQtConfigFileEditor const &ref) |
| void | import () |
Private Attributes | |
| bool | is_initialized_ |
| std::string | input_filename_ |
| LineList | lines_ |
Detailed Description
Simple line-based file editor.Provides some methods to query, manipulate and output an imported file on line-basis. The existance and count of string expressions can be queried with methods such as countOfExpr(). Lines of text can be killed with the killLine() method or inserted with insertLines() method at specified line index.
An object is first created specifying a file name in the constructor. Next, the object must be initialized calling the init() method. Within this method the refered file contents are imported to an interal list of lines. This list of lines can then be edited with the methods mentioned above and finally printed to standard output stream or another destination file location with methods such as writeToFile().
Definition at line 72 of file OTQtConfigFileEditor.h.
Member Typedef Documentation
| typedef LineList::const_iterator ot::OTQtConfigFileEditor::ConstLineIterator |
| typedef LineList::iterator ot::OTQtConfigFileEditor::LineIterator |
| typedef std::list<std::string> ot::OTQtConfigFileEditor::LineList |
Constructor & Destructor Documentation
| ot::OTQtConfigFileEditor::OTQtConfigFileEditor | ( | std::string & | input_filename | ) |
Stores the given input file name.
Returns object in state not initialized (file contexts are not imported).
- Parameters:
-
input_filename input XML configuration file name
Definition at line 55 of file OTQtConfigFileEditor.cxx.
| ot::OTQtConfigFileEditor::~OTQtConfigFileEditor | ( | ) |
Clears the file line container datastructure.
Definition at line 62 of file OTQtConfigFileEditor.cxx.
References lines_.
| ot::OTQtConfigFileEditor::OTQtConfigFileEditor | ( | OTQtConfigFileEditor const & | ref | ) |
Returns a copy of the given object.
- Parameters:
-
ref copy object
Definition at line 69 of file OTQtConfigFileEditor.cxx.
| ot::OTQtConfigFileEditor::OTQtConfigFileEditor | ( | ) | [private] |
Member Function Documentation
| bool ot::OTQtConfigFileEditor::containsExpr | ( | std::string | expr | ) | const |
Returns true if given expression is contained in the imported file.
- Parameters:
-
expr arbitrary string expressing
- Returns:
- true if expression is contained in imported file
Definition at line 132 of file OTQtConfigFileEditor.cxx.
References firstLineNoOfExpr().
Referenced by ot::OTQtMEMCalibProc::isInputConfigFileValid().
| int ot::OTQtConfigFileEditor::countOfExpr | ( | std::string | expr | ) | const |
Returns number of lines containing the given expression within the imported file.
- Parameters:
-
expr arbitrary string expression
- Returns:
- number of lines containing the given expression
Definition at line 109 of file OTQtConfigFileEditor.cxx.
References lines_.
| int ot::OTQtConfigFileEditor::firstLineNoOfExpr | ( | std::string | expr, | |
| int | start_index = 0 | |||
| ) | const |
Returns the line number of the first occurrence of given expression within imported file.
Starts search at given line number.
- Parameters:
-
expr arbitrary string expression start_index search start index: 0 <= index <= number of lines - 1
- Returns:
- line number of first occurrence
Definition at line 119 of file OTQtConfigFileEditor.cxx.
References lines_.
Referenced by containsExpr(), and ot::OTQtMEMCalibProc::exec().
| std::string const & ot::OTQtConfigFileEditor::getLine | ( | int | index | ) | const |
Returns the text line stored at the given index in the interal list of lines.
- Parameters:
-
index line index: 0 <= index <= number of lines - 1
- Returns:
- text line
Definition at line 137 of file OTQtConfigFileEditor.cxx.
References getLineCount(), and lines_.
| int ot::OTQtConfigFileEditor::getLineCount | ( | ) | const [inline] |
Returns the current number of lines stored in the internal list of lines.
- Returns:
- number of text lines
Definition at line 175 of file OTQtConfigFileEditor.h.
Referenced by getLine().
| void ot::OTQtConfigFileEditor::import | ( | ) | [private] |
Imports file refered to by previously set filename.
Reads line after line storing each line in a dedicated line container datastructure. Throws an exception on failure (file does not exist, is not readable, etc).
Definition at line 84 of file OTQtConfigFileEditor.cxx.
References input_filename_, and lines_.
| void ot::OTQtConfigFileEditor::init | ( | ) |
Initializes the object.
Imports the file contents refered to by the previously set filename. Switches state to initialized. Throws an exception if import fails (eg file does not exist, is not readable etc).
Definition at line 77 of file OTQtConfigFileEditor.cxx.
References is_initialized_.
Referenced by ot::OTQtMEMCalibProc::exec().
| bool ot::OTQtConfigFileEditor::insertLines | ( | int | index_at, | |
| LineList & | ins_lines, | |||
| int | num_indent_spaces = 0 | |||
| ) |
Inserts given lines of text into the internal list of lines, starting before (!) given line index (eg index equal zero, then the lines are inserted before the first line).
The optional indent argument (default value equal zero) defines the number of additional spaces prepended each inserted line. Returns true if operation was successful. Otherwise returns false (eg if given index is out of bounds).
- Parameters:
-
index_at insert start line index: 0 <= index <= number of lines - 1 ins_lines lines to insert num_indent_spaces optional number of additional spaces prepended to each line
- Returns:
- true if insert opertion successful
Definition at line 168 of file OTQtConfigFileEditor.cxx.
References lines_.
Referenced by ot::OTQtMEMCalibProc::exec().
| bool ot::OTQtConfigFileEditor::isInitialized | ( | ) | const [inline] |
Returns true if input file has been sucessfully imported (equals object which is in initialized state).
- Returns:
- true if input file successfully imported
Definition at line 116 of file OTQtConfigFileEditor.h.
| bool ot::OTQtConfigFileEditor::killLine | ( | int | index | ) |
Kills the line at given index from the interal list of lines.
Returns true if operation was successful, otherwise returns false (eg if given index is out of bounds).
- Parameters:
-
index line index: 0 <= index <= number of lines - 1
- Returns:
- true if kill opertion successful
Definition at line 153 of file OTQtConfigFileEditor.cxx.
References lines_.
Referenced by ot::OTQtMEMCalibProc::exec().
| OTQtConfigFileEditor ot::OTQtConfigFileEditor::operator= | ( | OTQtConfigFileEditor const & | ref | ) | [private] |
| void ot::OTQtConfigFileEditor::writeToFile | ( | std::string const & | output_filename | ) | const |
Writes the current list of lines contents to a file specifed by the given name.
Throws an exception in case of failur (file cannot be opened for writing etc).
Definition at line 218 of file OTQtConfigFileEditor.cxx.
References lines_.
Referenced by ot::OTQtMEMCalibProc::exec().
| void ot::OTQtConfigFileEditor::writeToStdOut | ( | ) | const |
Writes the current list of lines contents to standard output.
Definition at line 205 of file OTQtConfigFileEditor.cxx.
References lines_.
Referenced by ot::OTQtMEMCalibProc::exec().
Member Data Documentation
std::string ot::OTQtConfigFileEditor::input_filename_ [private] |
bool ot::OTQtConfigFileEditor::is_initialized_ [private] |
object initialized state (true if file was imported successfully)
Definition at line 194 of file OTQtConfigFileEditor.h.
Referenced by init().
LineList ot::OTQtConfigFileEditor::lines_ [private] |
file line container
Definition at line 198 of file OTQtConfigFileEditor.h.
Referenced by countOfExpr(), firstLineNoOfExpr(), getLine(), import(), insertLines(), killLine(), writeToFile(), writeToStdOut(), and ~OTQtConfigFileEditor().
The documentation for this class was generated from the following files: