db41258d16
Ersetzt das Geruest (counter/notebook) durch ein echtes Beispiel und teilt es in zwei eigenstaendige Projekte, wie P1204R0 es fuer Bibliothek plus Programm verlangt. libpda: textfile (C, Datei-I/O und Feld-Escaping), calculator (Recursive-Descent-Parser mit std::expected), contact, editor, explorer. Exportiert pda::pda ueber install(EXPORT) und ist per find_package(pda) benutzbar. pda: Shell ohne Ein-/Ausgabe (execute() gibt Text zurueck, deshalb ohne Terminal testbar), REPL und Stapelbetrieb in main.cpp. examples/consumer und tools/check-install.sh pruefen die Export-Kette Ende-zu-Ende: installieren, dann ein fremdes Projekt dagegen bauen. docs/CMAKE.md erklaert das Target-Modell, PUBLIC/PRIVATE/INTERFACE, Generator-Ausdruecke, install/export und Symbolsichtbarkeit an diesem Projekt. 71 Tests gruen unter Homebrew-clang 22, Apple clang und GCC 16, statisch und shared, mit und ohne ASan/UBSan. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
40 lines
1.0 KiB
C++
40 lines
1.0 KiB
C++
/* examples/consumer/main.cpp
|
|
* Ein fremdes Programm, das libpda benutzt.
|
|
*
|
|
* Es kennt das Projekt nicht -- nur das installierte Paket. Die Includes
|
|
* sehen deshalb genauso aus wie bei jedem anderen Benutzer, und es gibt keine
|
|
* relativen Pfade irgendwohin.
|
|
*/
|
|
#include <cstdio>
|
|
#include <string>
|
|
|
|
#include <libpda/calculator.hpp>
|
|
#include <libpda/contact.hpp>
|
|
#include <libpda/editor.hpp>
|
|
|
|
int
|
|
main()
|
|
{
|
|
/* Rechner */
|
|
const auto value = pda::evaluate("(1 + 2) * 3 ^ 2");
|
|
if (!value)
|
|
{
|
|
std::fprintf(stderr, "consumer: %s\n", pda::format_error(value.error()).c_str());
|
|
return 1;
|
|
}
|
|
|
|
std::printf("(1 + 2) * 3 ^ 2 = %g\n", *value);
|
|
|
|
/* Kontakte */
|
|
pda::ContactBook book;
|
|
book.add(pda::Contact{"Anna", "0151", "anna@example.org", "Test"});
|
|
std::printf("Kontakte: %zu\n", book.size());
|
|
|
|
/* Notizen */
|
|
pda::TextBuffer notes;
|
|
notes.append("libpda laeuft aus einem fremden Projekt");
|
|
std::printf("Notiz: %s\n", std::string{*notes.line(1U)}.c_str());
|
|
|
|
return *value == 27.0 ? 0 : 1;
|
|
}
|