Source-highlight Library
Public Types | Public Member Functions | Private Types | Private Attributes | List of all members
srchilite::LangMap Class Reference

A map stored in a file with the format key = elem. More...

#include <langmap.h>

Collaboration diagram for srchilite::LangMap:
Collaboration graph
[legend]

Public Types

typedef Map::const_iterator  const_iterator
 

Public Member Functions

  LangMap (const std::string &path, const std::string &filename)
  A LangMap object based on the passed map file (using the specified path). More...
 
  LangMap (const std::string &filename)
  A LangMap object based on the passed map file (using the path stored in the settings or the default hardcoded one). More...
 
const_iterator  begin ()
 
const_iterator  end ()
 
void  print ()
  Prints the contents on the map to the standard output. More...
 
void  open ()
  Open the corresponding file (if it is not already opened) and read and parse its contents. More...
 
const std::string  getFileName (const std::string &lang)
  Returns the lang file name corresponding to the passed language name. More...
 
const std::string  getMappedFileName (const std::string &lang)
  Returns the lang file name corresponding to the passed language name. More...
 
const std::string  getMappedFileNameFromFileName (const std::string &fileName)
  Tries to detect the corresponding lang file name, from the file name passed as parameter. More...
 
std::set< std::string >  getLangNames () const
  Returns a set (i.e., an ordered list) of all the lang names of this map. More...
 
std::set< std::string >  getMappedFileNames () const
  Returns a set (i.e., an ordered list) of all the mapped lang file names of this map. More...
 
void  reload (const std::string &path, const std::string &filename)
  Reloads the contents of this map, using the (new) path and filename. More...
 

Private Types

typedef std::map< std::string,
std::string >  Map
 

Private Attributes

Map  langmap
 
bool  isOpen
  whether the corresponding file is opened
 
std::string  path
  the path for searching for the map file name
 
std::string  filename
  the map file name
 

Detailed Description

A map stored in a file with the format key = elem.

Comment line start with a #

This is used for lang.map, outlang.map and style.defaults (and for any other files that have this simple syntax).

Methods of this class can throw ParserException if they can't parse the map file because of a syntax error.

Constructor & Destructor Documentation

srchilite::LangMap::LangMap ( const std::string &  path,
const std::string &  filename 
)

A LangMap object based on the passed map file (using the specified path).

Parameters
path the path where to search for the filename
filename the map file
srchilite::LangMap::LangMap ( const std::string &  filename )

A LangMap object based on the passed map file (using the path stored in the settings or the default hardcoded one).

Parameters
filename the map file

Member Function Documentation

const std::string srchilite::LangMap::getFileName ( const std::string &  lang )
inline

Returns the lang file name corresponding to the passed language name.

The lang map file must have already been opened (if you want to be sure of that, use getMappedFileName instead).

Parameters
lang the language name whose lang definition file name we want to retrieve
Returns
the file name of the lang definition file corresponding to the specified language (or the empty string if there's no such association)
set< string > srchilite::LangMap::getLangNames ( ) const

Returns a set (i.e., an ordered list) of all the lang names of this map.

Returns
the lang names of this map
const std::string srchilite::LangMap::getMappedFileName ( const std::string &  lang )

Returns the lang file name corresponding to the passed language name.

The lang map file is opened and parsed if it has not been inspected yet.

Parameters
lang the language name whose lang definition file name we want to retrieve
Returns
the file name of the lang definition file corresponding to the specified language (or the empty string if there's no such association)
Exceptions
ParserException in case the lang map file is not correct.
const std::string srchilite::LangMap::getMappedFileNameFromFileName ( const std::string &  fileName )

Tries to detect the corresponding lang file name, from the file name passed as parameter.

In order to do so it proceeds as follows (until it succeeds):

  1. Use the file extension if any (for instance, if the passed file name is foo.cpp it looks for the lang def file associated to cpp)
  2. Use the lower case file extension if any
  3. Use the file name if it has no extension (for instance, if the passed file name is changelog, then looks for the lang file associated to changelog)
  4. Use the file name in lowercase (for instance, if the passed file name is ChangeLog, then looks for the lang file to changelog)

This is useful, e.g., for highlighting a file using its file name for detecting its source language. Similarly, for choosing the output format by using the name of the output file.

This method opens the lang map file if it hasn't been parsed yet.

Parameters
fileName the language name whose lang definition file name we want to retrieve
Returns
the file name of the lang definition file corresponding to the specified file name (or the empty string if there's no such association)
Exceptions
ParserException in case the lang map file is not correct.
std::set< std::string > srchilite::LangMap::getMappedFileNames ( ) const

Returns a set (i.e., an ordered list) of all the mapped lang file names of this map.

Returns
the lang file names of this map
void srchilite::LangMap::open ( )

Open the corresponding file (if it is not already opened) and read and parse its contents.

If the map file has been already opened (and parsed) this does nothing.

Exceptions
ParserException in case the lang map file is not correct.
void srchilite::LangMap::print ( )

Prints the contents on the map to the standard output.

This is basically for testing purposes.

void srchilite::LangMap::reload ( const std::string &  path,
const std::string &  filename 
)

Reloads the contents of this map, using the (new) path and filename.

Parameters
path the path where to search for the filename
filename the map file

The documentation for this class was generated from the following files:
  • /home/bettini/work/source-highlight/src-highlite/lib/srchilite/langmap.h
  • /home/bettini/work/source-highlight/src-highlite/lib/srchilite/langmap.cpp

AltStyle によって変換されたページ (->オリジナル) /