Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit fb49162

Browse files
author
Andrew Bennett
committed
Moved Visualization into a frameork, included a test class
1 parent cbfa9ff commit fb49162

31 files changed

+6237
-13
lines changed

Core/BBContext.cpp

+38-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "BBContext.h"
2+
23
#include "BBPatchCollection.h"
34
#include "BBPatch.h"
5+
#include "BBIndexSet.h"
6+
47
#include "BBCore.h"
58

69
#include <stdexcept>
@@ -11,7 +14,8 @@
1114
BB::Context::Context()
1215
: m_class_context(NULL),
1316
m_class_patch(NULL),
14-
m_class_patch_collection(NULL)
17+
m_class_patch_collection(NULL),
18+
m_class_index_set(NULL)
1519
{
1620
JSObjectRef object;
1721

@@ -23,6 +27,7 @@ BB::Context::Context()
2327

2428
this->patchClass();
2529
this->patchCollectionClass();
30+
this->indexSetClass();
2631
}
2732

2833
BB::Context::~Context()
@@ -33,6 +38,8 @@ BB::Context::~Context()
3338
JSClassRelease(this->m_class_patch);
3439
if (this->m_class_patch_collection != NULL)
3540
JSClassRelease(this->m_class_patch_collection);
41+
if (this->m_class_index_set != NULL)
42+
JSClassRelease(this->m_class_index_set);
3643

3744
JSGlobalContextRelease(this->m_context);
3845
}
@@ -80,6 +87,10 @@ std::string BB::Context::getString(JSValueRef value) const throw(BB::Exception)
8087
return &buffer[0];
8188
}
8289

90+
#pragma mark -
91+
#pragma mark JS Class Definitions
92+
#pragma mark -
93+
8394
JSClassRef BB::Context::patchClass()
8495
{
8596
if (this->m_class_patch == NULL)
@@ -89,7 +100,7 @@ JSClassRef BB::Context::patchClass()
89100

90101
this->m_class_patch = JSClassCreate(&BB::Patch::Definition);
91102

92-
constructor_string = JSStringCreateWithUTF8CString("Patch");
103+
constructor_string = JSStringCreateWithUTF8CString(BB::Patch::Definition.className);
93104
constructor = JSObjectMakeConstructor(this->m_context, NULL,
94105
BB::Patch::Constructor);
95106
global = JSContextGetGlobalObject(this->m_context);
@@ -113,7 +124,7 @@ JSClassRef BB::Context::patchCollectionClass()
113124

114125
this->m_class_patch_collection = JSClassCreate(&BB::PatchCollection::Definition);
115126

116-
constructor_string = JSStringCreateWithUTF8CString("PatchCollection");
127+
constructor_string = JSStringCreateWithUTF8CString(BB::PatchCollection::Definition.className);
117128
constructor = JSObjectMakeConstructor(this->m_context, NULL,
118129
BB::PatchCollection::Constructor);
119130
global = JSContextGetGlobalObject(this->m_context);
@@ -128,6 +139,30 @@ JSClassRef BB::Context::patchCollectionClass()
128139
return this->m_class_patch_collection;
129140
}
130141

142+
JSClassRef BB::Context::indexSetClass()
143+
{
144+
if (this->m_class_index_set == NULL)
145+
{
146+
JSObjectRef constructor, global;
147+
JSStringRef constructor_string;
148+
149+
this->m_class_index_set = JSClassCreate(&BB::IndexSet::Definition);
150+
151+
constructor_string = JSStringCreateWithUTF8CString(BB::IndexSet::Definition.className);
152+
constructor = JSObjectMakeConstructor(this->m_context, NULL,
153+
BB::IndexSet::Constructor);
154+
global = JSContextGetGlobalObject(this->m_context);
155+
JSObjectSetProperty(this->m_context, global,
156+
constructor_string, constructor,
157+
kJSPropertyAttributeReadOnly |
158+
kJSPropertyAttributeDontEnum |
159+
kJSPropertyAttributeDontDelete,
160+
NULL);
161+
JSStringRelease(constructor_string);
162+
}
163+
return this->m_class_index_set;
164+
}
165+
131166
#pragma mark -
132167
#pragma mark Evaluate Scripts
133168

Core/BBContext.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace BB
1818

1919
JSClassRef patchClass();
2020
JSClassRef patchCollectionClass();
21+
JSClassRef indexSetClass();
2122

2223
JSValueRef evaluateScript(const std::string& string) const throw(BB::Exception);
2324
JSValueRef evaluateScriptFromFile(const std::string& filename) const throw(BB::Exception);
@@ -30,7 +31,7 @@ namespace BB
3031

3132
void throwException(JSValueRef except) const throw(BB::Exception);
3233
void throwException(const std::string& description) const throw(BB::Exception);
33-
34+
3435
JSObjectRef createFunction(const std::string& source) throw(BB::Exception);
3536

3637
static BB::Context* FromJS(JSContextRef ctx);
@@ -57,6 +58,7 @@ namespace BB
5758
JSClassRef m_class_context;
5859
JSClassRef m_class_patch_collection;
5960
JSClassRef m_class_patch;
61+
JSClassRef m_class_index_set;
6062
JSGlobalContextRef m_context;
6163
};
6264
}

Core/BBCore.h

+18-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33

44
#ifdef __cplusplus
55
extern "C" {
6+
7+
#include <cstdlib>
8+
9+
#else
10+
11+
#include <stdlib.h>
12+
613
#endif
714

815
typedef struct _bb_context * bb_context;
916
typedef struct _bb_patch * bb_patch;
1017
typedef struct _bb_patch_collection * bb_patch_collection;
1118

12-
1319
#pragma mark -
1420
#pragma mark Context
1521
#pragma mark -
@@ -33,20 +39,24 @@ extern "C" {
3339
void bbPatchRemoveInput(bb_patch patch, const char * name);
3440
void bbPatchRemoveOutput(bb_patch patch, const char * name);
3541

36-
char * bbPatchGetInputAsString(bb_patch ptch, const char * name);
37-
double bbPatchGetInputAsNumber(bb_patch ptch, const char * name);
38-
char * bbPatchGetOutputAsString(bb_patch ptch, const char * name);
39-
double bbPatchGetOutputAsNumber(bb_patch ptch, const char * name);
42+
char * bbPatchGetInputAsString(bb_patch patch, const char * name);
43+
double bbPatchGetInputAsNumber(bb_patch patch, const char * name);
44+
char * bbPatchGetOutputAsString(bb_patch patch, const char * name);
45+
double bbPatchGetOutputAsNumber(bb_patch patch, const char * name);
4046

4147
void bbPatchConnect(bb_patch patch_in, const char * input,
4248
bb_patch patch_out, const char * output);
43-
void bbPatchDisconnectInput(bb_patch ptch, const char * name);
44-
void bbPatchDisconnectOutput(bb_patch ptch, const char * name);
49+
void bbPatchDisconnectInput(bb_patch patch, const char * name);
50+
void bbPatchDisconnectOutput(bb_patch patch, const char * name);
51+
52+
void bbPatchCopyInputs(bb_patch patch, const char * name_ptr[], size_t * size_ptr);
53+
void bbPatchCopyOutputs(bb_patch patch, const char * name_ptr[], size_t * size_ptr);
54+
void bbPatchCopyConnections(bb_patch patch, bb_patch * from_ptr, const char * name_ptr[]);
4555

4656
#pragma mark -
4757
#pragma mark Patch Collection
4858
#pragma mark -
49-
59+
5060
bb_patch_collection bbPatchCollectionCreate(bb_context ctx);
5161
bb_patch_collection bbPatchCollectionCreateFromFile(bb_context ctx, const char * filename);
5262
void bbPatchCollectionDestroy(bb_patch_collection collection);

0 commit comments

Comments
 (0)