FILELIST
Classes
- vorlib::filelist
- vorlib::filelist_e (exception)
Files
You can use this if you don't want to have all file names hardcoded into your program. You can load them at the startup from single file (see file format below). It also can make absolute paths of relatives and can conver slashes while loading.
Sections and files
What mean now? Every file has it's name and files are divided into sections. In every section can be just one file with every name, but in different sections can be files with identical names. Both name and section are of std::string type.
Interface
-
load
list.load(filename, conversion) loads file "filename" as a list of files, but does not clear the list before the loading, so you can put more files together. Conversion is of int type and specify, how to convert slashes. 0 does not change anything, 1 converts standard slashes to backslashes and 2 the other way. This can be used for easier porting to other system, you don't need to rewrite your whole list.
-
clear
Forgets all files it actually remembers.
-
getpath
This returns std::string containing path to file specified by section and name. list.getpath(section, name).
-
getsection
This returns vorlib::stringlist of all file paths from given section. Call: list.getsection(section).
-
basepath
This std::string variable is used to make absolute path of relative. Just place there path to the starting path (like you app's) and it will be combined every time you ask for file. This mean it will be combined with actual content of this var.
File format
The file containing file list has its own format, quite similar to ini files. Lines starting with # are comments, lines looking like [this] are starts of section, with the section name inside the square brackets. The last type is file containing line. It starts with name of file folowed by one space and continuing by the path. However, be carefull, that there may be no spaces at the end, because, under Linux (and other Unix systems), files can end with spaces and it would be considered as a part of the path.
Error handling
Error handling is done like in whole vorlib. (see exception) The exception class is filelist_e. Codes are theese:
- 1: Source file not found. It means that you provided wrong file name while to "load" function, or the file was deleted.
- 2: Spurce file not closed. This means that there occured some serious error in the system and the file could not be closed. This usually means that there's not enough space on disk while writing, however, the file was opened only for reading. This should newer happen on a well made system.
- 3: Section duplicated. This means that the file you are loading has some section twice, or this is not the first file you are loading and some previous file had same section as has this one.
- 4: ] missing on the section-line. This means that some files begins with [, but does not end with ] and it is considered a syntax error
- 5: Space missing after file name. This means that there is no space on the line and therefore, it couldn't be divided into name and path. It is syntax error.
- 6: Path missing. This means that on some line is name of file, space, and it ends. It is syntax error.
- 7: Path specified outside section. This means that there is path before the [section] line was found. Each file must be in some section. Syntax error.
- 8: File name duplicated. This means that some section has two files with the same name.
- 9: Section or file name not found. It is when you request section or file (in the getpath or getsection) that does not exist inside any of loaded files.
- 10: Base path does not have enough slashes. This means that the relative path contains more "../" (steps up in the tree) than is inside the basepath variable.
- 11: Empty path. You requested file that has empty path. This should never happen, it is self-check inside.