The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Collection<user-defined class>

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
MBIMO Posted - 08/18/2005 : 10:43:29 AM
Origin Version (Select Help-->About Origin): 7.5 SR5
Operating System: Win2k

Hi everybody,

is there a simple way to implement an array of instances of a
user-defined class?
Or to make myself more clear, is it possible to emulate the behaviour of the internal collections like Pages, Layers,...

Collection<aClass> obviously works only for internal Origin objects.

So far I figured out that I could save the pointers to the instances in a vector<unit>. Is this feasible or are there better ways to do this.

Thanks in advance.

Best regards,

Martin


8   L A T E S T    R E P L I E S    (Newest First)
cpyang Posted - 08/30/2005 : 5:49:04 PM
I just found out that


trN = tr.Children.Item(ii);


has already been added to our next version, just it was not implemented in Origin 7.5

CP


MBIMO Posted - 08/24/2005 : 03:57:22 AM
Hi it's me again,

to finally conclude this topic here's the solution I came up with.

Personally I find it more elegant then CP's approach of abusing the tagNames of the TreeNodes.

The code uses the FirstNode and NextNode data fields to loop through all nodes until the n'th one.



TreeNode Item(int n)
{
TreeNode tr;
int i;

tr=m_trNode.FirstNode;

for (i=0; i<=anIndex; i++)
{
tr=tr.NextNode;
};

return tr;
}


It works perfect.

Best regards,

Martin


Edited by - MBIMO on 08/24/2005 03:59:10 AM
MBIMO Posted - 08/22/2005 : 11:51:50 AM
Thank you CP, I will implement your workaround.

I'm glad it's a bug, I really had second thoughts about my programming skills :-)

Best regards,

Martin

cpyang Posted - 08/22/2005 : 11:42:38 AM
Looks like you have found a bug. I have created bug tracking number 8037 to be fixed in our next release.

For the time being, you will have to write your own foreach loop to get a tree node, or you can prepare your tagName with enumeration to get around this bug.

CP


MBIMO Posted - 08/22/2005 : 04:03:31 AM
During the weekend I had time to test the code from
http://www.originlab.com/forum/topic.asp?TOPIC_ID=3560

It works fine. However there remains one further question. In the code above there's a member function which iterates through the nodes by using a foreach loop on the "Children" data field:


void ShowSequence()
{
foreach(TreeNode tr in m_trNode.Children)
{
AminoAcidResidue aar(tr);
printf("%c", aar.GetType());
}
printf("\n");
}


Since Children is defined a Collection<TreeNode> I tried something like this to access a specific child directly:


Collection<TreeNode> aCollection;

aCollection=m_trNode.Children;
TreeNode myChild;
myChild=aCollection.Item(anIndex); //<<Error, Incompatible variable types in expression


The compiler aborted with the error mentioned in the code above.
If I use an explicit typecast in the marked line:

 
myChild=(TreeNode)aCollection.Item(anIndex); //<<Error, invalid explicit cast


the copiler still refuses to compile.

I think I'm missing something fundamental. Can somebody please point me to the correct direction? What is the proper way to access a specific item of the Children collection? I know that I could use the
 TreeNode  GetNode (LPCSTR Name) 
member function but since I don't know the name, I'd like to access the child by index.

Thanks for your help.

Best regards,

Martin
MBIMO Posted - 08/19/2005 : 10:40:18 AM
Thanks rlewis,

I will give it a shot.

Best regards,

Martin
rlewis Posted - 08/19/2005 : 09:32:17 AM
See also ....
http://www.originlab.com/forum/topic.asp?TOPIC_ID=3560
MBIMO Posted - 08/19/2005 : 05:50:06 AM
Hi everybody,

meanwhile I came up with the following code.

"TestClass" is just an arbitrary user-defined class that holds an interger value.
The function "Test" creates a couple of instances and adds their addresses to a vector<uint> list.

Here's the code:

-- 8< ---------------

class TestClass
{
private:
protected:
public:
TestClass(); //constructor
~TestClass(); //destructor

int Tag;
};


void Test()
{
vector<uint> ObjectList; //the list that stores the objects
TestClass Item0,Item1,Item2; //some instances of the TestClass
int Tag;
TestClass myItem;
uint Ptr;
int i;

Item0.Tag=0; //sets the "Tag" variable...
ObjectList.Add((uint) &Item0); //...and adds the address to the list

Item1.Tag=1;
ObjectList.Add((uint) &Item1);

Item2.Tag=2;
ObjectList.Add((uint) &Item2);


for (i=0; i<=ObjectList.GetSize()-1; i++) //loop through the list...
{
Ptr=ObjectList[i]; //...get the address...
myItem=*((TestClass*)Ptr); //...typecase it...
out_int("Tag: ",myItem.Tag); //...and finally print it
};
}

-- 8< ---------------

So far it's working. However I'm stuck now with the following problem.
How can I create the instances in a loop i.e. how can I call the constructor explicitly and create a new instance?

I tried to use something like this:

TestClass *newItem = new TestClass;

However Origin crashed when running this in a for-loop.

Can anybody help me?

Best regards,

Martin



Edited by - MBIMO on 08/19/2005 08:02:23 AM

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000