Skip to content

Commit 3803c84

Browse files
committed
Single-header version.
1 parent 2280ec5 commit 3803c84

7 files changed

Lines changed: 38723 additions & 2 deletions

File tree

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ test: jsoncheck numberparsingcheck stringparsingcheck
6262
@echo "It looks like the code is good!"
6363
@tput sgr0
6464

65+
amalgamate:
66+
./amalgamation.sh
6567

6668
$(SAJSON_INCLUDE):
6769
git submodule update --init --recursive

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ if( ! pj.isValid() ) {
8888
}
8989
```
9090

91+
## Usage: easy single-header version
92+
93+
See the "singleheader" repository for a single header version. See the included
94+
file "amalgamation_demo.cpp" for usage. This requires no specific build system: just
95+
copy the files in your project.
96+
97+
9198

9299
## Usage (old-school Makefile on platforms like Linux or macOS)
93100

amalgamation.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ AMAL_H="simdjson.h"
1212
AMAL_C="simdjson.cpp"
1313

1414
# order does not matter
15-
ALLCFILES=$( ( [ -d $SCRIPTPATH/.git ] && ( type git >/dev/null 2>&1 ) && ( git ls-files $SCRIPTPATH/src/*.c $SCRIPTPATH/src/**/*c ) ) || ( find $SCRIPTPATH/src -name '*.c' ) )
15+
ALLCFILES="
16+
$SCRIPTPATH/src/jsonioutil.cpp
17+
$SCRIPTPATH/src/jsonminifier.cpp
18+
$SCRIPTPATH/src/jsonparser.cpp
19+
$SCRIPTPATH/src/stage1_find_marks.cpp
20+
$SCRIPTPATH/src/stage2_flatten.cpp
21+
$SCRIPTPATH/src/stage34_unified.cpp
22+
"
1623

1724
# order matters
1825
ALLCHEADERS="
@@ -112,7 +119,14 @@ echo "Giving final instructions:"
112119
CPPBIN=${DEMOCPP%%.*}
113120

114121
echo "Try :"
115-
echo "c++ -march=native -O3 -std=c++11 -o ${CPPBIN} ${DEMOCPP} && ./${CPPBIN} "
122+
echo "c++ -march=native -O3 -std=c++11 -o ${CPPBIN} ${DEMOCPP} && ./${CPPBIN} jsonexamples/twitter.json "
123+
124+
SINGLEHDR=$SCRIPTPATH/singleheader
125+
echo "Copying files to $SCRIPTPATH/singleheader "
126+
mkdir -p $SINGLEHDR
127+
echo "c++ -march=native -O3 -std=c++11 -o ${CPPBIN} ${DEMOCPP} && ./${CPPBIN} ../jsonexamples/twitter.json " > $SINGLEHDR/README.md
128+
cp ${AMAL_C} ${AMAL_H} ${DEMOCPP} $SINGLEHDR
129+
ls $SINGLEHDR
116130

117131
lowercase(){
118132
echo "$1" | tr 'A-Z' 'a-z'

singleheader/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c++ -march=native -O3 -std=c++11 -o amalgamation_demo amalgamation_demo.cpp && ./amalgamation_demo ../jsonexamples/twitter.json

singleheader/amalgamation_demo.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* auto-generated on Sun 30 Dec 2018 21:47:24 EST. Do not edit! */
2+
3+
#include <iostream>
4+
#include "simdjson.h"
5+
#include "simdjson.cpp"
6+
int main(int argc, char *argv[]) {
7+
const char * filename = argv[1];
8+
std::string_view p = get_corpus(filename);
9+
ParsedJson pj = build_parsed_json(p); // do the parsing
10+
if( ! pj.isValid() ) {
11+
std::cout << "not valid" << std::endl;
12+
} else {
13+
std::cout << "valid" << std::endl;
14+
}
15+
return EXIT_SUCCESS;
16+
}
17+

0 commit comments

Comments
 (0)