ATTENTIONThis FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices. |
flexsim.com |
#1
|
||||
|
||||
Storing a C++ class pointer in a flexsim object
Would it be possible to store a pointer to a class in C++ into a Flexsim node? With other words make a link between a class object in a DLL and a Flexsim object?
Interested to hear your ideas. |
#2
|
||||
|
||||
You can always just give the node number data, and then set it to tonum(class pointer). The problem with that, though, is that you're explicitly breaking save state capability, so it's not "best practices." What I usually try to do is preserve the idea that all pointers need to be to nodes (not to custom c++ class instances), and then nodes can hold binary data such as custom classes that I define. With version 5 you have the added capability of using one-way coupling data that is properly saved, so this gives you more flexibility in using this method. Then I usually define structs, and store them in the nodes' data using the bb... commands: bbsetsize(), bbgetsize(), bbgetbuffer(). The main drawback here is that the definition of the struct needs to be completely serializable, meaning it has to be one contiguous block of bytes that contain all the class' information, or in other words, the struct/class can't contain pointers to other structs/classes. So it's not the most flexible method, but so far it's worked pretty well for me.
|
The Following 3 Users Say Thank You to Anthony Johnson For This Useful Post: | ||
Phil BoBo (04-15-2010) |
#3
|
||||
|
||||
Anthony,
I have to chew on your answer a bit, but thanks anyway. I think that breaking save state capability is not that big an issue because the DLL with it's class instances is also closed anyway and I don't think there is any use keeping links there between the DLL and Flexsim. |
Tags |
c++, class, pointer, store in node |
Thread | Thread Starter | Forum | Replies | Last Post |
Get object class | juan alberto | Q&A | 1 | 09-24-2009 06:25 AM |
COM Object for Controlling Flexsim | Anthony Johnson | User Development | 6 | 02-25-2009 11:43 AM |
I think an easy question... - how to pointer to objects | david_white | Q&A | 21 | 08-18-2008 12:20 PM |
How to select all objects of a class in your model | Brenton King | Tips and Tricks | 3 | 04-03-2008 11:25 PM |