8000 Now split all blobstamper code into thematic files · postgrespro/libblobstamper@e03b0a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit e03b0a1

Browse files
Now split all blobstamper code into thematic files
1 parent c518c41 commit e03b0a1

File tree

11 files changed

+179
-213
lines changed

11 files changed

+179
-213
lines changed

Makefile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ ifeq ($(origin CC),default)
66
CC = gcc
77
endif
88

9-
BLOB_STAMPER_OBJ = blobstamper/blob.o blobstamper/helpers.o
9+
BLOB_STAMPER_OBJ = blobstamper/blob.o \
10+
blobstamper/helpers.o \
11+
blobstamper/stamp.o \
12+
blobstamper/stamp_atomic.o \
13+
blobstamper/stamp_pg_type_geo.o \
14+
15+
1016

1117
.PHONY: all
1218
all: blob-stamper-all test test_pg_op_wrappers test_libblobstamper
@@ -19,12 +25,11 @@ blob-stamper-all:
1925
test: $(LIB_OBJS) test.o
2026
$(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS)
2127

22-
test_pg_op_wrappers: blob-stamper-a 8000 ll $(LIB_OBJS) test_pg_op_wrappers.o libblobstamper.o pg_op_wrappers.o
23-
$(CXX) $(LDFLAGS) $@.o -o $@ $(LDLIBS) $(BLOB_STAMPER_OBJ) libblobstamper.o pg_op_wrappers.o
24-
25-
test_libblobstamper: $(LIB_OBJS) libblobstamper.o test_libblobstamper.o blob-stamper-all
26-
$(CXX) $(LDFLAGS) $@.o -o $@ $(LDLIBS) $(BLOB_STAMPER_OBJ) libblobstamper.o
28+
test_pg_op_wrappers: blob-stamper-all $(LIB_OBJS) test_pg_op_wrappers.o pg_op_wrappers.o
29+
$(CXX) $(LDFLAGS) $@.o -o $@ $(LDLIBS) $(BLOB_STAMPER_OBJ) pg_op_wrappers.o
2730

31+
test_libblobstamper: $(LIB_OBJS) test_libblobstamper.o blob-stamper-all
32+
$(CXX) $(LDFLAGS) $@.o -o $@ $(LDLIBS) $(BLOB_STAMPER_OBJ)
2833

2934

3035
%.o: %.cpp $(DEPS)

blobstamper/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11

2-
ALL_OBJS = blob.o helpers.o
2+
ALL_OBJS = blob.o \
3+
helpers.o \
4+
stamp.o \
5+
stamp_atomic.o \
6+
stamp_pg_type_geo.o
7+
38

49
%.o: %.cpp $(DEPS)
510
$(CXX) -c -g $(CFLAGS) $<

blobstamper/blob.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "blob.h"
22
#include "helpers.h"
33

4-
#include "../libblobstamper.h" /*FIXME remove this*/
4+
#include "stamp.h"
55

66
Blob::Blob (char * data_in, int size_in)
77
{

blobstamper/blobstamper.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
#include "blob.h"
3+
#include "stamp.h"
4+
#include "stamp_atomic.h"
5+
#include "stamp_pg_type_geo.h"
6+
7+

blobstamper/stamp.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
#include <string>
3+
#include <list>
4+
5+
#include "blob.h"
6+
#include "stamp.h"
7+
8+
/*************************************************************************************/
9+
10+
std::list<std::string> StampList::ExtractStrList(Blob &blob)
11+
{
12+
std::list<std::string> res;
13+
14+
if (target_stamp.isFixedSize())
15+
{
16+
while (1)
17+
{
18+
std::string el = blob.ShiftSingleStampStr(target_stamp);
19+
if (el.empty())
20+
break;
21+
res.push_back(el);
22+
}
23+
}
24+
else
25+
{
26+
printf("Not implemented yet!");
27+
exit(1);
28+
}
29+
30+
return res;
31+
}
32+

blobstamper/stamp.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
#ifndef STAMP_H
3+
#define STAMP_H
4+
5+
#include <string>
6+
#include <list>
7+
8+
class StampGeneric
9+
{
10+
protected:
11+
bool is_fixed_size;
12+
int min_size;
13+
int max_size;
14+
public:
15+
bool isFixedSize() {return is_fixed_size;}
16+
int minSize() {return min_size;}
17+
int maxSize() {return max_size;}
18+
19+
virtual void * Extract(Blob &blob) {printf ("1111111\n"); return NULL;}
20+
virtual std::string ExtractStr(Blob &blob) {printf ("22222\n"); return "";}
21+
22+
};
23+
24+
class StampList: public StampGeneric
25+
{
26+
protected:
27+
StampGeneric& target_stamp;
28+
public:
29+
StampList(StampGeneric &stamp) : target_stamp(stamp) {};
30+
31+
virtual std::list<std::string> ExtractStrList(Blob &blob);
32+
33+
34+
};
35+
36+
#endif /* STAMP_H */

blobstamper/stamp_atomic.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
#include <string.h>
3+
4+
#include "blob.h"
5+
#include "stamp.h"
6+
#include "stamp_atomic.h"
7+
8+
StampBinDouble::StampBinDouble() : StampGeneric()
9+
{
10+
min_size = sizeof(double);
11+
max_size = sizeof(double);
12+
is_fixed_size = true;
13+
}
14+
15+
void *
16+
StampBinDouble::Extract(Blob &blob)
17+
{
18+
Blob blob2 = blob.ShiftBytes(min_size);
19+
if (blob2.isEmpty())
20+
return NULL;
21+
void *res = malloc(min_size);
22+
memcpy(res, blob2.data + blob2.begin, min_size);
23+
return res;
24+
}
25+
26+
/* ---- */
27+
28+
std::string
29+
StampStrDouble::ExtractStr(Blob &blob)
30+
{
31+
std::string res = "";
32+
double *pd = (double *)this->Extract(blob);
33+
if (! pd)
34+
return res;
35+
36+
int size_s = snprintf( nullptr, 0, "%.999g", *pd) + 1;
37+
if (size_s <= 0)
38+
{
39+
printf("ai-ai-ai\n");
40+
return "";
41+
}
42+
43+
char * resc =(char *) malloc(size_s);
44+
if (! resc)
45+
{
46+
printf("oh-oh-oh\n");
47+
return "";
48+
}
49+
50+
int ret = snprintf(resc,size_s,"%.999g", *pd);
51+
if (ret <= 0)
52+
{
53+
printf("oi-oi-oi\n");
54+
free(resc);
55+
return "";
56+
}
57+
res = resc;
58+
free(resc);
59+
free(pd);
60+
return res;
61+
}
62+
/* ---- */

blobstamper/stamp_atomic.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef STAMP_ATOMIC_H
2+
#define STAMP_ATOMIC_H
3+
4+
#include <string>
5+
6+
class StampBinDouble: public StampGeneric
7+
{
8+
public:
9+
StampBinDouble();
10+
void * Extract(Blob &blob) override;
11+
};
12+
13+
14+
class StampStrDouble: public StampBinDouble
15+
{
16+
public:
17+
StampStrDouble() : StampBinDouble() {}
18+
std::string ExtractStr(Blob &blob) override;
19+
};
20+
21+
22+
23+
#endif /* STAMP_ATOMIC_H */

libblobstamper.cpp

Lines changed: 0 additions & 134 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0