tomwalters@268: /** @mainpage
tomwalters@268:
tomwalters@268:
tomwalters@268: Library | SimpleIni
tomwalters@268: |
---|
File | SimpleIni.h
tomwalters@268: |
---|
Author | Brodie Thiesfield [code at jellycan dot com]
tomwalters@268: |
---|
Source | http://code.jellycan.com/simpleini/
tomwalters@330: |
---|
Version | 4.13
tomwalters@268: |
---|
tomwalters@268:
tomwalters@268: Jump to the @link CSimpleIniTempl CSimpleIni @endlink interface documentation.
tomwalters@268:
tomwalters@268: @section intro INTRODUCTION
tomwalters@268:
tomwalters@268: This component allows an INI-style configuration file to be used on both
tomwalters@268: Windows and Linux/Unix. It is fast, simple and source code using this
tomwalters@268: component will compile unchanged on either OS.
tomwalters@268:
tomwalters@268:
tomwalters@268: @section features FEATURES
tomwalters@268:
tomwalters@268: - MIT Licence allows free use in all software (including GPL and commercial)
tomwalters@268: - multi-platform (Windows 95/98/ME/NT/2K/XP/2003, Windows CE, Linux, Unix)
tomwalters@268: - loading and saving of INI-style configuration files
tomwalters@268: - configuration files can have any newline format on all platforms
tomwalters@268: - liberal acceptance of file format
tomwalters@268: - key/values with no section
tomwalters@268: - removal of whitespace around sections, keys and values
tomwalters@268: - support for multi-line values (values with embedded newline characters)
tomwalters@268: - optional support for multiple keys with the same name
tomwalters@268: - optional case-insensitive sections and keys (for ASCII characters only)
tomwalters@268: - saves files with sections and keys in the same order as they were loaded
tomwalters@268: - preserves comments on the file, section and keys where possible.
tomwalters@268: - supports both char or wchar_t programming interfaces
tomwalters@268: - supports both MBCS (system locale) and UTF-8 file encodings
tomwalters@268: - system locale does not need to be UTF-8 on Linux/Unix to load UTF-8 file
tomwalters@268: - support for non-ASCII characters in section, keys, values and comments
tomwalters@268: - support for non-standard character types or file encodings
tomwalters@268: via user-written converter classes
tomwalters@268: - support for adding/modifying values programmatically
tomwalters@268: - compiles cleanly in the following compilers:
tomwalters@268: - Windows/VC6 (warning level 3)
tomwalters@268: - Windows/VC.NET 2003 (warning level 4)
tomwalters@268: - Windows/VC 2005 (warning level 4)
tomwalters@268: - Linux/gcc (-Wall)
tomwalters@268:
tomwalters@268:
tomwalters@268: @section usage USAGE SUMMARY
tomwalters@268:
tomwalters@268: -# Define the appropriate symbol for the converter you wish to use and
tomwalters@268: include the SimpleIni.h header file. If no specific converter is defined
tomwalters@268: then the default converter is used. The default conversion mode uses
tomwalters@268: SI_CONVERT_WIN32 on Windows and SI_CONVERT_GENERIC on all other
tomwalters@268: platforms. If you are using ICU then SI_CONVERT_ICU is supported on all
tomwalters@268: platforms.
tomwalters@268: -# Declare an instance the appropriate class. Note that the following
tomwalters@268: definitions are just shortcuts for commonly used types. Other types
tomwalters@268: (PRUnichar, unsigned short, unsigned char) are also possible.
tomwalters@268:
tomwalters@268: Interface | Case-sensitive | Load UTF-8 | Load MBCS | Typedef
tomwalters@268: |
---|
SI_CONVERT_GENERIC
tomwalters@268: |
---|
char | No | Yes | Yes #1 | CSimpleIniA
tomwalters@268: |
char | Yes | Yes | Yes | CSimpleIniCaseA
tomwalters@268: |
wchar_t | No | Yes | Yes | CSimpleIniW
tomwalters@268: |
wchar_t | Yes | Yes | Yes | CSimpleIniCaseW
tomwalters@268: |
SI_CONVERT_WIN32
tomwalters@268: |
---|
char | No | No #2 | Yes | CSimpleIniA
tomwalters@268: |
char | Yes | Yes | Yes | CSimpleIniCaseA
tomwalters@268: |
wchar_t | No | Yes | Yes | CSimpleIniW
tomwalters@268: |
wchar_t | Yes | Yes | Yes | CSimpleIniCaseW
tomwalters@268: |
SI_CONVERT_ICU
tomwalters@268: |
---|
char | No | Yes | Yes | CSimpleIniA
tomwalters@268: |
char | Yes | Yes | Yes | CSimpleIniCaseA
tomwalters@268: |
UChar | No | Yes | Yes | CSimpleIniW
tomwalters@268: |
UChar | Yes | Yes | Yes | CSimpleIniCaseW
tomwalters@268: |
tomwalters@268: #1 On Windows you are better to use CSimpleIniA with SI_CONVERT_WIN32.
tomwalters@268: #2 Only affects Windows. On Windows this uses MBCS functions and
tomwalters@268: so may fold case incorrectly leading to uncertain results.
tomwalters@268: -# Call Load() or LoadFile() to load and parse the INI configuration file
tomwalters@268: -# Access and modify the data of the file using the following functions
tomwalters@268:
tomwalters@268: GetAllSections | Return all section names
tomwalters@268: |
GetAllKeys | Return all key names within a section
tomwalters@268: |
GetAllValues | Return all values within a section & key
tomwalters@268: |
GetSection | Return all key names and values in a section
tomwalters@268: |
GetSectionSize | Return the number of keys in a section
tomwalters@268: |
GetValue | Return a value for a section & key
tomwalters@268: |
SetValue | Add or update a value for a section & key
tomwalters@268: |
Delete | Remove a section, or a key from a section
tomwalters@268: |
tomwalters@268: -# Call Save() or SaveFile() to save the INI configuration data
tomwalters@268:
tomwalters@268: @section iostreams IO STREAMS
tomwalters@268:
tomwalters@268: SimpleIni supports reading from and writing to STL IO streams. Enable this
tomwalters@268: by defining SI_SUPPORT_IOSTREAMS before including the SimpleIni.h header
tomwalters@268: file. Ensure that if the streams are backed by a file (e.g. ifstream or
tomwalters@268: ofstream) then the flag ios_base::binary has been used when the file was
tomwalters@268: opened.
tomwalters@268:
tomwalters@268: @section multiline MULTI-LINE VALUES
tomwalters@268:
tomwalters@268: Values that span multiple lines are created using the following format.
tomwalters@268:
tomwalters@268:
tomwalters@268: key = <<
tomwalters@268:
tomwalters@268: Note the following:
tomwalters@268: - The text used for ENDTAG can be anything and is used to find
tomwalters@268: where the multi-line text ends.
tomwalters@268: - The newline after ENDTAG in the start tag, and the newline
tomwalters@268: before ENDTAG in the end tag is not included in the data value.
tomwalters@268: - The ending tag must be on it's own line with no whitespace before
tomwalters@268: or after it.
tomwalters@268: - The multi-line value is modified at load so that each line in the value
tomwalters@268: is delimited by a single '\\n' character on all platforms. At save time
tomwalters@268: it will be converted into the newline format used by the current
tomwalters@268: platform.
tomwalters@268:
tomwalters@268: @section comments COMMENTS
tomwalters@268:
tomwalters@268: Comments are preserved in the file within the following restrictions:
tomwalters@268: - Every file may have a single "file comment". It must start with the
tomwalters@268: first character in the file, and will end with the first non-comment
tomwalters@268: line in the file.
tomwalters@268: - Every section may have a single "section comment". It will start
tomwalters@268: with the first comment line following the file comment, or the last
tomwalters@268: data entry. It ends at the beginning of the section.
tomwalters@268: - Every key may have a single "key comment". This comment will start
tomwalters@268: with the first comment line following the section start, or the file
tomwalters@268: comment if there is no section name.
tomwalters@268: - Comments are set at the time that the file, section or key is first
tomwalters@268: created. The only way to modify a comment on a section or a key is to
tomwalters@268: delete that entry and recreate it with the new comment. There is no
tomwalters@268: way to change the file comment.
tomwalters@268:
tomwalters@268: @section save SAVE ORDER
tomwalters@268:
tomwalters@268: The sections and keys are written out in the same order as they were
tomwalters@268: read in from the file. Sections and keys added to the data after the
tomwalters@268: file has been loaded will be added to the end of the file when it is
tomwalters@268: written. There is no way to specify the location of a section or key
tomwalters@268: other than in first-created, first-saved order.
tomwalters@268:
tomwalters@268: @section notes NOTES
tomwalters@268:
tomwalters@268: - To load UTF-8 data on Windows 95, you need to use Microsoft Layer for
tomwalters@268: Unicode, or SI_CONVERT_GENERIC, or SI_CONVERT_ICU.
tomwalters@268: - When using SI_CONVERT_GENERIC, ConvertUTF.c must be compiled and linked.
tomwalters@268: - When using SI_CONVERT_ICU, ICU header files must be on the include
tomwalters@268: path and icuuc.lib must be linked in.
tomwalters@268: - To load a UTF-8 file on Windows AND expose it with SI_CHAR == char,
tomwalters@268: you should use SI_CONVERT_GENERIC.
tomwalters@268: - The collation (sorting) order used for sections and keys returned from
tomwalters@268: iterators is NOT DEFINED. If collation order of the text is important
tomwalters@268: then it should be done yourself by either supplying a replacement
tomwalters@268: SI_STRLESS class, or by sorting the strings external to this library.
tomwalters@268: - Usage of the header on Windows can be disabled by defining
tomwalters@268: SI_NO_MBCS. This is defined automatically on Windows CE platforms.
tomwalters@268:
tomwalters@268:
tomwalters@268: @section licence MIT LICENCE
tomwalters@268:
tomwalters@268: The licence text below is the boilerplate "MIT Licence" used from:
tomwalters@268: http://www.opensource.org/licenses/mit-license.php
tomwalters@268:
tomwalters@268: Copyright (c) 2006-2008, Brodie Thiesfield
tomwalters@268:
tomwalters@268: Permission is hereby granted, free of charge, to any person obtaining a copy
tomwalters@268: of this software and associated documentation files (the "Software"), to deal
tomwalters@268: in the Software without restriction, including without limitation the rights
tomwalters@268: to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
tomwalters@268: copies of the Software, and to permit persons to whom the Software is furnished
tomwalters@268: to do so, subject to the following conditions:
tomwalters@268:
tomwalters@268: The above copyright notice and this permission notice shall be included in
tomwalters@268: all copies or substantial portions of the Software.
tomwalters@268:
tomwalters@268: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
tomwalters@268: IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
tomwalters@268: FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
tomwalters@268: COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
tomwalters@268: IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
tomwalters@268: CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
tomwalters@268: */
tomwalters@268:
tomwalters@268: #ifndef INCLUDED_SimpleIni_h
tomwalters@268: #define INCLUDED_SimpleIni_h
tomwalters@268:
tomwalters@268: #if defined(_MSC_VER) && (_MSC_VER >= 1020)
tomwalters@268: # pragma once
tomwalters@268: #endif
tomwalters@268:
tomwalters@268: // Disable these warnings in MSVC:
tomwalters@268: // 4127 "conditional expression is constant" as the conversion classes trigger
tomwalters@268: // it with the statement if (sizeof(SI_CHAR) == sizeof(char)). This test will
tomwalters@268: // be optimized away in a release build.
tomwalters@268: // 4503 'insert' : decorated name length exceeded, name was truncated
tomwalters@268: // 4702 "unreachable code" as the MS STL header causes it in release mode.
tomwalters@268: // Again, the code causing the warning will be cleaned up by the compiler.
tomwalters@268: // 4786 "identifier truncated to 256 characters" as this is thrown hundreds
tomwalters@268: // of times VC6 as soon as STL is used.
tomwalters@268: #ifdef _MSC_VER
tomwalters@268: # pragma warning (push)
tomwalters@268: # pragma warning (disable: 4127 4503 4702 4786)
tomwalters@268: #endif
tomwalters@268:
tomwalters@268: #include
tomwalters@268: #include
tomwalters@268: #include