Skip to content

Commit a1db5bd

Browse files
committed
support for json only
export directives
1 parent 4afbf05 commit a1db5bd

File tree

12 files changed

+110
-26
lines changed

12 files changed

+110
-26
lines changed

src/include/export.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
JSON to OSC Library
3+
Copyright (C) 2013 Grame
4+
5+
This Source Code Form is subject to the terms of the Mozilla Public
6+
License, v. 2.0. If a copy of the MPL was not distributed with this
7+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
8+
9+
Grame Research Laboratory, 11, cours de Verdun Gensoul 69002 Lyon - France
10+
11+
12+
*/
13+
14+
#ifndef export__
15+
#define export__
16+
17+
18+
#if __MINGW32__
19+
# define jsonexport
20+
21+
#elif defined(WIN32) && !defined(GCC)
22+
23+
# ifdef JSONExport
24+
# define jsonexport _declspec (dllexport)
25+
# else
26+
# define jsonexport _declspec (dllimport)
27+
# endif
28+
29+
#else
30+
31+
# ifdef JSONExport
32+
# define jsonexport __attribute__ ((visibility("default")))
33+
34+
# else
35+
# define jsonexport
36+
# endif
37+
38+
#endif
39+
40+
41+
#endif

src/include/json_osc.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Multiple messages can be included in a single JSON : they should be encoded usin
8989
#define json_osc__
9090

9191
#include "osc2json.h"
92+
#include "export.h"
9293

9394
namespace json
9495
{
@@ -106,13 +107,13 @@ enum { kNoError, kSyntaxError, kIncorrectParameter, kNoSuchFile, kCantBindSocket
106107
\note The function does not return since it listens to a socket.
107108
Thus the caller is responsible of calling the function in a separate thread when appropriate.
108109
*/
109-
int start_osc2json (osc2json* client, int port, osc_listener** listener);
110+
jsonexport int start_osc2json (osc2json* client, int port, osc_listener** listener);
110111

111112
/**
112113
\brief stops osc to json conversion
113114
\param listener an osc listener that has been previously returned by start_osc2json
114115
*/
115-
void stop_osc2json (osc_listener* listener);
116+
jsonexport void stop_osc2json (osc_listener* listener);
116117

117118
/**
118119
\brief starts json to osc conversion
@@ -122,36 +123,36 @@ void stop_osc2json (osc_listener* listener);
122123
\note sending a json string including a destination and/or a udp port changes
123124
the default destination and/or default udp port number.
124125
*/
125-
osc_stream* start_json2osc (const char* defaultDest, int defaultPort);
126+
jsonexport osc_stream* start_json2osc (const char* defaultDest, int defaultPort);
126127

127128
/**
128129
\brief sends a json string as osc packets
129130
\param json the json code
130131
\param stream an osc stream that has been previously returned by start_json2osc
131132
\return an error code or kNoError when no error
132133
*/
133-
int send (const char * json, osc_stream* stream);
134+
jsonexport int send (const char * json, osc_stream* stream);
134135

135136
/**
136137
\brief sends a json file as osc packets
137138
\param file the file path name
138139
\param stream an osc stream that has been previously returned by start_json2osc
139140
\return an error code or kNoError when no error
140141
*/
141-
int sendfile (const char * file, osc_stream* stream);
142+
jsonexport int sendfile (const char * file, osc_stream* stream);
142143

143144
/**
144145
\brief stops json to osc conversion
145146
\param stream an osc stream that has been previously returned by start_json2osc
146147
*/
147-
void stop_json2osc (osc_stream* stream);
148+
jsonexport void stop_json2osc (osc_stream* stream);
148149

149150
/**
150151
\brief gives a textual description of an error
151152
\param error an error code
152153
\return a string
153154
*/
154-
const char* error_string (int error);
155+
jsonexport const char* error_string (int error);
155156

156157

157158
} // end namespoace

src/json/json2osc.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
#include "json2osc.h"
1717
#include "json_object.h"
18-
#include "osc_stream.h"
18+
#ifndef JSON_ONLY
19+
# include "osc_stream.h"
20+
#endif
1921

2022
using namespace std;
2123

src/json/json_array.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ json_array::~json_array()
3030
}
3131

3232
// --------------------------------------------------------------
33+
#ifndef JSON_ONLY
3334
void json_array::print(osc_stream& out) const
3435
{
3536
unsigned int n = fValues.size();
3637
for (unsigned int i=0; i < n; i++) {
3738
fValues[i]->print(out);
3839
}
3940
}
41+
#endif
4042

4143
// --------------------------------------------------------------
4244
void json_array::print(json_stream& out) const

src/json/json_array.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define json_array__
1717

1818
#include <vector>
19+
#include "export.h"
1920

2021
namespace json
2122
{
@@ -27,7 +28,7 @@ class osc_stream;
2728
/*!
2829
\brief a json array, as defined by the json spec (see http://json.org/)
2930
*/
30-
class json_array
31+
class jsonexport json_array
3132
{
3233
std::vector<const json_value *> fValues;
3334

@@ -37,7 +38,9 @@ class json_array
3738

3839
virtual void add(const json_value * val) { fValues.push_back(val); }
3940
virtual void print(json_stream& out) const;
41+
#ifndef JSON_ONLY
4042
virtual void print(osc_stream& out) const;
43+
#endif
4144
};
4245

4346
} // end namespace

src/json/json_element.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <string>
1919
#include "json_value.h"
2020
#include "json_stream.h"
21+
#include "export.h"
2122

2223
namespace json
2324
{
@@ -27,7 +28,7 @@ class osc_stream;
2728
/*!
2829
\brief a json element, actually a pair name/value
2930
*/
30-
class json_element
31+
class jsonexport json_element
3132
{
3233
std::string fName;
3334
const json_value * fValue;

src/json/json_object.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#include "json_object.h"
1515
#include "json_stream.h"
1616
#include "json2osc.h"
17-
#include "osc_stream.h"
17+
#ifndef JSON_ONLY
18+
# include "osc_stream.h"
19+
#endif
1820

1921
using namespace std;
2022
namespace json
@@ -61,6 +63,7 @@ void json_object::print(json_stream& out) const
6163
};
6264

6365
// --------------------------------------------------------------
66+
#ifndef JSON_ONLY
6467
void json_object::print(osc_stream& out) const
6568
{
6669
const json_element* list = getKey (kOSCMarker);
@@ -97,5 +100,6 @@ void json_object::print(osc_stream& out) const
97100
}
98101
}
99102
}
103+
#endif
100104

101105
} // end namespace

src/json/json_object.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <vector>
1919
#include "json_element.h"
20+
#include "export.h"
2021

2122
namespace json
2223
{
@@ -27,7 +28,7 @@ class osc_stream;
2728
/*!
2829
\brief a json object, as defined by the json spec (see http://json.org/)
2930
*/
30-
class json_object
31+
class jsonexport json_object
3132
{
3233
std::vector<const json_element*> fElements;
3334

@@ -43,8 +44,10 @@ class json_object
4344

4445
/// \brief print the element to the json stream (for indented output)
4546
virtual void print(json_stream& out) const;
47+
#ifndef JSON_ONLY
4648
/// \brief print the element to the osc stream
4749
virtual void print(osc_stream& out) const;
50+
#endif
4851
/// \brief print the element to the output stream
4952
virtual void print(std::ostream& out) const;
5053
};

src/json/json_stream.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define json_stream__
1717

1818
#include <ostream>
19+
#include "export.h"
1920

2021
namespace json
2122
{
@@ -26,7 +27,7 @@ namespace json
2627
\brief to be used in place of std::endl
2728
to provide indentation of the json output.
2829
*/
29-
class json_endl {
30+
class jsonexport json_endl {
3031
private:
3132
int fIndent;
3233
public:
@@ -51,7 +52,7 @@ inline std::ostream& operator<< (std::ostream& os, const json_endl& eol) { eol.p
5152
\internal
5253
\brief a stream that embed a special endl for output formatting
5354
*/
54-
class json_stream {
55+
class jsonexport json_stream {
5556
std::ostream& fStream;
5657
json_endl fEndl;
5758
public:
@@ -63,8 +64,8 @@ class json_stream {
6364
json_endl& nl() { return fEndl; }
6465
};
6566

66-
class json_array;
67-
class json_object;
67+
class jsonexport json_array;
68+
class jsonexport json_object;
6869
/// \private
6970
json_stream& operator<< (json_stream& os, const json_object* obj);
7071
/// \private

src/json/json_value.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ namespace json
2525
//--------------------------------------------------------------------------
2626
json_object_value::~json_object_value() { delete fValue; }
2727
void json_object_value::print(json_stream& out) const { out << fValue; }
28+
#ifndef JSON_ONLY
2829
void json_object_value::print(osc_stream& out) const { fValue->print(out); }
30+
#endif
2931

3032
//--------------------------------------------------------------------------
3133
json_array_value::~json_array_value() { delete fValue; }
3234
void json_array_value::print(json_stream& out) const { out << fValue; }
35+
#ifndef JSON_ONLY
3336
void json_array_value::print(osc_stream& out) const { fValue->print(out); }
37+
#endif
3438

3539

3640
//--------------------------------------------------------------------------

0 commit comments

Comments
 (0)