PUMA Library Reference Manual
Loading...
Searching...
No Matches
Puma::Project Class Reference

#include <Puma/Project.h>

+ Inheritance diagram for Puma::Project:

Description

A project is a set of source directories.

It provides methods for searching and writing files.

Public Member Functions

 Project (ErrorStream &err)
 Constructor.
 
virtual ~Project ()
 Destructor.
 
void saveMode (Mode mode=OVERWRITE, const char *suffix=0)
 Set the mode for saving an unit.
 
virtual void save (Unit *unit, bool only_modified=false) const
 Save a unit using the name of the unit to get the full name of the file and path to save to.
 
virtual void save (const char *file=0, bool only_modified=false, bool is_reg_ex=false) const
 Save one, all or all matching files.
 
void print (const char *name=0, std::ostream &out=std::cout, bool is_reg_ex=false) const
 Print one, all or all matching units.
 
void close (const char *name=0, bool destroy=false, bool is_reg_ex=false) const
 Close one, all or all matching units.
 
UnitaddFile (Filename file)
 Add a new file to the project.
 
UnitaddFile (Filename srcFile, Filename destFile)
 Add a new file to the project.
 
virtual void configure (const Config &config)
 Configure the project from the command line or a file.
 
UnitManagerunitManager ()
 Get the unit manager.
 
bool isNewer (const char *file) const
 Check if the given file in the source directory or the unit is newer than the corresponding file in the destination directory.
 
virtual bool isBelow (const char *file) const
 Check if a given file is found below any of the source paths of this project.
 
virtual bool isBelow (Unit *file) const
 Check if a given file is found below any of the source paths of this project.
 
- Public Member Functions inherited from Puma::PathManager
 PathManager (ErrorStream &err)
 Constructor.
 
 PathManager (PathManager &other)
 Copy-constructor.
 
virtual ~PathManager ()
 Destructor.
 
void glob (char *filenamePattern=0)
 Search files in the managed path matching the given filename pattern or every file if no pattern is given.
 
bool iterate (PathIterator &iterator) const
 Iterate the contents of the managed paths.
 
virtual void addPath (const char *srcPath, const char *destPath=0)
 Add a source and destination paths pair.
 
ProjectFile::MapConstIter addFile (Filename filename)
 Add a new file to the project file list.
 
ProjectFile::MapConstIter addFile (Filename filename, Filename destPath)
 Add a new file to the project file list.
 
void setDest (const char *srcPath, const char *destPath)
 Set the destination path of the given source path.
 
void protect (const char *pathPattern)
 Add a pattern for a write-protected path.
 
long numPaths () const
 Get the number of managed paths.
 
long numProts () const
 Get the number of managed write-protected paths.
 
const char * src (long n) const
 Get the n-th managed source path.
 
const char * src_canon (long n) const
 Get canonical version of the n-th managed source path.
 
const char * dest (long n) const
 Get the n-th managed destination path.
 
RegCompprot (long n) const
 Get the n-th managed write-protected path pattern.
 
bool isProtected (const char *path) const
 Check if the given path is write-protected.
 
bool isBelow (const char *filename, ProjectFile::MapConstIter &iterator) const
 Check if a given file is directly managed by this path manager or is found below any of the managed paths.
 
virtual void join (PathManager &other)
 Join the paths of the given manager with the paths of this path manager.
 
ErrorStreamerr () const
 Get the error stream used by this path manager.
 
bool getDestinationPath (const char *sourcePath, std::ostream &out) const
 Get the destination path of a given source path and write it on the given output stream.
 

Protected Member Functions

virtual void write (Unit *unit, std::ofstream &file) const
 Write a unit on the given file output stream.
 
- Protected Member Functions inherited from Puma::PathManager
const char * getDestination (Filename sourcePath, std::ostream *destinationPath=0) const
 Get the destination path for a given source path.
 
virtual void action (PathIterator &iterator)
 Called for every matched file when traversing a source path.
 
char * addSeparator (const char *path) const
 Add the separator '/' to the end of the given path.
 
char * addSeparator (const char *path, char *buffer) const
 Add the separator '/' to the end of the given path and store the resulting path in the given buffer.
 

Additional Inherited Members

- Public Types inherited from Puma::SaveMode
enum  Mode {
  OVERWRITE = 1 ,
  RENAME_OLD ,
  NEW_SUFFIX
}
 Save modes. More...
 

Constructor & Destructor Documentation

◆ Project()

Puma::Project::Project ( ErrorStream & err)

Constructor.

Parameters
errAn error stream for reporting errors.

◆ ~Project()

virtual Puma::Project::~Project ( )
virtual

Destructor.

Member Function Documentation

◆ addFile() [1/2]

Unit * Puma::Project::addFile ( Filename file)

Add a new file to the project.

Parameters
fileThe path to the file to add.
Returns
An empty file unit for the file to add.

◆ addFile() [2/2]

Unit * Puma::Project::addFile ( Filename srcFile,
Filename destFile )

Add a new file to the project.

Parameters
srcFileThe path to the source file to add.
destFileThe path to the destination file.
Returns
An empty file unit for the file to add.

◆ close()

void Puma::Project::close ( const char * name = 0,
bool destroy = false,
bool is_reg_ex = false ) const

Close one, all or all matching units.

Parameters
nameOptional unit name or unit name pattern.
destroyIf true destroy the units when closed.
is_reg_exIf true the given unit name is a regular expression.

◆ configure()

virtual void Puma::Project::configure ( const Config & config)
virtual

Configure the project from the command line or a file.

Parameters
configThe configuration.

Reimplemented from Puma::PathManager.

◆ isBelow() [1/2]

bool Puma::Project::isBelow ( const char * file) const
inlinevirtual

Check if a given file is found below any of the source paths of this project.

Parameters
fileThe file.
Returns
True if the file was found.

Reimplemented from Puma::PathManager.

◆ isBelow() [2/2]

virtual bool Puma::Project::isBelow ( Unit * file) const
virtual

Check if a given file is found below any of the source paths of this project.

Parameters
fileThe file.
Returns
True if the file was found.

◆ isNewer()

bool Puma::Project::isNewer ( const char * file) const

Check if the given file in the source directory or the unit is newer than the corresponding file in the destination directory.

Parameters
fileThe path to the file.
Returns
True if destination file is older.

◆ print()

void Puma::Project::print ( const char * name = 0,
std::ostream & out = std::cout,
bool is_reg_ex = false ) const

Print one, all or all matching units.

Parameters
nameOptional unit name or unit name pattern.
outOutput stream on which to print the unit(s), defaults to std::cout.
is_reg_exIf true the given unit name is a regular expression.

◆ save() [1/2]

virtual void Puma::Project::save ( const char * file = 0,
bool only_modified = false,
bool is_reg_ex = false ) const
virtual

Save one, all or all matching files.

Parameters
fileOptional file name or file name pattern.
only_modifiedIf true only modified files are saved.
is_reg_exIf true the given filename is a regular expression.

◆ save() [2/2]

virtual void Puma::Project::save ( Unit * unit,
bool only_modified = false ) const
virtual

Save a unit using the name of the unit to get the full name of the file and path to save to.

The save location must not be protected by a protect pattern and the original file must be located in one of the source directories.

Parameters
unitThe unit to save.
only_modifiedIf true only modified units are saved.

◆ saveMode()

void Puma::Project::saveMode ( Mode mode = OVERWRITE,
const char * suffix = 0 )

Set the mode for saving an unit.

Mode OVERWRITE: Save the unit under its name and overwrite existing files. Mode RENAME_OLD: An existing file will be renamed. A suffix will be added to the name of the file, like 'main.cc.old' for the file 'main.cc' and the suffix '.old'. Mode NEW_SUFFIX: The unit will be saved with a new suffix, like 'main.cpp' for the unit 'main.cc' and the suffix 'cpp'.

Parameters
modeThe save mode.
suffixOptional filename suffix.

◆ unitManager()

UnitManager & Puma::Project::unitManager ( )
inline

Get the unit manager.

Returns
A reference to the unit manager.

◆ write()

virtual void Puma::Project::write ( Unit * unit,
std::ofstream & file ) const
protectedvirtual

Write a unit on the given file output stream.

Parameters
unitThe input unit.
fileThe output file.