FastFormat

FastFormat

infobox software
name = FastFormat C/C++ Formatting Library


caption =
latest_release_version = 0.2.1 (alpha 3)
latest_release_date = 12 September 2008
programming_language = C++
operating_system = Cross-platform
genre = Formatting
license = BSD-form license
website = [http://fastformat.org/ http://fastformat.org/]

FastFormat is an open source C++ formatting library, provided by Synesis Software, whose design focus is performance, robustness and transparency. It claims 100% type-safety, and extremely high efficiency.

FastFormat is completely free for use in both commercial and non-commercial activities, being licensed under the BSD license. It is platform-independent, working on UNIX (Linux, Solaris, FreeBSD), Mac OS X, and Windows (x86 and x64). It is compiler-independent, and is known to work with Borland, Metrowerks CodeWarrior, Comeau, Digital Mars, GCC, Intel and Microsoft Visual C++ compilers.

FastFormat provides both Format and Write APIs. It is infinitely extensible to allowing formatting of arbitrary argument types, with format strings of arbitrary types, to receivers, known as sinks, of arbitrary types.

Design Principles

The principles underpinning FastFormat arecite book
last = Wilson
first = Matthew
authorlink = Matthew Wilson
year = 2007
title = Extended STL
publisher = Addison-Wesley
id = ISBN 0-321-30550-7
] :
* the sinks, formats and arguments may be of arbitrary types
* any argument that must be converted into string form will be converted only once, regardless of how many times it is used in the resultant string
* the measurement (e.g. strlen()) and copying (e.g. memcpy()) of each argument is done only once

APIs

FastFormat has two APIs:
* The Format API comprises the fmt() and fmtln() function template suites
* The Write API comprises the write() and writeln() function template suites

Hello, World

Applying FastFormat to the classic Hello, World program gives the following examples:

;1. Using the Write API, with the ostream sink


#include // Primary include for the library
#include // Include the ostream sink
#include

int main(int argc, char** argv){ fastformat::writeln(std::cout, "Hello world");

return EXIT_SUCCESS;}

;2. Using the Write API, with the string sink


#include // Primary include for the library
#include

int main(int argc, char** argv){ std::string result; std::string hello("Hello"); std::string world("world");

fastformat::writeln(result, hello, " ", world);

return EXIT_SUCCESS;}

;3. Using the Format API, with the ostream sink


#include
#include
#include

int main(int argc, char** argv){ std::string hello("Hello"); char world [] = "world";

fastformat::fmtln(std::cout, "{1} {0}", world, hello); // Arbitrarily swapped the order

return EXIT_SUCCESS;}

;4. Using the Format API, with the string sink


#include

int main(int argc, char** argv){ std::string result;

std::string he("He"); std::string d("d"); std::string l("l"); std::string o("o"); std::string r("r"); std::string w("w");

fastformat::fmtln(result, "{0}{1}{1}{2} {3}{2}{4}{1}{5}", he, l, o, w, r, d);

return EXIT_SUCCESS;}

Dependencies

The library depends on the STLSoft C++ libraries.

References

External links

* [http://fastformat.org/ FastFormat Official Website]
* [http://stlsoft.org/ STLSoft Official Website]
* [http://stlsoft-musings.blogspot.com/ STLSoft Musings] Blog
* [news://news.digitalmars.com/c++.stlsoft STLSoft newsgroup]


Wikimedia Foundation. 2010.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • STLSoft C++ Libraries — infobox software name = STLSoft C++ Libraries caption = latest release version = 1.9.57 latest release date = release date|2008|10|10 programming language = C/C++ operating system = MS Windows, Unix, partially Cross platform genre = STL extension …   Wikipedia

  • Matthew Wilson (author) — Matthew Wilson is a software engineer and author. Specializing in C/C++, he may be best known for his time as columnist and contributing editor for C/C++ Users Journal, but has also written articles for a number of other publications, as well as… …   Wikipedia

  • Microsoft Speech API — This article is about the Speech API. For other uses, see SAPI (disambiguation). The Speech Application Programming Interface or SAPI is an API developed by Microsoft to allow the use of speech recognition and speech synthesis within Windows… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”