Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.20)

project(cwpack LANGUAGES CXX)

enable_testing()

add_library(cwpack INTERFACE
src/cwpack.hpp
src/cwpack_config.h
src/cwpack_internals.hpp
)

target_include_directories(cwpack INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src)

target_compile_features(cwpack INTERFACE cxx_std_20)

add_subdirectory(goodies)

add_subdirectory(example)

add_subdirectory(test)
10 changes: 10 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.20)

project(cwpack_example)

add_executable(json2cwpack2json
item.cpp
json2cwpack2json.cpp
)

target_link_libraries(json2cwpack2json PUBLIC cwpack_basic_contexts)
22 changes: 11 additions & 11 deletions example/item.c → example/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void item32JsonFile (FILE* file, item_root* item)
#define scanSpace while (**ptr == ' ' || **ptr == '\n' || **ptr == '\t') (*ptr)++

#define allocate_item(typ, typeMark, extra) \
malloc (sizeof(typ) + extra); \
reinterpret_cast<typ*>(malloc (sizeof(typ) + extra)); \
result->item_type = typeMark


Expand Down Expand Up @@ -368,7 +368,7 @@ item_root* jsonFile2item3 (FILE* file)
{
fseek (file, 0, SEEK_END);
long length = ftell(file);
char* buffer = malloc (length+1);
char* buffer = reinterpret_cast<char*>(malloc (length+1));

fseek (file, 0l, SEEK_SET);
fread (buffer, 1, length, file);
Expand Down Expand Up @@ -454,11 +454,11 @@ static item_root* packContext2item3 (cw_unpack_context* uc)
item_container* ic;
switch (uc->item.type)
{
case CWP_ITEM_NIL:
case cwpack::item_type::NIL:
result = allocate_item(item_root,ITEM_NIL,0);
break;

case CWP_ITEM_BOOLEAN:
case cwpack::item_type::BOOLEAN:
if (uc->item.as.boolean)
{
result = allocate_item(item_root,ITEM_TRUE,0);
Expand All @@ -469,29 +469,29 @@ static item_root* packContext2item3 (cw_unpack_context* uc)
}
break;

case CWP_ITEM_POSITIVE_INTEGER:
case CWP_ITEM_NEGATIVE_INTEGER:
case cwpack::item_type::POSITIVE_INTEGER:
case cwpack::item_type::NEGATIVE_INTEGER:
result = (item_root*)allocate_item(item_integer,ITEM_INTEGER,0);
((item_integer*)result)->value = uc->item.as.i64;
break;

case CWP_ITEM_FLOAT:
case cwpack::item_type::FLOAT:
result = (item_root*)allocate_item(item_real,ITEM_REAL,0);
((item_real*)result)->value = uc->item.as.real;
break;

case CWP_ITEM_DOUBLE:
case cwpack::item_type::DOUBLE:
result = (item_root*)allocate_item(item_real,ITEM_REAL,0);
((item_real*)result)->value = uc->item.as.long_real;
break;

case CWP_ITEM_STR:
case cwpack::item_type::STR:
result = (item_root*)allocate_item(item_string,ITEM_STRING,uc->item.as.str.length + 1);
strncpy(((item_string*)result)->string, (const char*)uc->item.as.str.start, uc->item.as.str.length);
((item_string*)result)->string[uc->item.as.str.length] = 0;
break;

case CWP_ITEM_MAP:
case cwpack::item_type::MAP:
dim = 2 * uc->item.as.map.size;
ic = allocate_container(ITEM_MAP, dim);
for (i=0; i<dim; i++)
Expand All @@ -501,7 +501,7 @@ static item_root* packContext2item3 (cw_unpack_context* uc)
result = (item_root*)ic;
break;

case CWP_ITEM_ARRAY:
case cwpack::item_type::ARRAY:
dim = uc->item.as.array.size;
ic = allocate_container(ITEM_ARRAY, dim);
for (i=0; i<dim; i++)
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions goodies/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.20)

project(cwpack_goodies)

add_subdirectory(basic-contexts)
add_subdirectory(utils)
12 changes: 12 additions & 0 deletions goodies/basic-contexts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.20)

project(cwpack_basic_contexts)

add_library(cwpack_basic_contexts
basic_contexts.h
basic_contexts.cpp
)

target_link_libraries(cwpack_basic_contexts PUBLIC cwpack)

target_include_directories(cwpack_basic_contexts PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/***************************************** DYNAMIC MEMORY PACK CONTEXT ********************************/


static int handle_memory_pack_overflow(struct cw_pack_context* pc, unsigned long more)
static int handle_memory_pack_overflow(cw_pack_context* pc, unsigned long more)
{
unsigned long contains = (unsigned long)(pc->current - pc->start);
unsigned long tot_len = contains + more;
Expand Down Expand Up @@ -78,7 +78,7 @@ void free_dynamic_memory_pack_context(dynamic_memory_pack_context* dmpc)



static int flush_stream_pack_context(struct cw_pack_context* pc)
static int flush_stream_pack_context(cw_pack_context* pc)
{
stream_pack_context* spc = (stream_pack_context*)pc;
unsigned long contains = (unsigned long)(pc->current - pc->start);
Expand All @@ -95,7 +95,7 @@ static int flush_stream_pack_context(struct cw_pack_context* pc)
}


static int handle_stream_pack_overflow(struct cw_pack_context* pc, unsigned long more)
static int handle_stream_pack_overflow(cw_pack_context* pc, unsigned long more)
{
int rc = flush_stream_pack_context(pc);
if (rc != CWP_RC_OK)
Expand Down Expand Up @@ -150,7 +150,7 @@ void terminate_stream_pack_context(stream_pack_context* spc)
/***************************************** STREAM UNPACK CONTEXT *******************************/


static int handle_stream_unpack_underflow(struct cw_unpack_context* uc, unsigned long more)
static int handle_stream_unpack_underflow(cw_unpack_context* uc, unsigned long more)
{
stream_unpack_context* suc = (stream_unpack_context*)uc;
unsigned long remains = (unsigned long)(uc->end - uc->current);
Expand Down Expand Up @@ -214,7 +214,7 @@ void terminate_stream_unpack_context(stream_unpack_context* suc)
/***************************************** FILE PACK CONTEXT **********************************/


static int flush_file_pack_context(struct cw_pack_context* pc)
static int flush_file_pack_context(cw_pack_context* pc)
{
file_pack_context* fpc = (file_pack_context*)pc;
uint8_t *bStart = fpc->barrier ? fpc->barrier : pc->current;
Expand Down Expand Up @@ -243,7 +243,7 @@ static int flush_file_pack_context(struct cw_pack_context* pc)
return CWP_RC_OK;
}

static int handle_file_pack_overflow(struct cw_pack_context* pc, unsigned long more)
static int handle_file_pack_overflow(cw_pack_context* pc, unsigned long more)
{
file_pack_context* fpc = (file_pack_context*)pc;
int rc = flush_file_pack_context(pc);
Expand Down Expand Up @@ -327,7 +327,7 @@ void terminate_file_pack_context(file_pack_context* fpc)
/***************************************** FILE UNPACK CONTEXT ********************************/


static int handle_file_unpack_underflow(struct cw_unpack_context* uc, unsigned long more)
static int handle_file_unpack_underflow(cw_unpack_context* uc, unsigned long more)
{
file_unpack_context* auc = (file_unpack_context*)uc;
uint8_t *bStart = auc->barrier ? auc->barrier : uc->current;
Expand Down
2 changes: 1 addition & 1 deletion goodies/basic-contexts/basic_contexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#define basic_contexts_h

#include <stdio.h>
#include "cwpack.h"
#include "cwpack.hpp"


/***************************************** DYNAMIC MEMORY PACK CONTEXT ************************/
Expand Down
13 changes: 13 additions & 0 deletions goodies/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.20)

project(cwpack_utils LANGUAGES CXX)

add_library(cwpack_utils
cwpack_utils.cpp
cwpack_utils.h
)

target_link_libraries(cwpack_utils PUBLIC cwpack)

target_include_directories(cwpack_utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

Loading