aliiitarek / labstreaminglayer

Automatically exported from code.google.com/p/labstreaminglayer
0 stars 0 forks source link

C++ examples with persistent inlet or outlet? #34

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I'm trying to do something that requires greater knowledge of C++ than I 
currently have.

I am trying to create an Unreal Engine 4 plugin. The engine handles its own 
threading and when to call the Tick functions of each object in the scene. I am 
building a SceneComponent object and I want to use its TickComponent function 
to call inlet.pull_sample. But I don't want to recreate the inlet on every tick 
(75 Hz).

So I thought I'd have the inlet as a member variable in my component class. 
This requires the inlet to be created explicitly upon component instantiation 
because lsl::stream_inlet has no default constructor. I tried constructing it 
with my_inlet(lsl::stream_info("NotAName", "NotAType", 0)), and, though it 
compiles, attempting to add my component to the scene causes a bunch of errors.

So how do I make a placeholder inlet on instantiation? Or is there a better 
solution?

I will try to use the C API instead, but I would really prefer to use the C++ 
API.

Original issue reported on code.google.com by chadwick...@gmail.com on 11 Mar 2015 at 2:26

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This is more of a C++ question than an lsl question. However, I think what you 
want is to declare my_inlet as a pointer in your object and then use the new 
keyword to grab the memory for it:

lsl::stream_inlet *my_inlet; // member declaration
my_inlet = new lsl::stream_inlet(<constructor args>); // in the constructor code

Two things about this. First, you will have to manually destroy the inlet. 
Second, since it is now a pointer rather than an actual inlet, you will need to 
use the "->" rather than the "." to reference its members.

Original comment by david.er...@gmail.com on 16 Mar 2015 at 10:22

GoogleCodeExporter commented 9 years ago
I thought it might be the 'new' keyword. Thanks. Though this question was 
specifically for what I'm doing, I do think it would be generally useful to 
have a C++ example that uses classes.

Original comment by chadwick...@gmail.com on 16 Mar 2015 at 11:21

GoogleCodeExporter commented 9 years ago
By the way, thank you very much for the tip, and I think you can probably close 
this issue. Now that I know the answer it seems rather trivial, and should be 
something I knew and surely anyone that uses C++ regularly will know.

Original comment by chadwick...@gmail.com on 17 Mar 2015 at 2:17

GoogleCodeExporter commented 9 years ago
No problem, Chad. I had many similar difficulties when I first got started with 
C++.

Original comment by david.er...@gmail.com on 17 Mar 2015 at 6:45