Skip to content

Commit 0589ec8

Browse files
committed
Apply formatting to examples
1 parent 93eb0f2 commit 0589ec8

19 files changed

+242
-227
lines changed

examples/GetAllStreams.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* resolved and displayed. This is useful for browsing applications.
1111
*/
1212

13-
int main(int argc, char* argv[]) {
13+
int main(int argc, char *argv[]) {
1414
try {
1515
std::cout << "Here is a one-shot resolve of all current streams:" << std::endl;
1616

@@ -54,7 +54,7 @@ int main(int argc, char* argv[]) {
5454
std::this_thread::sleep_for(std::chrono::seconds(1));
5555
}
5656

57-
} catch (std::exception& e) { std::cerr << "Got an exception: " << e.what() << std::endl; }
57+
} catch (std::exception &e) { std::cerr << "Got an exception: " << e.what() << std::endl; }
5858
std::cout << "Press any key to exit. " << std::endl;
5959
std::cin.get();
6060
return 0;

examples/GetFullinfo.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
* resolve functions only includes the core information otherwise.
88
*/
99

10-
int main(int argc, char* argv[]) {
10+
int main(int argc, char *argv[]) {
1111
std::string field, value;
1212
if (argc != 3) {
1313
std::cout << "This connects to a stream which has a particular value for a given field and "
14-
"displays its full stream_info contentss."
15-
<< std::endl;
14+
"displays its full stream_info contentss."
15+
<< std::endl;
1616
std::cout << "Please enter a field name and the desired value (e.g. \"type EEG\" (without "
17-
"the quotes)):"
18-
<< std::endl;
17+
"the quotes)):"
18+
<< std::endl;
1919
std::cin >> field >> value;
2020
} else {
2121
field = argv[1];
@@ -36,11 +36,11 @@ int main(int argc, char* argv[]) {
3636

3737
// get & display the info
3838
std::cout << "The information about this stream is displayed in the following: "
39-
<< std::endl;
39+
<< std::endl;
4040
lsl::stream_info info = inlet.info();
4141
std::cout << info.as_xml() << std::endl;
4242

43-
} catch (std::exception& e) { std::cerr << "Got an exception: " << e.what() << std::endl; }
43+
} catch (std::exception &e) { std::cerr << "Got an exception: " << e.what() << std::endl; }
4444
std::cout << "Press any key to exit. " << std::endl;
4545
std::cin.get();
4646
return 0;

examples/GetTimeCorrection.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
* should be approx. 0 (up to some tolerance).
1010
*/
1111

12-
int main(int argc, char* argv[]) {
12+
int main(int argc, char *argv[]) {
1313
std::string field, value;
1414
if (argc != 3) {
1515
std::cout << "This connects to a stream which has a particular value for a given field and "
16-
"gets the time-synchronization information for it."
17-
<< std::endl;
16+
"gets the time-synchronization information for it."
17+
<< std::endl;
1818
std::cout << "Please enter a field name and the desired value (e.g. \"type EEG\" (without "
19-
"the quotes)):"
20-
<< std::endl;
19+
"the quotes)):"
20+
<< std::endl;
2121
std::cin >> field >> value;
2222
} else {
2323
field = argv[1];
@@ -38,13 +38,13 @@ int main(int argc, char* argv[]) {
3838

3939
// start receiving & displaying the data
4040
std::cout << "Press [Enter] to query a new correction value (clocks may drift)..."
41-
<< std::endl;
41+
<< std::endl;
4242
while (true) {
4343
std::cout << inlet.time_correction() << std::endl;
4444
std::cin.get();
4545
}
4646

47-
} catch (std::exception& e) { std::cerr << "Got an exception: " << e.what() << std::endl; }
47+
} catch (std::exception &e) { std::cerr << "Got an exception: " << e.what() << std::endl; }
4848
std::cout << "Press any key to exit. " << std::endl;
4949
std::cin.get();
5050
return 0;

examples/HandleMetaData.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
#include <iostream>
22
#include <lsl_cpp.h>
33

4-
int main(int argc, char* argv[]) {
4+
int main(int argc, char *argv[]) {
55
try {
66
// create a new stream_info and declare some meta-data (in accordance with XDF format)
7-
const char* name = argc > 1 ? argv[1] : "MetaTester";
7+
const char *name = argc > 1 ? argv[1] : "MetaTester";
88
lsl::stream_info info(name, "EEG", 8, 100, lsl::cf_float32, "myuid323457");
99
lsl::xml_element chns = info.desc().append_child("channels");
10-
const char* labels[] = {"C3", "C4", "Cz", "FPz", "POz", "CPz", "O1", "O2"};
11-
for (const char* label : labels)
10+
const char *labels[] = {"C3", "C4", "Cz", "FPz", "POz", "CPz", "O1", "O2"};
11+
for (const char *label : labels)
1212
chns.append_child("channel")
13-
.append_child_value("label", label)
14-
.append_child_value("unit", "microvolts")
15-
.append_child_value("type", "EEG");
13+
.append_child_value("label", label)
14+
.append_child_value("unit", "microvolts")
15+
.append_child_value("type", "EEG");
1616
info.desc().append_child_value("manufacturer", "SCCN");
1717
info.desc()
18-
.append_child("cap")
19-
.append_child_value("name", "EasyCap")
20-
.append_child_value("size", "54")
21-
.append_child_value("labelscheme", "10-20");
18+
.append_child("cap")
19+
.append_child_value("name", "EasyCap")
20+
.append_child_value("size", "54")
21+
.append_child_value("labelscheme", "10-20");
2222

2323
// create outlet for the stream
2424
lsl::stream_outlet outlet(info);
@@ -32,17 +32,17 @@ int main(int argc, char* argv[]) {
3232
// get the full stream info (including custom meta-data) and dissect it
3333
lsl::stream_info inf = inlet.info();
3434
std::cout << "The stream's XML meta-data is: \n"
35-
<< inf.as_xml()
36-
<< "\nThe manufacturer is: " << inf.desc().child_value("manufacturer")
37-
<< "\nThe cap circumference is: " << inf.desc().child("cap").child_value("size")
38-
<< "\nThe channel labels are as follows:\n";
35+
<< inf.as_xml()
36+
<< "\nThe manufacturer is: " << inf.desc().child_value("manufacturer")
37+
<< "\nThe cap circumference is: " << inf.desc().child("cap").child_value("size")
38+
<< "\nThe channel labels are as follows:\n";
3939
lsl::xml_element ch = inf.desc().child("channels").child("channel");
4040
for (int k = 0; k < info.channel_count(); k++) {
4141
std::cout << " " << ch.child_value("label") << std::endl;
4242
ch = ch.next_sibling();
4343
}
4444

45-
} catch (std::exception& e) { std::cerr << "Got an exception: " << e.what() << std::endl; }
45+
} catch (std::exception &e) { std::cerr << "Got an exception: " << e.what() << std::endl; }
4646
std::cout << "Press any key to exit. " << std::endl;
4747
std::cin.get();
4848
return 0;

examples/HandleMetaDataC.c

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,52 @@
11
#include <lsl_c.h>
22
#include <stdio.h>
33

4-
int main(int argc, char* argv[]) {
5-
int c; /* channel index */
6-
lsl_xml_ptr desc,chns,chn,cap; /* some xml element pointers */
7-
lsl_outlet outlet; /* stream outlet */
8-
lsl_streaminfo info,inf; /* streaminfo objects */
9-
lsl_inlet inlet; /* a stream inlet to get samples from */
10-
int errcode; /* error code (lsl_lost_error or timeouts) */
11-
const char* labels[] = {"C3","C4","Cz","FPz","POz","CPz","O1","O2"};
4+
int main(int argc, char *argv[]) {
5+
int c; /* channel index */
6+
lsl_xml_ptr desc, chns, chn, cap; /* some xml element pointers */
7+
lsl_outlet outlet; /* stream outlet */
8+
lsl_streaminfo info, inf; /* streaminfo objects */
9+
lsl_inlet inlet; /* a stream inlet to get samples from */
10+
int errcode; /* error code (lsl_lost_error or timeouts) */
11+
const char *labels[] = {"C3", "C4", "Cz", "FPz", "POz", "CPz", "O1", "O2"};
1212

1313
/* create a new streaminfo and declare some meta-data (in accordance with XDF format) */
14-
const char* name = argc > 1 ? argv[1] : "MetaTester";
15-
info = lsl_create_streaminfo(name,"EEG",8,100,cft_float32,"myuid323457");
14+
const char *name = argc > 1 ? argv[1] : "MetaTester";
15+
info = lsl_create_streaminfo(name, "EEG", 8, 100, cft_float32, "myuid323457");
1616
desc = lsl_get_desc(info);
17-
chns = lsl_append_child(desc,"channels");
18-
for (c=0;c<8;c++) {
19-
chn = lsl_append_child(chns,"channel");
20-
lsl_append_child_value(chn,"label",labels[c]);
21-
lsl_append_child_value(chn,"unit","microvolts");
22-
lsl_append_child_value(chn,"type","EEG");
17+
chns = lsl_append_child(desc, "channels");
18+
for (c = 0; c < 8; c++) {
19+
chn = lsl_append_child(chns, "channel");
20+
lsl_append_child_value(chn, "label", labels[c]);
21+
lsl_append_child_value(chn, "unit", "microvolts");
22+
lsl_append_child_value(chn, "type", "EEG");
2323
}
24-
lsl_append_child_value(desc,"manufacturer","SCCN");
25-
cap = lsl_append_child(desc,"cap");
26-
lsl_append_child_value(cap,"name","EasyCap");
27-
lsl_append_child_value(cap,"size","54");
28-
lsl_append_child_value(cap,"labelscheme","10-20");
24+
lsl_append_child_value(desc, "manufacturer", "SCCN");
25+
cap = lsl_append_child(desc, "cap");
26+
lsl_append_child_value(cap, "name", "EasyCap");
27+
lsl_append_child_value(cap, "size", "54");
28+
lsl_append_child_value(cap, "labelscheme", "10-20");
2929

3030
/* create outlet for the stream */
31-
outlet = lsl_create_outlet(info,0,360);
31+
outlet = lsl_create_outlet(info, 0, 360);
3232

3333
/* === the following could run on another computer === */
3434

3535
/* resolve the stream and open an inlet */
36-
lsl_resolve_byprop(&info,1,"name","MetaTester",1,LSL_FOREVER);
36+
lsl_resolve_byprop(&info, 1, "name", "MetaTester", 1, LSL_FOREVER);
3737
inlet = lsl_create_inlet(info, 360, LSL_NO_PREFERENCE, 1);
38-
inf = lsl_get_fullinfo(inlet,LSL_FOREVER,&errcode);
38+
inf = lsl_get_fullinfo(inlet, LSL_FOREVER, &errcode);
3939
printf("The stream's XML meta-data is: \n");
40-
printf("%s\n",lsl_get_xml(inf));
41-
printf("The manufacturer is: %s\n",lsl_child_value_n(lsl_get_desc(inf),"manufacturer"));
42-
printf("The cap circumference is: %s\n",lsl_child_value_n(lsl_child(lsl_get_desc(inf),"cap"),"size"));
40+
printf("%s\n", lsl_get_xml(inf));
41+
printf("The manufacturer is: %s\n", lsl_child_value_n(lsl_get_desc(inf), "manufacturer"));
42+
printf("The cap circumference is: %s\n",
43+
lsl_child_value_n(lsl_child(lsl_get_desc(inf), "cap"), "size"));
4344
printf("The channel labels are as follows:\n");
44-
chn = lsl_child(lsl_child(lsl_get_desc(inf),"channels"),"channel");
45-
for (c=0; c<lsl_get_channel_count(inf); c++) {
46-
printf(" %s\n",lsl_child_value_n(chn,"label"));
47-
chn = lsl_next_sibling(chn);
48-
}
45+
chn = lsl_child(lsl_child(lsl_get_desc(inf), "channels"), "channel");
46+
for (c = 0; c < lsl_get_channel_count(inf); c++) {
47+
printf(" %s\n", lsl_child_value_n(chn, "label"));
48+
chn = lsl_next_sibling(chn);
49+
}
4950

5051
/* destroy objects and free memory */
5152
lsl_destroy_streaminfo(inf);

examples/ReceiveData.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1-
#include <thread>
21
#include <iostream>
32
#include <lsl_cpp.h>
43
#include <string>
4+
#include <thread>
55

66

77
/**
88
* Example program that demonstrates how to resolve a specific stream on the lab
99
* network and how to connect to it in order to receive data.
1010
*/
1111

12-
void printChunk(const std::vector<float>& chunk, std::size_t n_channels) {
13-
for(std::size_t i=0; i < chunk.size(); ++i) {
12+
void printChunk(const std::vector<float> &chunk, std::size_t n_channels) {
13+
for (std::size_t i = 0; i < chunk.size(); ++i) {
1414
std::cout << chunk[i] << ' ';
15-
if (i % n_channels == n_channels - 1)
16-
std::cout << '\n';
15+
if (i % n_channels == n_channels - 1) std::cout << '\n';
1716
}
1817
}
1918

20-
void printChunk(const std::vector<std::vector<float>>& chunk) {
21-
for(const auto& vec: chunk)
22-
printChunk(vec, vec.size());
19+
void printChunk(const std::vector<std::vector<float>> &chunk) {
20+
for (const auto &vec : chunk) printChunk(vec, vec.size());
2321
}
2422

25-
int main(int argc, char* argv[]) {
23+
int main(int argc, char *argv[]) {
2624
std::string field, value;
2725
const int max_samples = argc > 3 ? std::stoi(argv[3]) : 10;
2826
if (argc < 3) {
2927
std::cout << "This connects to a stream which has a particular value for a "
30-
"given field and receives data.\nPlease enter a field name and the desired "
31-
"value (e.g. \"type EEG\" (without the quotes)):"
32-
<< std::endl;
28+
"given field and receives data.\nPlease enter a field name and the desired "
29+
"value (e.g. \"type EEG\" (without the quotes)):"
30+
<< std::endl;
3331
std::cin >> field >> value;
3432
} else {
3533
field = argv[1];
@@ -39,7 +37,7 @@ int main(int argc, char* argv[]) {
3937
// resolve the stream of interet
4038
std::cout << "Now resolving streams..." << std::endl;
4139
std::vector<lsl::stream_info> results = lsl::resolve_stream(field, value);
42-
if(results.empty()) throw std::runtime_error("No stream found");
40+
if (results.empty()) throw std::runtime_error("No stream found");
4341

4442
std::cout << "Here is what was resolved: " << std::endl;
4543
std::cout << results[0].as_xml() << std::endl;
@@ -54,7 +52,7 @@ int main(int argc, char* argv[]) {
5452
std::vector<float> sample;
5553
std::vector<std::vector<float>> chunk_nested_vector;
5654

57-
for(int i=0; i < max_samples; ++i) {
55+
for (int i = 0; i < max_samples; ++i) {
5856
// pull a single sample
5957
inlet.pull_sample(sample);
6058
printChunk(sample, inlet.get_channel_count());
@@ -73,7 +71,7 @@ int main(int argc, char* argv[]) {
7371
printChunk(sample, inlet.get_channel_count());
7472
}
7573

76-
if(argc == 1) {
74+
if (argc == 1) {
7775
std::cout << "Press any key to exit. " << std::endl;
7876
std::cin.get();
7977
}

examples/ReceiveDataC.c

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,41 @@
22
#include <stdio.h>
33

44
/**
5-
* Example program that demonstrates how to resolve a specific stream on the lab network and how to connect to it in order to receive data.
6-
*/
5+
* Example program that demonstrates how to resolve a specific stream on the lab network and how to
6+
* connect to it in order to receive data.
7+
*/
78

8-
int main(int argc, char* argv[]) {
9+
int main(int argc, char *argv[]) {
910

10-
unsigned k,t; /* channel index */
11-
lsl_streaminfo info; /* the streaminfo returned by the resolve call */
12-
lsl_inlet inlet; /* a stream inlet to get samples from */
13-
int errcode; /* error code (lsl_lost_error or timeouts) */
14-
float cursample[8]; /* array to hold our current sample */
15-
double timestamp; /* time stamp of the current sample (in sender time) */
11+
unsigned k, t; /* channel index */
12+
lsl_streaminfo info; /* the streaminfo returned by the resolve call */
13+
lsl_inlet inlet; /* a stream inlet to get samples from */
14+
int errcode; /* error code (lsl_lost_error or timeouts) */
15+
float cursample[8]; /* array to hold our current sample */
16+
double timestamp; /* time stamp of the current sample (in sender time) */
1617

17-
/* resolve the stream of interest (result array: info, array capacity: 1 element, type shall be EEG, resolve at least 1 stream, wait forever if necessary) */
18+
/* resolve the stream of interest (result array: info, array capacity: 1 element, type shall be
19+
* EEG, resolve at least 1 stream, wait forever if necessary) */
1820
printf("Now waiting for an EEG stream...\n");
19-
lsl_resolve_byprop(&info, 1, "type","EEG", 1, LSL_FOREVER);
21+
lsl_resolve_byprop(&info, 1, "type", "EEG", 1, LSL_FOREVER);
2022

21-
/* make an inlet to read data from the stream (buffer max. 300 seconds of data, no preference regarding chunking, automatic recovery enabled) */
23+
/* make an inlet to read data from the stream (buffer max. 300 seconds of data, no preference
24+
* regarding chunking, automatic recovery enabled) */
2225
inlet = lsl_create_inlet(info, 300, LSL_NO_PREFERENCE, 1);
2326

24-
/* subscribe to the stream (automatically done by push, but a nice way of checking early on that we can connect successfully) */
25-
lsl_open_stream(inlet,LSL_FOREVER,&errcode);
26-
if (errcode != 0)
27-
return errcode;
27+
/* subscribe to the stream (automatically done by push, but a nice way of checking early on that
28+
* we can connect successfully) */
29+
lsl_open_stream(inlet, LSL_FOREVER, &errcode);
30+
if (errcode != 0) return errcode;
2831

2932
printf("Displaying data...\n");
30-
for(t=0;t<100000000;t++) {
31-
/* get the next sample form the inlet (read into cursample, 8 values, wait forever if necessary) and return the timestamp if we got something */
32-
timestamp = lsl_pull_sample_f(inlet,cursample,8,LSL_FOREVER,&errcode);
33+
for (t = 0; t < 100000000; t++) {
34+
/* get the next sample form the inlet (read into cursample, 8 values, wait forever if
35+
* necessary) and return the timestamp if we got something */
36+
timestamp = lsl_pull_sample_f(inlet, cursample, 8, LSL_FOREVER, &errcode);
3337

3438
/* print the data */
35-
for (k=0; k<8; ++k)
36-
printf("\t%.2f", cursample[k]);
39+
for (k = 0; k < 8; ++k) printf("\t%.2f", cursample[k]);
3740
printf("\n");
3841
}
3942

examples/ReceiveDataInChunks.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include <stdint.h>
21
#include <iostream>
32
#include <lsl_cpp.h>
3+
#include <stdint.h>
44

55

66
// define a packed sample struct (here a stereo sample).
@@ -9,7 +9,7 @@ struct stereo_sample {
99
int16_t l, r;
1010
};
1111

12-
int main(int, char* []) {
12+
int main(int, char *[]) {
1313
try {
1414

1515
// resolve the stream of interest & make an inlet
@@ -23,7 +23,7 @@ int main(int, char* []) {
2323
std::cout << timestamp << std::endl; // only showing the time stamps here
2424
}
2525

26-
} catch (std::exception& e) { std::cerr << "Got an exception: " << e.what() << std::endl; }
26+
} catch (std::exception &e) { std::cerr << "Got an exception: " << e.what() << std::endl; }
2727
std::cout << "Press any key to exit. " << std::endl;
2828
std::cin.get();
2929
return 0;

0 commit comments

Comments
 (0)