Skip to content

Commit d79a7c4

Browse files
Update to match repl
1 parent 2714775 commit d79a7c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+5852
-0
lines changed

ReplAPI.it/conanfile.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from conans import ConanFile, CMake
2+
3+
#####################################################
4+
# Temporarily using nlohmann_json until we can make #
5+
# our own parser #
6+
#####################################################
7+
8+
class ReplAPIItConan(ConanFile):
9+
name = "ReplAPI.it"
10+
version = "0.1"
11+
license = "GPL 3.0"
12+
author = "<Put your name here> <And your email here>"
13+
url = "https://github.com/ReplAPI-it/ReplAPI.it-C"
14+
description = "Wrapper for Repl.it APIs for C++"
15+
topics = ("replit", "graphql", "api")
16+
settings = "os", "compiler", "build_type", "arch"
17+
options = {"shared": [True, False], "fPIC": [True, False]}
18+
default_options = {"shared": False, "fPIC": True}
19+
generators = "cmake"
20+
exports_sources = "src/*"
21+
requires = ("cpr/1.6.2", "nlohmann_json/3.9.1")
22+
23+
def config_options(self):
24+
if self.settings.os == "Windows":
25+
del self.options.fPIC
26+
27+
def build(self):
28+
cmake = CMake(self)
29+
cmake.configure(source_folder="src")
30+
cmake.build()
31+
32+
# Explicit way:
33+
# self.run('cmake %s/hello %s'
34+
# % (self.source_folder, cmake.command_line))
35+
# self.run("cmake --build . %s" % cmake.build_config)
36+
37+
def package(self):
38+
self.copy("*.h", dst="include", src="src")
39+
self.copy("*.lib", dst="lib", keep_path=False)
40+
self.copy("*.dll", dst="bin", keep_path=False)
41+
self.copy("*.dylib*", dst="lib", keep_path=False)
42+
self.copy("*.so", dst="lib", keep_path=False)
43+
self.copy("*.a", dst="lib", keep_path=False)
44+
45+
def package_info(self):
46+
self.cpp_info.libs = ["ReplAPIit"]

ReplAPI.it/src/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(ReplAPI.it CXX)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup()
6+
7+
add_library(ReplAPIit ReplAPIit.cpp)

ReplAPI.it/src/ReplAPIit.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <cpr/cpr.h>
2+
#include <nlohmann/json.hpp>
3+
#include <iostream>
4+
#include "./lib/arraylib/arraylib.h"
5+
#include "ReplAPIit.h"
6+
7+
using namespace adaptX;
8+
using json = nlohmann::json;
9+
10+
namespace lib {
11+
int main() {
12+
cpr::Response r = cpr::Get(cpr::Url{"https://api.github.com/repos/whoshuu/cpr/contributors"},
13+
cpr::Authentication{"user", "pass"},
14+
cpr::Parameters{{"anon", "true"}, {"key", "value"}});
15+
std::cout << r.status_code << "\n"; // 200
16+
std::cout << r.header["content-type"] << "\n"; // application/json; charset=utf-8
17+
std::cout << json::parse(r.text) << "\n"; // JSON text string
18+
}
19+
}
20+
21+
void hashMapTest() {
22+
HashMap<String, String> test;
23+
test.put(String("test"), String("testing 1 2 3"));
24+
std::cout << test.get(String("test")).valueOf();
25+
}
26+
27+
void ReplAPIit(){
28+
#ifdef NDEBUG
29+
std::cout << "ReplAPI.it/0.1: Hello World Release!" <<std::endl;
30+
#else
31+
std::cout << "ReplAPI.it/0.1: Hello World Debug!" <<std::endl;
32+
#endif
33+
lib::main();
34+
hashMapTest();
35+
}

ReplAPI.it/src/ReplAPIit.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#ifdef WIN32
4+
#define ReplAPIit_EXPORT __declspec(dllexport)
5+
#else
6+
#define ReplAPIit_EXPORT
7+
#endif
8+
9+
ReplAPIit_EXPORT void ReplAPIit();
10+
11+
namespace lib {
12+
int main();
13+
}

ReplAPI.it/src/lib/arraylib/array.h

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#pragma once
2+
3+
namespace adaptX {
4+
5+
template <class Type>
6+
class Array
7+
{
8+
public:
9+
Array()
10+
: length(0)
11+
{
12+
_array = (Type*)malloc(length * sizeof(Type));
13+
}
14+
15+
public:
16+
void push(const Type& value)
17+
{
18+
++length;
19+
20+
Type* temp = _array;
21+
22+
_array = (Type*)malloc(length * sizeof(Type));
23+
arrcpy(_array, temp, length - 1);
24+
_array[length - 1] = value;
25+
}
26+
27+
Type get(int index)
28+
{
29+
return _array[index];
30+
}
31+
32+
void set(int index, Type value)
33+
{
34+
_array[index] = value;
35+
}
36+
37+
void remove(int index)
38+
{
39+
--length;
40+
41+
Type* temp = _array;
42+
_array = (Type*) malloc(length * sizeof(Type));
43+
44+
//int j = 0;
45+
for (int i = 0, j = 0; i < length + 1; ++i)
46+
{
47+
if (i != index)
48+
{
49+
_array[j] = temp[i];
50+
++j;
51+
}
52+
}
53+
}
54+
55+
Type pop()
56+
{
57+
--length;
58+
59+
Type* temp = _array;
60+
_array = (Type*)malloc(length * sizeof(Type));
61+
62+
//int j = 0;
63+
for (int i = 0, j = 0; i < length; ++i)
64+
{
65+
_array[j] = temp[i];
66+
++j;
67+
}
68+
69+
return temp[length];
70+
}
71+
72+
void clear()
73+
{
74+
_array = (Type*)malloc(0);
75+
length = 0;
76+
}
77+
78+
// added const modifier
79+
int size() const
80+
{
81+
return length;
82+
}
83+
84+
// added const ref param and const modifier
85+
int indexOf(const Type& value) const
86+
{
87+
for (int i = 0; i < length; ++i)
88+
{
89+
if (value == _array[i])
90+
return i;
91+
}
92+
93+
return -1;
94+
}
95+
96+
private:
97+
Type* _array;
98+
int length;// = 0;
99+
100+
private:
101+
// added const param
102+
void arrcpy(Type* value1, const Type* value2, int l)
103+
{
104+
for (int i = 0; i < l; ++i)
105+
value1[i] = value2[i];
106+
};
107+
};
108+
109+
} // namespace adaptX
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
#include "./array.h"
3+
#include "./hashmap.h"
4+
#include "./string.h"

ReplAPI.it/src/lib/arraylib/hashmap.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include "./array.h"
4+
5+
namespace adaptX {
6+
7+
template <class T1, class T2>
8+
class HashMap
9+
{
10+
public:
11+
void put(const T1& key, const T2& value)
12+
{
13+
if (keys.indexOf(key) != -1)
14+
{
15+
values.set(keys.indexOf(key), value);
16+
}
17+
else
18+
{
19+
keys.push(key);
20+
values.push(value);
21+
}
22+
}
23+
24+
// added const ref param and cosnt modifier
25+
// Later removed because of errors thrown because of it
26+
T2 get(T1 key)
27+
{
28+
if (keys.indexOf(key) != -1)
29+
return values.get(keys.indexOf(key));
30+
else
31+
return (T2)0;
32+
}
33+
34+
private:
35+
Array<T1> keys;
36+
Array<T2> values;
37+
};
38+
39+
} //namespace adaptX

ReplAPI.it/src/lib/arraylib/string.h

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#pragma once
2+
3+
#include <string.h> // strlen, strncmp
4+
5+
namespace adaptX {
6+
7+
class String
8+
{
9+
private:
10+
int getLength(char* str) const
11+
{
12+
for (int i = 0; true; ++i)
13+
{
14+
if (str[i] == '\0')
15+
return i;
16+
}
17+
/*
18+
int i = 0;
19+
while (true)
20+
{
21+
if (str[i] == '\0')
22+
return i;
23+
24+
++i;
25+
}
26+
*/
27+
};
28+
29+
public:
30+
// const char* initializer ??
31+
String(char* initializer)
32+
: _value(initializer), _length(getLength(initializer))
33+
{
34+
//_value = initializer;
35+
//_length = getLength(initializer);
36+
};
37+
38+
int length() const
39+
{
40+
return _length;
41+
}
42+
43+
char get(int index) const
44+
{
45+
return _value[index];
46+
}
47+
48+
// const char* string
49+
void operator=(char* str)
50+
{
51+
_value = str;
52+
_length = getLength(str);
53+
}
54+
55+
// const char* str
56+
void operator+=(char* str)
57+
{
58+
int _len = getLength(str);
59+
60+
char* temp = _value;
61+
_value = (char*)malloc((_length+_len) * sizeof(char*));
62+
63+
int i;
64+
65+
for (i = 0; i < _length; ++i)
66+
_value[i] = temp[i];
67+
68+
for (int j = 0; j < _len; ++i, ++j)
69+
_value[i] = str[j];
70+
71+
//_value[i] = '\0';
72+
_length += _len;
73+
}
74+
75+
void operator+=(char str)
76+
{
77+
char* temp = _value;
78+
_value = (char*)malloc((_length+1) * sizeof(char*));
79+
80+
int i;
81+
82+
for (i = 0; i < _length; ++i)
83+
_value[i] = temp[i];
84+
85+
for (int j = 0; j < 1; ++i, ++j)
86+
_value[i] = str;
87+
88+
_length += 1;
89+
}
90+
91+
// added this
92+
bool operator==(const char* str) const
93+
{
94+
return !strncmp(_value, str, strlen(str));
95+
}
96+
97+
98+
bool operator==(adaptX::String str) const
99+
{
100+
return !strncmp(_value, str.valueOf(), strlen(str.valueOf()));
101+
}
102+
103+
char* valueOf()
104+
{
105+
return _value;
106+
}
107+
108+
private:
109+
char* _value;
110+
int _length;
111+
};
112+
113+
} //namespace adaptX
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "json_object.h"
2+
3+
JSONObject::JSONObject(String data, Types _type) {
4+
type = _type;
5+
6+
switch (type)
7+
{
8+
case Types::OBJECT:
9+
objData = parseObj(data);
10+
break;
11+
case Types::ARRAY:
12+
objData = parseArray(data);
13+
break;
14+
}
15+
}

0 commit comments

Comments
 (0)