LibPkg
Classes | Public Member Functions | Protected Member Functions | List of all members
pkg::boot_options_file Class Referenceabstract

Base class to manipulate the RISC OS boot options files in Choices. More...

#include <boot_options_file.h>

Inheritance diagram for pkg::boot_options_file:
pkg::add_to_apps_options pkg::look_at_options pkg::run_options

Classes

class  commit_error
 An exception class for reporting failure to commit a boot options file. More...
 

Public Member Functions

 boot_options_file (const char *file_name, const char *section_prefix, const char *section_version, const char *section_suffix, const char *command, const char *command2=0)
 Construct boot_options_file object by setting parameters for the options file it will edit. More...
 
virtual ~boot_options_file ()
 
void rollback ()
 Discard any changes and reload the file. More...
 
void commit ()
 Commit any changes to the file. More...
 
bool contains (const std::string &app) const
 Check if application is contained in the look ups. More...
 
bool add (const std::string &app)
 Add application to up section. More...
 
bool remove (const std::string &app)
 Remove application from section. More...
 
bool replace (const std::string &was_app, const std::string &app)
 Replace an application. More...
 
const std::string & read_pathname () const
 The path name to the location of the PreDesk file that contains the look at declarations for reading. More...
 
const std::string & write_pathname () const
 The path name to the location of the PreDesk file that any changes to the look at declarations will be written to. More...
 
void use_test_pathname (const std::string &pathname)
 Change the path name for read or write. More...
 
bool has_section () const
 See if file has the section defined. More...
 
bool modified () const
 
bool contains_raw (const std::string &app) const
 Check if exact name is contained in the look ups. More...
 
void dump_apps () const
 Dump apps array to cout - debugging helper. More...
 

Protected Member Functions

virtual char * find_insert_section ()=0
 
char * find_section (const char *name, const char *suffix)
 Find section in the file. More...
 
void parse_section ()
 Parse section we are interested into C++ structures. More...
 
bool parse_word (char *&pos, std::string &word) const
 Parse a single word from the given location. More...
 
char * find_section_end (char *section) const
 Find the end of the section. More...
 
char * next_line (char *line) const
 Return adress of start of next line. More...
 
std::string name_in_section (const std::string &app) const
 Generate the name used in the file. More...
 

Detailed Description

Base class to manipulate the RISC OS boot options files in Choices.

Constructor & Destructor Documentation

pkg::boot_options_file::boot_options_file ( const char *  file_name,
const char *  section_prefix,
const char *  section_version,
const char *  section_suffix,
const char *  command,
const char *  command2 = 0 
)

Construct boot_options_file object by setting parameters for the options file it will edit.

Parameters
file_nameChoices file name to be updated
section_prefixprefix for section title
section_versionsection version
section_suffixsuffix for section title
commandcommand to write to section
command2optional second command for section

References rollback().

pkg::boot_options_file::~boot_options_file ( )
virtual

Member Function Documentation

void pkg::boot_options_file::rollback ( )

Discard any changes and reload the file.

Exceptions
std::runtime_errorif it fails to open the file

References parse_section().

Referenced by boot_options_file().

void pkg::boot_options_file::commit ( )

Commit any changes to the file.

Does nothing if no modifications have been made

Exceptions
std::ios_base::failureif commit fails to write the file

References pkg::create_directory(), dst_pathname, find_insert_section(), find_section_end(), pkg::force_delete(), pkg::force_move(), next_line(), pkg::object_type(), and pkg::write_filetype().

Referenced by pkg::commit::poll().

bool pkg::boot_options_file::contains ( const std::string &  app) const

Check if application is contained in the look ups.

Parameters
appapplication to check
Returns
true if application is contained in the look ups

References name_in_section().

bool pkg::boot_options_file::add ( const std::string &  app)

Add application to up section.

Parameters
appname of application to add
Returns
true if app was added, false if it's already there.

References name_in_section().

Referenced by pkg::commit::poll().

bool pkg::boot_options_file::remove ( const std::string &  app)

Remove application from section.

Parameters
appname of application to remove
Returns
true if application was found and removed

References name_in_section().

Referenced by pkg::commit::poll().

bool pkg::boot_options_file::replace ( const std::string &  was_app,
const std::string &  app 
)

Replace an application.

Parameters
was_appapplication to replace
appapplication to replace it with
Returns
true if the replace was done

References name_in_section().

const std::string& pkg::boot_options_file::read_pathname ( ) const
inline

The path name to the location of the PreDesk file that contains the look at declarations for reading.

const std::string& pkg::boot_options_file::write_pathname ( ) const
inline

The path name to the location of the PreDesk file that any changes to the look at declarations will be written to.

void pkg::boot_options_file::use_test_pathname ( const std::string &  pathname)

Change the path name for read or write.

This method is for unit testing and would not normally be used. call rollback() to read the test file after this method.

bool pkg::boot_options_file::has_section ( ) const

See if file has the section defined.

bool pkg::boot_options_file::modified ( ) const
inline
bool pkg::boot_options_file::contains_raw ( const std::string &  app) const

Check if exact name is contained in the look ups.

Used for Unit testing to check that entries of format "Boot:^..."

Parameters
appapplication to check (is not standardized)
Returns
true if application is contained in the look ups
void pkg::boot_options_file::dump_apps ( ) const

Dump apps array to cout - debugging helper.

virtual char* pkg::boot_options_file::find_insert_section ( )
protectedpure virtual
char * pkg::boot_options_file::find_section ( const char *  name,
const char *  suffix 
)
protected

Find section in the file.

Section format is |Start <name> <version> <suffix> where <version> is of form n.nn

Parameters
namename of section
suffixsuffix name of section
Returns
pointer to start of section or 0 if not found

Referenced by pkg::look_at_options::find_insert_section(), pkg::run_options::find_insert_section(), pkg::add_to_apps_options::find_insert_section(), and parse_section().

void pkg::boot_options_file::parse_section ( )
protected

Parse section we are interested into C++ structures.

References find_section(), and parse_word().

Referenced by rollback().

bool pkg::boot_options_file::parse_word ( char *&  pos,
std::string &  word 
) const
protected

Parse a single word from the given location.

Skips spaces, then a word is defined until the next space, char 0 or line feed.

Parameters
poslocation to start parsing - updated to position of character after word
wordparsed out (empty if at end of line)
Returns
true if a word is found.

Referenced by parse_section().

char * pkg::boot_options_file::find_section_end ( char *  section) const
protected

Find the end of the section.

Parameters
sectionlocation in section to find
Returns
section end or 0 if not found

Referenced by commit().

char * pkg::boot_options_file::next_line ( char *  line) const
protected

Return adress of start of next line.

Parameters
lineline to find next line for
Returns
start of next line

Referenced by commit().

std::string pkg::boot_options_file::name_in_section ( const std::string &  app) const
protected

Generate the name used in the file.

This usually involves replacing the start with Boot:^ if it's on the boot drive

Parameters
appname of application
Returns
name that will be stored in the file

References pkg::canonicalise().

Referenced by add(), contains(), remove(), and replace().


The documentation for this class was generated from the following files:

Reference Manual LibPkg Version 0.6.1 (28 Jan 2015)