Skip to content

Commit

Permalink
Improve readme (#39)
Browse files Browse the repository at this point in the history
* rename show_* -> *

* update dump tests

* rename cont_index -> index

* update dump & color tests

* update README.md

* update readme test

* update README.md

* remove int_style10() manipulator

* update dump test

* update README.md

* use CPP_DUMP_SET_OPTION() in readme code

* update customize-dump.png

* update test

* fix conflict

* tweak
  • Loading branch information
philip82148 authored Jun 4, 2024
1 parent 9189e8d commit bbb2b2e
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 29 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ log_label_func_t fixed_length(int min_width, int max_width,
/**
* Set a value to a variable in cpp_dump namespace.
* You can also assign values to the variables directly.
* (See 'For competitive programming use' for details.)
*/
#define CPP_DUMP_SET_OPTION(variable, value)
```
Expand Down
11 changes: 10 additions & 1 deletion readme/auto-indent.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
#include <iostream>
#include <vector>

#define DEBUGGING
#ifdef DEBUGGING

#include "../dump.hpp"
namespace cp = cpp_dump;

#else
#define cpp_dump(...)
#define CPP_DUMP_SET_OPTION(...)
#endif

int main() {
std::clog << std::endl;

cpp_dump::max_line_width = 100;
CPP_DUMP_SET_OPTION(max_line_width, 100);

std::vector my_vector{
"This is a test string.", "This is a test string.", "This is a test string."};
Expand Down
44 changes: 28 additions & 16 deletions readme/customizable-colors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,37 @@
#include <variant>
#include <vector>

#define DEBUGGING
#ifdef DEBUGGING

#include "../dump.hpp"
namespace cp = cpp_dump;

#else
#define cpp_dump(...)
#define CPP_DUMP_SET_OPTION(...)
#endif

int main() {
cpp_dump::es_value = {
"\x1b[02m", // log: dark
"\x1b[34m", // expression: blue
"\x1b[36m", // reserved: cyan
"\x1b[36m", // number: cyan
"\x1b[36m", // character: cyan
"\x1b[02m", // op: dark
"\x1b[32m", // identifier: green
"\x1b[36m", // member: cyan
"", // unsupported: default
{
"\x1b[33m", // bracket_by_depth[0]: yellow
"\x1b[35m", // bracket_by_depth[1]: magenta
"\x1b[36m", // bracket_by_depth[2]: cyan
},
};
CPP_DUMP_SET_OPTION(
es_value,
(cp::es_value_t{
"\x1b[02m", // log: dark
"\x1b[34m", // expression: blue
"\x1b[36m", // reserved: cyan
"\x1b[36m", // number: cyan
"\x1b[36m", // character: cyan
"\x1b[02m", // op: dark
"\x1b[32m", // identifier: green
"\x1b[36m", // member: cyan
"", // unsupported: default
{
"\x1b[33m", // bracket_by_depth[0]: yellow
"\x1b[35m", // bracket_by_depth[1]: magenta
"\x1b[36m", // bracket_by_depth[2]: cyan
},
})
);

int my_int = 15;
int *ptr = &my_int;
Expand Down
13 changes: 11 additions & 2 deletions readme/customize-dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
#include <set>
#include <vector>

#define DEBUGGING
#ifdef DEBUGGING

#include "../dump.hpp"
namespace cp = cpp_dump;

#else
#define cpp_dump(...)
#define CPP_DUMP_SET_OPTION(...)
#endif

void my_func() {
std::map<int, int> my_map{{2, 6}, {4, 6}, {5, 3}};
Expand All @@ -18,15 +27,15 @@ int main() {
std::vector<std::vector<int>> my_vector{{3, 5, 8, 9, 7}, {9, 3, 2, 3, 8}};

std::clog << "// Print the filename and line instead of [dump]" << std::endl;
cpp_dump::log_label_func = cpp_dump::log_label::filename();
CPP_DUMP_SET_OPTION(log_label_func, cp::log_label::filename());

cpp_dump(my_vector);
my_func();

std::clog << std::endl;

std::clog << "// Print along with the function name" << std::endl;
cpp_dump::log_label_func = cpp_dump::log_label::filename(true);
CPP_DUMP_SET_OPTION(log_label_func, cp::log_label::filename(true));

cpp_dump(my_vector);
my_func();
Expand Down
Binary file modified readme/customize-dump.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions readme/formatting-with-manipulators.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#include <iostream>
#include <vector>

#include "../dump.hpp"
#define DEBUGGING
#ifdef DEBUGGING

#include "../dump.hpp"
namespace cp = cpp_dump;

#else
#define cpp_dump(...)
#define CPP_DUMP_SET_OPTION(...)
#endif

int main() {
std::clog << std::endl;

Expand Down Expand Up @@ -37,7 +44,7 @@ int main() {
std::clog << std::endl;

// cont-index.png
cp::max_iteration_count = 5;
CPP_DUMP_SET_OPTION(max_iteration_count, 5);
cpp_dump(some_huge_vector | cp::dec(2) | cp::index());

std::clog << std::endl;
Expand Down
9 changes: 9 additions & 0 deletions readme/introduction.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#include <iostream>
#include <vector>

#define DEBUGGING
#ifdef DEBUGGING

#include "../dump.hpp"
namespace cp = cpp_dump;

#else
#define cpp_dump(...)
#define CPP_DUMP_SET_OPTION(...)
#endif

int main() {
std::clog << std::endl;
Expand Down
11 changes: 10 additions & 1 deletion readme/no-es.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@
#include <variant>
#include <vector>

#define DEBUGGING
#ifdef DEBUGGING

#include "../dump.hpp"
namespace cp = cpp_dump;

#else
#define cpp_dump(...)
#define CPP_DUMP_SET_OPTION(...)
#endif

int main() {
cpp_dump::es_style = cpp_dump::es_style_t::no_es;
CPP_DUMP_SET_OPTION(es_style, cp::es_style_t::no_es);

int my_int = 15;
int *ptr = &my_int;
Expand Down
9 changes: 9 additions & 0 deletions readme/supports-various-types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@
#include <variant>
#include <vector>

#define DEBUGGING
#ifdef DEBUGGING

#include "../dump.hpp"
namespace cp = cpp_dump;

#else
#define cpp_dump(...)
#define CPP_DUMP_SET_OPTION(...)
#endif

int main() {
int my_int = 15;
Expand Down
10 changes: 10 additions & 0 deletions readme/user-defined-class.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#include <iostream>

#define DEBUGGING
#ifdef DEBUGGING

#include "../dump.hpp"
namespace cp = cpp_dump;

#else
#define cpp_dump(...)
#define CPP_DUMP_SET_OPTION(...)
#define CPP_DUMP_DEFINE_EXPORT_OBJECT(...)
#endif

struct class_A {
int i;
Expand Down
10 changes: 10 additions & 0 deletions readme/user-defined-class2.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#include <iostream>

#define DEBUGGING
#ifdef DEBUGGING

#include "../dump.hpp"
namespace cp = cpp_dump;

#else
#define cpp_dump(...)
#define CPP_DUMP_SET_OPTION(...)
#define CPP_DUMP_DEFINE_DANGEROUS_EXPORT_OBJECT(...)
#endif

CPP_DUMP_DEFINE_DANGEROUS_EXPORT_OBJECT(i, str());

Expand Down
9 changes: 9 additions & 0 deletions readme/user-defined-class3.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#include <iostream>

#define DEBUGGING
#ifdef DEBUGGING

#include "../dump.hpp"
namespace cp = cpp_dump;

#else
#define cpp_dump(...)
#define CPP_DUMP_SET_OPTION(...)
#endif

struct class_A {
int i;
Expand Down
10 changes: 10 additions & 0 deletions readme/user-defined-enum.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#include <iostream>

#define DEBUGGING
#ifdef DEBUGGING

#include "../dump.hpp"
namespace cp = cpp_dump;

#else
#define cpp_dump(...)
#define CPP_DUMP_SET_OPTION(...)
#define CPP_DUMP_DEFINE_EXPORT_ENUM(...)
#endif

enum class enum_A { a, b, c };
CPP_DUMP_DEFINE_EXPORT_ENUM(enum_A, enum_A::a, enum_A::b, enum_A::c);
Expand Down
12 changes: 6 additions & 6 deletions test/txt/readme_customize-dump.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

// Print the filename and line instead of [dump]
[customize-dump.cpp:23] my_vector => [
[customize-dump.cpp:32] my_vector => [
[ 3, 5, 8, 9, 7 ],
[ 9, 3, 2, 3, 8 ]
]
[customize-dump.cpp:11] my_map => { 2: 6, 4: 6, 5: 3 }
[customize-dump.cpp:12] my_set => { 'A', 'e', 'l', 'p' }
[customize-dump.cpp:20] my_map => { 2: 6, 4: 6, 5: 3 }
[customize-dump.cpp:21] my_set => { 'A', 'e', 'l', 'p' }

// Print along with the function name
[customize-dump.cpp:31 (main)] my_vector => [
[customize-dump.cpp:40 (main)] my_vector => [
[ 3, 5, 8, 9, 7 ],
[ 9, 3, 2, 3, 8 ]
]
[customize-dump.cpp:11 (my_func)] my_map => { 2: 6, 4: 6, 5: 3 }
[customize-dump.cpp:12 (my_func)] my_set => { 'A', 'e', 'l', 'p' }
[customize-dump.cpp:20 (my_func)] my_map => { 2: 6, 4: 6, 5: 3 }
[customize-dump.cpp:21 (my_func)] my_set => { 'A', 'e', 'l', 'p' }

0 comments on commit bbb2b2e

Please sign in to comment.