Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 407cd78

Browse files
Add first example; and a blob representation 'asString' to fit this example
1 parent a4e3a52 commit 407cd78

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ endif
1111
BLOBSTAMPER_SRC := $(wildcard blobstamper/*.cpp)
1212
BLOBSTAMPER_OBJ := $(addsuffix .o, $(basename $(BLOBSTAMPER_SRC)))
1313

14+
EXAMPLES_SRC = $(wildcard examples/*.cpp)
15+
EXAMPLES_BIN = $(basename $(EXAMPLES_SRC))
16+
17+
1418
.PHONY: all blob-stamper-all blob-stamper-clean clean test gagaga
1519

1620
all: $(BLOBSTAMPER_OBJ)
@@ -46,6 +50,8 @@ test:
4650
#test_dict: test_dict.o blob-stamper-all
4751
# $(CXX) $(LDFLAGS) $@.o -o $@ $(BLOB_STAMPER_OBJ)
4852

53+
examples: $(BLOBSTAMPER_OBJ)
54+
$(MAKE) -C examples
4955

5056
gagaga:
5157
@echo ------- $(BLOBSTAMPER_OBJ)

blobstamper/blob.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,10 @@ Blob::asVector()
111111
return res;
112112
}
113113

114+
/* Do not use in prod. For tests and examples only */
115+
std::string
116+
Blob::asString()
117+
{
118+
std::string res((char *)data + begin, Size());
119+
return res;
120+
}

blobstamper/blob.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Blob
4242
std::vector<char> ChopBlank(StampBase &stmp);
4343
void DataDup(char *& data_out, size_t& size_out);
4444
std::vector<char> asVector();
45+
std::string asString(); /* Should not be used in prod, for tests and examples only*/
4546
};
4647

4748
class OutOfData /*An exeption. Experemental for now*/

examples/Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
BLOBSTAMPER_SRC := $(wildcard ../blobstamper/*.cpp)
3+
BLOBSTAMPER_OBJ := $(addsuffix .o, $(basename $(BLOBSTAMPER_SRC)))
4+
5+
EXAMPLES_SRC = $(wildcard *.cpp)
6+
EXAMPLES_BIN = $(basename $(EXAMPLES_SRC))
7+
8+
9+
all: $(EXAMPLES_BIN)
10+
11+
build-libtappp:
12+
$(MAKE) -C ../libtappp
13+
14+
../blobstamper-pg/%.o: ../blobstamper-pg/%.cpp
15+
$(CXX) -c -g $(CXXFLAGS) -I .. $< -o $@
16+
17+
../wrappers/%.o: ../wrappers/%.cpp
18+
$(CXX) -c -g $(CXXFLAGS) -I .. $< -o $@
19+
20+
21+
%: %.cpp $(BLOBSTAMPER_OBJ) $(BLOBSTAMPER_PG_OBJ) $(WRAPPERS_OBJ)
22+
$(CXX) $(CXXFLAGS) -I.. -o $@ $< $(BLOBSTAMPER_OBJ)
23+
24+
clean:
25+
-rm $(EXAMPLES_BIN) 2>/dev/null
26+
27+
.PHONY: test clean all
28+

examples/example01.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
4+
#include<string>
5+
#include<iostream>
6+
7+
#include<blobstamper/blobstamper.h>
8+
9+
int main()
10+
{
11+
char data[] = "abcde";
12+
Blob blob(data, strlen(data));
13+
StampArithm<short int> stamp;
14+
std::string s = stamp.ExtractStr(blob);
15+
16+
std::cout << "Stamp minSize: " << stamp.minSize() << "\n";
17+
std::cout << "Stamp maxSize: " << stamp.maxSize() << "\n";
18+
std::cout << "Extracted value: " << s <<"\n";
19+
std::cout << "Remaining blob: " << blob.asString() << "\n";
20+
}

0 commit comments

Comments
 (0)