Skip to content

Commit 94dece2

Browse files
committed
Cleaned up header
1 parent ee6ba45 commit 94dece2

File tree

2 files changed

+39
-30
lines changed

2 files changed

+39
-30
lines changed

DynamicArray/dynamic.h

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,95 @@
1-
#pragma once
1+
// Dynamic Array Header /////////////////////////////////
2+
//
3+
// Based on the MT4R dll by Bernd Kreuss, distributed under GNU license
4+
// in the Source folder. See RTest.c for example usage.
5+
26
#ifndef dynamic_h
37
#define dynamic_h
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
413
#ifdef WIN32
514

6-
#include<Windows.h>
715
#ifdef DYNAMICARRAY_EXPORTS
8-
#define DLLFUNC_C extern "C" __declspec(dllexport)
16+
#define DA_FUNC __declspec(dllexport)
917
#else
10-
#define DLLFUNC_C extern "C" __declspec(dllimport)
18+
#define DA_FUNC __declspec(dllimport)
1119
#endif
12-
#define API(x,y) // force ignorance
13-
#define DynamicArray // force ignorance
14-
//#define __POINTER__ void*
20+
#define API(x,y) // ignore
21+
#define DynamicArray // ignore
1522

1623
#else // if Zorro Trading Automation
1724
#include <windows.h> // Zorro windows API header
18-
//#define __POINTER__ void*
19-
#define DLLFUNC_C // force ignorance
25+
#define DA_FUNC // ignore
2026
#endif
2127

2228
// ** CREATION, EXISTENCE, AND DELETION **
2329

2430
// Creates a new dynamic array. Each element of the array has size of sizeof_type.
2531
// Returns a handle to the array.
26-
DLLFUNC_C int __cdecl da_new(int sizeof_type);
27-
API(da_new,DynamicArray)
32+
DA_FUNC int da_new(int sizeof_type);
33+
API(da_new, DynamicArray)
2834

2935
// Confirms the existence of a dynamic array.
30-
DLLFUNC_C bool __cdecl da_exists(int handle);
36+
DA_FUNC bool da_exists(int handle);
3137
API(da_exists, DynamicArray)
3238

3339
// De-allocates the dynamic vector from memory
3440
// After this function, the handle will no longer be recognized.
3541
// Returns true if completed, false if handle not recognized.
36-
DLLFUNC_C bool __cdecl da_delete(int handle);
42+
DA_FUNC bool da_delete(int handle);
3743
API(da_delete, DynamicArray)
3844

3945
// De-allocates **all** dynamic vectors from memory.
4046
// After this function, **all handles** will no longer be recognized.
41-
DLLFUNC_C void __cdecl da_delete_all();
47+
DA_FUNC void da_delete_all();
4248
API(da_delete_all, DynamicArray)
4349

4450
// ** SIZING **
4551

4652
// Returns the size of the dynamic array, in number of elements,
4753
// or zero if the handle does not exist.
48-
DLLFUNC_C int __cdecl da_size(int handle);
54+
DA_FUNC int da_size(int handle);
4955
API(da_size, DynamicArray)
5056

5157
// Returns the capacity of the dynamic array, in number of elements,
5258
// or zero if the handle does not exist.
53-
DLLFUNC_C int __cdecl da_capacity(int handle);
59+
DA_FUNC int da_capacity(int handle);
5460
API(da_capacity, DynamicArray)
5561

5662
// Returns the max number of elements the dynamic array is capable of holding,
5763
// or zero if the handle does not exist.
58-
DLLFUNC_C int __cdecl da_max_size(int handle);
64+
DA_FUNC int da_max_size(int handle);
5965
API(da_max_size, DynamicArray)
6066

6167
// Returns true if an existing array is empty
6268
// or false if either the array has elements or does not exist.
63-
DLLFUNC_C bool __cdecl da_is_empty(int handle);
69+
DA_FUNC bool da_is_empty(int handle);
6470
API(da_is_empty, DynamicArray)
6571

6672
// Returns the size of each individual element,
6773
// or zero if the handle does not exist.
68-
DLLFUNC_C int __cdecl da_typesize(int handle);
74+
DA_FUNC int da_typesize(int handle);
6975
API(da_typesize, DynamicArray)
7076

7177
// Resizes the array in terms of number of elements.
7278
// Behavior is similar to that of std::vector.
7379
// Returns true if completed, false if handle not recognized.
74-
DLLFUNC_C bool __cdecl da_resize(int handle, int nSize);
80+
DA_FUNC bool da_resize(int handle, int nSize);
7581
API(da_resize, DynamicArray)
7682

7783
// Pre-allocates contiguous memory without changing the size of the dynamic array.
7884
// Behavior is similar to that of std::vector.
7985
// Returns true if completed, false if handle not recognized.
80-
DLLFUNC_C bool __cdecl da_reserve(int handle, int nSize);
86+
DA_FUNC bool da_reserve(int handle, int nSize);
8187
API(da_reserve, DynamicArray)
8288

8389
// At the STL implementation's discretion, the capacity will be reduced to the size.
8490
// Behavior is similar to that of std::vector.
8591
// handle: Dynamic array handle.
86-
DLLFUNC_C bool __cdecl da_shrink_to_fit(int handle);
92+
DA_FUNC bool da_shrink_to_fit(int handle);
8793
API(da_shrink_to_fit, DynamicArray)
8894

8995
// ** DATA ACCESS **
@@ -94,7 +100,7 @@ API(da_shrink_to_fit, DynamicArray)
94100
// Note: if size==0, no pointer can be returned.
95101
// handle: Dynamic array handle.
96102
// The pointer should be assumed invalid once the array is resized or reserved.
97-
DLLFUNC_C void* __cdecl da_data(int handle, int nElement);
103+
DA_FUNC void* da_data(int handle, int nElement);
98104
API(da_data, DynamicArray)
99105

100106
// ** ADD ELEMENTS **
@@ -103,8 +109,8 @@ API(da_data, DynamicArray)
103109
// handle: Dynamic array handle.
104110
// Returns the new size of the dynamic array, in number of elements,
105111
// or zero if the handle does not exist.
106-
//DLLFUNC_C int da_push_back(int handle, void* pElement);
107-
DLLFUNC_C int __cdecl da_push_back(int handle, void* pElement);
112+
//DA_FUNC int da_push_back(int handle, void* pElement);
113+
DA_FUNC int da_push_back(int handle, void* pElement);
108114
API(da_push_back, DynamicArray)
109115

110116
// Inserts elements to a given position in the dynamic array.
@@ -115,8 +121,8 @@ API(da_push_back, DynamicArray)
115121
// where 0 = front and size = back.
116122
// numElements: Number of fixed-size elements to be inserted. Must be 1 or greater.
117123
// Returns the new size if completed or zero if unsuccessful.
118-
//DLLFUNC_C int da_insert(int handle, void* pElement, int nPosition, int numElements);
119-
DLLFUNC_C int __cdecl da_insert(int handle, void* pElement, int nPosition, int numElements);
124+
//DA_FUNC int da_insert(int handle, void* pElement, int nPosition, int numElements);
125+
DA_FUNC int da_insert(int handle, void* pElement, int nPosition, int numElements);
120126
API(da_insert, DynamicArray)
121127

122128
// ** REMOVE ELEMENTS **
@@ -128,21 +134,24 @@ API(da_insert, DynamicArray)
128134
// where 0 = front and size = back.
129135
// numElements: Number of fixed-size elements to be deleted. Must be 1 or greater.
130136
// For example, nPosition = 2, numElements = 3 :: 2 thru 5 get deleted.
131-
DLLFUNC_C int __cdecl da_erase(int handle, int nPosition, int numElements);
137+
DA_FUNC int da_erase(int handle, int nPosition, int numElements);
132138
API(da_erase, DynamicArray)
133139

134140
// Removes the last element of the dynamic array.
135141
// handle: Dynamic array handle.
136142
// Returns the new size if completed or zero if unsuccessful.
137-
DLLFUNC_C int __cdecl da_pop_back(int handle);
143+
DA_FUNC int da_pop_back(int handle);
138144
API(da_pop_back, DynamicArray)
139145

140146
// Clears the contents of the dynamic array.
141147
// (The size become zero but not the capacity per se.)
142148
// handle: Dynamic array handle.
143149
// Returns true if successful or false if handle not recognized.
144-
DLLFUNC_C bool __cdecl da_clear(int handle);
150+
DA_FUNC bool da_clear(int handle);
145151
API(da_clear, DynamicArray)
146152

153+
#ifdef __cplusplus
154+
}
155+
#endif
147156

148157
#endif // dynamic_h
-8 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)