Git Product home page Git Product logo

smallcxx's Introduction

smallcxx - Small C++ libraries

These use C++11.

All code Copyright (c) 2021 Christopher White, unless otherwise indicated.

Overview

This is a C++11 project using autotools as the build system.

The modules are:

Always built

  • logging: multi-level logging library
  • string: some string functions not in string.h and friends
  • test: basic testcase-management and test-assertion library

Optional

  • globstari: file-globbing and ignore-files routines
    • Depends on PCRE2

Using

Compiling with gcc

./configure && make -j  # normal
./coverage.sh           # for code coverage
./asan.sh               # for Address Sanitizer

Compiling with clang

./configure CC=clang CXX=clang++ && make -j
./asan.sh clang                             # for Address Sanitizer

Note that CXX does have to be clang++, not just clang.

Third-party software used by smallcxx

  • editorconfig-core-c by the EditorConfig team. Licensed under various BSD licenses. Included in the globstari module

Developing

Development dependencies

  • Pretty-printing: Artistic Style, Ubuntu package astyle.
  • Docs: Doxygen and dot(1) (Ubuntu packages doxygen and graphviz)

Starting fresh

./autogen.sh && make -j maintainer-clean && ./autogen.sh

That will leave you ready to run make

The first time you compile, you may get errors about missing .deps/* files. If so, re-run make. If that doesn't work, run make -jk once to generate the deps files, and then you should be back in business.

Running the tests

make -j check, or ./asan.sh for Address Sanitizer testing.

Structure of the codebase

  • src/: implementation files
  • include/smallcxx/: header files
  • t/: tests. *-t.sh and *-t.cpp are test sources. *-s.cpp are supporting programs.
  • doc/: documentation. Doxygen output is in doc/html/index.html.

Coding style

  • 4-space tabs, cuddled else. Run make prettyprint to format your code.
  • All Doxygen tags start with @ (not backslash).

smallcxx's People

Contributors

cxw42 avatar

Watchers

 avatar  avatar  avatar

smallcxx's Issues

Add a command-line logger

A program you can run from the command line to output a single log line. That way scripts will be able to log in the same format as C programs.

logging: add `LOG_S` to log with stream syntax

I think something like this:

struct Printer {
    operator=(LogStringFormatter&) { ... }
} g_PrintNow;

#define LOG_S(...) \
    g_PrintNow = LogStringFormatter(__VA_ARGS__)
...
LOG_S(INFO) << "Foo " << i;

logging.hpp: PRINT and PRINTERR should add a newline

They currently do not.

diff --git a/3rdparty/smallcxx/logging.hpp b/3rdparty/smallcxx/logging.hpp
index 95202f8..fc03ba9 100644
--- a/3rdparty/smallcxx/logging.hpp
+++ b/3rdparty/smallcxx/logging.hpp
@@ -93,7 +93,7 @@ void vlogMessage(const std::string& domain,
 /// Usage example: `LOG_F(INFO, "foo %s", some_string);`
 /// @note `LOG_F(SILENT, ...)` is forbidden.
 #define LOG_F(level, format, ...) \
-    LOG_F_DOMAIN(SMALLCXX_LOG_DOMAIN_NAME, level, (format), ## __VA_ARGS__);
+    LOG_F_DOMAIN(SMALLCXX_LOG_DOMAIN_NAME, level, format, ## __VA_ARGS__);
 
 /// Log, with a particular log domain.
 #define LOG_F_DOMAIN(domain, level, format, ...) \
@@ -107,11 +107,11 @@ void vlogMessage(const std::string& domain,
         /* print it */ \
         if(LOG_##level == LOG_PRINT) { \
             if(getLogLevel(domain) != LOG_SILENT) { \
-                printf((format), ## __VA_ARGS__); \
+                printf(format "\n", ## __VA_ARGS__); \
             } \
         } else if(LOG_##level == LOG_PRINTERR) { \
             if(getLogLevel(domain) != LOG_SILENT) { \
-                fprintf(stderr, (format), ## __VA_ARGS__); \
+                fprintf(stderr, format "\n", ## __VA_ARGS__); \
             } \
         } else { \
             logMessage(domain, LOG_##level, __FILE__, __LINE__, __func__, \

New module: globstar + ignores

ag and editorconfig aren't quite what I'm looking for.

  • Ability to traverse virtual (no readdir()) trees
  • Ability to turn ignores on and off

bin/smallcxxlog: accept PID as a parameter

Call smallcxxlog multiple times from a script and you may see, e.g.:

[780437.384507222] 288405   ERROR ./630-cmdline-checko:73   test_subdir          Command failed (code 1): [ -e /tmp/tmp.qtbeIhe7s4/dir/first ]
[780437.411007634] 288419   ERROR            common.sh:227  readable_file_ok     Command failed (code 1): [ -f /tmp/tmp.qtbeIhe7s4/dir/first ]
[780437.434050256] 288433   ERROR            common.sh:228  readable_file_ok     Command failed (code 1): [ -r /tmp/tmp.qtbeIhe7s4/dir/first ]
                   ^^^^^^  different PIDs each time

even though the script's PID hasn't changed. Permit smallcxxlog to take the PID as a parameter.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.