Menu

Tree [7c046e] main v2.0.9 /
 History

HTTPS access


File Date Author Commit
 unittest 2023-03-23 Antti Jääskeläinen Antti Jääskeläinen [7c046e] general: minor fixes
 .clang-format 2022-09-11 A.J. Jääskeläinen A.J. Jääskeläinen [7e2fc1] ring_buffer: rename and partial rewrite, unit t...
 .gitignore 2022-07-17 A.J. Jääskeläinen A.J. Jääskeläinen [21ca49] build: Add 32bit cross compile (draft)
 Disclaimer of Warranty.txt 2022-07-06 A.J. Jääskeläinen A.J. Jääskeläinen [f0b1da] Cpp4Scripts version 2 - initial revision
 Doxyfile 2022-09-11 A.J. Jääskeläinen A.J. Jääskeläinen [7e2fc1] ring_buffer: rename and partial rewrite, unit t...
 LICENSE 2022-07-06 A.J. Jääskeläinen A.J. Jääskeläinen [f0b1da] Cpp4Scripts version 2 - initial revision
 README.md 2022-07-06 A.J. Jääskeläinen A.J. Jääskeläinen [f0b1da] Cpp4Scripts version 2 - initial revision
 build.cxx 2023-03-23 Antti Jääskeläinen Antti Jääskeläinen [7c046e] general: minor fixes
 builder.cpp 2023-03-07 Antti Jääskeläinen Antti Jääskeläinen [e71e20] builder: macOS build, remove clang-17 reference...
 builder.hpp 2023-03-07 Antti Jääskeläinen Antti Jääskeläinen [e71e20] builder: macOS build, remove clang-17 reference...
 builder_clang.cpp 2023-03-07 Antti Jääskeläinen Antti Jääskeläinen [e71e20] builder: macOS build, remove clang-17 reference...
 builder_clang.hpp 2023-03-07 Antti Jääskeläinen Antti Jääskeläinen [e71e20] builder: macOS build, remove clang-17 reference...
 builder_gcc.cpp 2023-03-04 Antti Jääskeläinen Antti Jääskeläinen [856348] Merge clang builder
 builder_gcc.hpp 2023-03-04 Antti Jääskeläinen Antti Jääskeläinen [856348] Merge clang builder
 builder_ml.cpp 2022-09-11 A.J. Jääskeläinen A.J. Jääskeläinen [1e972c] reformat: builders
 builder_ml.hpp 2022-07-16 A.J. Jääskeläinen A.J. Jääskeläinen [ee8979] general: Copyright text change
 builder_vc.cpp 2022-09-11 A.J. Jääskeläinen A.J. Jääskeläinen [1e972c] reformat: builders
 builder_vc.hpp 2022-07-16 A.J. Jääskeläinen A.J. Jääskeläinen [ee8979] general: Copyright text change
 c4slib.hpp 2023-03-04 Antti Jääskeläinen Antti Jääskeläinen [856348] Merge clang builder
 compiled_file.hpp 2022-08-04 A.J. Jääskeläinen A.J. Jääskeläinen [b77cd3] ntbs: copy portion of string; more std::string ...
 config.cpp 2022-09-11 A.J. Jääskeläinen A.J. Jääskeläinen [ad9fab] reformat: config & exception
 config.hpp 2022-09-11 A.J. Jääskeläinen A.J. Jääskeläinen [ad9fab] reformat: config & exception
 cpp4scripts2.sublime-project 2023-03-04 Antti Jääskeläinen Antti Jääskeläinen [856348] Merge clang builder
 disable_log.hpp 2022-07-16 A.J. Jääskeläinen A.J. Jääskeläinen [ee8979] general: Copyright text change
 egg.sh 2023-03-23 Antti Jääskeläinen Antti Jääskeläinen [7c046e] general: minor fixes
 exception.cpp 2022-09-11 A.J. Jääskeläinen A.J. Jääskeläinen [ad9fab] reformat: config & exception
 exception.hpp 2023-03-07 Antti Jääskeläinen Antti Jääskeläinen [e71e20] builder: macOS build, remove clang-17 reference...
 libconfig.hpp 2023-03-04 Antti Jääskeläinen Antti Jääskeläinen [856348] Merge clang builder
 logger.cpp 2023-03-04 Antti Jääskeläinen Antti Jääskeläinen [856348] Merge clang builder
 logger.hpp 2022-09-11 A.J. Jääskeläinen A.J. Jääskeläinen [7a59f2] reformat: logger, ntbs, path
 makec4s.cpp 2023-03-04 Antti Jääskeläinen Antti Jääskeläinen [856348] Merge clang builder
 ntbs.cpp 2023-03-04 Antti Jääskeläinen Antti Jääskeläinen [856348] Merge clang builder
 ntbs.hpp 2023-03-23 Antti Jääskeläinen Antti Jääskeläinen [7c046e] general: minor fixes
 path.cpp 2023-03-23 Antti Jääskeläinen Antti Jääskeläinen [7c046e] general: minor fixes
 path.hpp 2022-09-11 A.J. Jääskeläinen A.J. Jääskeläinen [7a59f2] reformat: logger, ntbs, path
 path_list.cpp 2023-03-04 Antti Jääskeläinen Antti Jääskeläinen [856348] Merge clang builder
 path_list.hpp 2022-10-12 A.J. Jääskeläinen A.J. Jääskeläinen [877b5e] ntbs: multiple improvements
 path_stack.hpp 2022-07-16 A.J. Jääskeläinen A.J. Jääskeläinen [ee8979] general: Copyright text change
 process.cpp 2023-03-04 Antti Jääskeläinen Antti Jääskeläinen [856348] Merge clang builder
 process.hpp 2022-10-12 A.J. Jääskeläinen A.J. Jääskeläinen [877b5e] ntbs: multiple improvements
 program_arguments.cpp 2023-03-07 Antti Jääskeläinen Antti Jääskeläinen [e71e20] builder: macOS build, remove clang-17 reference...
 program_arguments.hpp 2023-03-04 Antti Jääskeläinen Antti Jääskeläinen [856348] Merge clang builder
 ring_buffer.cpp 2023-03-23 Antti Jääskeläinen Antti Jääskeläinen [7c046e] general: minor fixes
 ring_buffer.hpp 2023-03-23 Antti Jääskeläinen Antti Jääskeläinen [7c046e] general: minor fixes
 user.cpp 2023-03-04 Antti Jääskeläinen Antti Jääskeläinen [856348] Merge clang builder
 user.hpp 2023-02-21 Antti Jääskeläinen Antti Jääskeläinen [d340e6] general: initial build builder with clang compi...
 util.cpp 2022-10-12 A.J. Jääskeläinen A.J. Jääskeläinen [877b5e] ntbs: multiple improvements
 util.hpp 2022-10-12 A.J. Jääskeläinen A.J. Jääskeläinen [877b5e] ntbs: multiple improvements

Read Me

Introduction

C++ for scripts (cpp4scripts or c4s for short), is a library of classes and functions that
make it easy to write medium and large size "scripts" with C++. Small add-hock scripts are more feasible to
write with Bash (or possibly Perl, Python, etc) but as the complexity of the script increases it helps to
have things like classes, exceptions, debuggers and logging to name a few. These scripts still need to be
compiled but with current compilers this takes only second or two. Trivial price to pay for extra speed
and power.

Using C++ does create more source code than your average script language as far as the line or character count is
concerned. This library tries to mitigate the gap and does pretty good job at it. And if you work mostly with C++
then those few extra lines that are needed are faster to write than trying to learn intricasies of Bash for example.

Building the library

C4S library includes classes to create custom make files or build scripts. Instead of providing scripts or make files
for this library we make use of the library's functionality to create build executable that in turn can be used to
create and install the library itself.

To create build-binary in Lihux / Mac:

g++ -o build build.cxx -Wall -Wno-unused-result -pthread -fexceptions -fno-rtti -fuse-cxa-atexit -O2 -std=c++17 -lstdc++

To create build-exe in Windows:

cl /Febuild.exe /O2 /MD /EHsc /W2 build.cxx Advapi32.lib

Once build-binary is created we can use it for the library:

./build -deb
./build -rel
./build -install [target]

Version 2

  • Include ntbs class as a integrate part of cpp4scripts
  • Replace most std::string instances with ntbs
  • Add support for parallel builds

About ntbs-class

Class is intended to be used in places where std::string is not feasible. This is often case with embeded systems and applications that make extensive use of C-library. It basically acts as a smart pointer for const char* and char* types. Class stores only three things: maximum size reserved for the string, type of allocation and the pointer to null terminated byte string.

Major differences with std::string :
- As with std::string, on assignment more memory is reserved if needed but class only reserves required amount i.e. no exponential growth like in std::string. If memory has been allocated, it will be automatically released once object goes out of scope.
- Library has a macro NTBS(var, size) that reserves desired size char-array from stack and creates ntbs-object for it. This allows programmer to choose wether to use local stack or heap instead of forcing the use of heap.
- ntbs-class does not have any support for standard library streams. Streams don't offer clear benefit over buffered streams and carry same memory disadvantage as std::strings.

Actual ntbs string can be accessed with get()-function. If returns pointer to allocated null terminated memory. This memory can be manipulated just as regular char-buffers can be manipulated. Please note that assigning new value to ntbs-object may require a reservation of more memory and thus invalidates previous pointer received by get().

Samples

Basic declaration and copy

  ntbs foo;             // Initialize empty zero-length object
  ntbs bar(64);     // Reserve 64 byte buffer from heap
ntbs cee("Init to const string");
//
  foo = "Hello world";  // Allocate memory for new value
  bar = foo;                // Copy value to existing buffer

Use stack memory and sprint

NTBS(txt, 64);
txt.sprint("Current unix time = %ld", time());
fputs(txt.get());