Skip to content

Commit

Permalink
[#183][C] Added occaJson
Browse files Browse the repository at this point in the history
  • Loading branch information
dmed256 committed Sep 2, 2018
1 parent ce46013 commit e27b29e
Show file tree
Hide file tree
Showing 17 changed files with 922 additions and 141 deletions.
1 change: 1 addition & 0 deletions include/occa.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <occa/c/kernel.h>
#include <occa/c/memory.h>
#include <occa/c/base.h>
#include <occa/c/json.h>
#include <occa/c/properties.h>

// Just in case someone wants to run with an older format than C99
Expand Down
86 changes: 86 additions & 0 deletions include/occa/c/json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* The MIT License (MIT)
*
* Copyright (c) 2014-2018 David Medina and Tim Warburton
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*/

#ifndef OCCA_C_JSON_HEADER
#define OCCA_C_JSON_HEADER

#include <occa/c/defines.h>
#include <occa/c/types.h>

OCCA_START_EXTERN_C

OCCA_LFUNC occaJson OCCA_RFUNC occaCreateJson();

OCCA_LFUNC occaJson OCCA_RFUNC occaCreateJsonFromString(const char *c);

//---[ Type checks ]--------------------
OCCA_LFUNC int OCCA_RFUNC occaJsonIsBoolean(occaJson j);
OCCA_LFUNC int OCCA_RFUNC occaJsonIsNumber(occaJson j);
OCCA_LFUNC int OCCA_RFUNC occaJsonIsString(occaJson j);
OCCA_LFUNC int OCCA_RFUNC occaJsonIsArray(occaJson j);
OCCA_LFUNC int OCCA_RFUNC occaJsonIsObject(occaJson j);
//======================================


//---[ Getters ]------------------------
OCCA_LFUNC int OCCA_RFUNC occaJsonGetBoolean(occaJson j);
OCCA_LFUNC occaType OCCA_RFUNC occaJsonGetNumber(occaJson j,
const int type);
OCCA_LFUNC const char* OCCA_RFUNC occaJsonGetString(occaJson j);
//======================================


//---[ Object methods ]-----------------
OCCA_LFUNC occaType OCCA_RFUNC occaJsonObjectGet(occaJson j,
const char *key,
occaType defaultValue);

OCCA_LFUNC void OCCA_RFUNC occaJsonObjectSet(occaJson j,
const char *key,
occaType value);

OCCA_LFUNC int OCCA_RFUNC occaJsonObjectHas(occaJson j,
const char *key);
//======================================


//---[ Array methods ]------------------
OCCA_LFUNC int OCCA_RFUNC occaJsonArraySize(occaJson j);

OCCA_LFUNC occaType OCCA_RFUNC occaJsonArrayGet(occaJson j,
const int index);

OCCA_LFUNC void OCCA_RFUNC occaJsonArrayPush(occaJson j,
occaType value);

OCCA_LFUNC void OCCA_RFUNC occaJsonArrayPop(occaJson j);

OCCA_LFUNC void OCCA_RFUNC occaJsonArrayInsert(occaJson j,
const int index,
occaType value);

OCCA_LFUNC void OCCA_RFUNC occaJsonArrayClear(occaJson j);
//======================================

OCCA_END_EXTERN_C

#endif
12 changes: 6 additions & 6 deletions include/occa/c/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@

OCCA_START_EXTERN_C

OCCA_LFUNC occaType OCCA_RFUNC occaCreateProperties();
OCCA_LFUNC occaProperties OCCA_RFUNC occaCreateProperties();

OCCA_LFUNC occaType OCCA_RFUNC occaCreatePropertiesFromString(const char *c);
OCCA_LFUNC occaProperties OCCA_RFUNC occaCreatePropertiesFromString(const char *c);

OCCA_LFUNC occaType OCCA_RFUNC occaPropertiesGet(occaProperties props,
const char *key,
occaType defaultValue);

OCCA_LFUNC void OCCA_RFUNC occaPropertiesSet(occaProperties props,
const char *key,
Expand All @@ -39,10 +43,6 @@ OCCA_LFUNC void OCCA_RFUNC occaPropertiesSet(occaProperties props,
OCCA_LFUNC int OCCA_RFUNC occaPropertiesHas(occaProperties props,
const char *key);

OCCA_LFUNC occaType OCCA_RFUNC occaPropertiesGet(occaProperties props,
const char *key,
occaType defaultValue);

OCCA_END_EXTERN_C

#endif
5 changes: 5 additions & 0 deletions include/occa/c/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef struct {
int magicHeader;
int type;
occaUDim_t bytes;
char needsFree;

union {
uint8_t uint8_;
Expand All @@ -63,6 +64,8 @@ typedef struct {
typedef occaType occaDevice;
typedef occaType occaKernel;
typedef occaType occaMemory;

typedef occaType occaJson;
typedef occaType occaProperties;

typedef struct {
Expand Down Expand Up @@ -99,6 +102,8 @@ extern const int OCCA_STRING;
extern const int OCCA_DEVICE;
extern const int OCCA_KERNEL;
extern const int OCCA_MEMORY;

extern const int OCCA_JSON;
extern const int OCCA_PROPERTIES;
//======================================

Expand Down
23 changes: 20 additions & 3 deletions include/occa/c/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ namespace occa {
static const int kernel = 17;
static const int memory = 18;

static const int properties = 19;
static const int json = 19;
static const int properties = 20;
}

occaType defaultOccaType();
Expand All @@ -65,6 +66,12 @@ namespace occa {

occaType newOccaType(void *value);

template <>
occaType newOccaType(const occa::primitive &value);

occaType newOccaType(const occa::primitive &value,
const int type);

template <>
occaType newOccaType(const bool &value);

Expand Down Expand Up @@ -102,8 +109,11 @@ namespace occa {
occaType newOccaType(occa::kernel kernel);
occaType newOccaType(occa::memory memory);

template <>
occaType newOccaType(const occa::properties &properties);
occaType newOccaType(const json &json,
const bool needsFree);

occaType newOccaType(const occa::properties &properties,
const bool needsFree);

occaStream newOccaType(occa::stream value);
occaStreamTag newOccaType(occa::streamTag value);
Expand All @@ -114,6 +124,13 @@ namespace occa {
occa::kernel kernel(occaType value);
occa::memory memory(occaType value);

occa::primitive primitive(occaType value);
occa::primitive primitive(occaType value,
const int type);

occa::json& json(occaType value);
occa::json inferJson(occaType value);

occa::properties& properties(occaType value);
const occa::properties& constProperties(occaType value);

Expand Down
6 changes: 4 additions & 2 deletions src/c/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ OCCA_START_EXTERN_C

//---[ Globals & Flags ]----------------
occaProperties OCCA_RFUNC occaSettings() {
return occa::c::newOccaType(occa::settings());
return occa::c::newOccaType(occa::settings(),
false);
}

void OCCA_RFUNC occaPrintModeInfo() {
Expand All @@ -54,7 +55,8 @@ void OCCA_RFUNC occaSetDeviceFromInfo(const char *infos) {
}

occaProperties OCCA_RFUNC occaDeviceProperties() {
return occa::c::newOccaType(occa::deviceProperties());
return occa::c::newOccaType(occa::deviceProperties(),
false);
}

void OCCA_RFUNC occaLoadKernels(const char *library) {
Expand Down
6 changes: 3 additions & 3 deletions src/c/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ const char* OCCA_RFUNC occaDeviceMode(occaDevice device) {

occaProperties OCCA_RFUNC occaDeviceGetProperties(occaDevice device) {
occa::properties &props = occa::c::device(device).properties();
return occa::c::newOccaType(props);
return occa::c::newOccaType(props, false);
}

occaProperties OCCA_RFUNC occaDeviceGetKernelProperties(occaDevice device) {
occa::properties &props = occa::c::device(device).kernelProperties();
return occa::c::newOccaType(props);
return occa::c::newOccaType(props, false);
}

occaProperties OCCA_RFUNC occaDeviceGetMemoryProperties(occaDevice device) {
occa::properties &props = occa::c::device(device).memoryProperties();
return occa::c::newOccaType(props);
return occa::c::newOccaType(props, false);
}

occaUDim_t OCCA_RFUNC occaDeviceMemorySize(occaDevice device) {
Expand Down
Loading

0 comments on commit e27b29e

Please sign in to comment.