making generic list class

C

colin

Hi,

Im trying to implement a generic list class for a number of 3d object types,
that form a 3d solid model, take the easiest one Point for example,

it contains a Vector3 and a list of other 3d object types
such as surfaces and wires wich also reference this point.

I need to be able to search the list for an exisitng Point
but just using the Vector3, then if its not in the list
to insert a new Point with the given coordinates.

Is there a good/easy way of doing this with a template class
with only specifying the one type ie Point in the template ?
I had problems in that you cant use parameters in a new statement,
nor have static functions in the interface.

I dont realy want to resort to using object as a parameter.

nor do I want to use a list such as <key,value> pair
as the key is in the value. although I dont need it to be fast.

Im stil relativly new to c# and I tried it a few ways using class template
with 2 types but
it was awkward, even trying to use an interface template as the base for the
3d objects.
I keep trying to do the things I know I can do in C++ wich probably isnt so
good.

In the end I found it easier to do a seperate list class for each type,
as trying to use templates I seemed to end up with more helper classes,
and the information was buried under more layers when viewed in the
debugger.

thanks
Colin =^.^=
 
J

Jon Skeet [C# MVP]

colin said:
Im trying to implement a generic list class for a number of 3d object types,
that form a 3d solid model, take the easiest one Point for example,

it contains a Vector3 and a list of other 3d object types
such as surfaces and wires wich also reference this point.

I need to be able to search the list for an exisitng Point
but just using the Vector3, then if its not in the list
to insert a new Point with the given coordinates.

Okay - that sounds like you just need to use List<Point> and then
List<T>.Find with a predicate which matches based on the Vector3.

I'm afraid if that doesn't help, I'm not terribly clear on what you're
trying to do...
 
C

colin

Jon Skeet said:
Okay - that sounds like you just need to use List<Point> and then
List<T>.Find with a predicate which matches based on the Vector3.

Aha ok thanks, I remember I did come accross that
but im not familiar with it and it wasnt obvious to me at first glance how
to even use it,
so il have to go have a further read now youve given me a hint it might be
in the right direction.
:)

I kinda like the idea of keeping it simple,
as theres only 3 seperate list types.
after having to use reflection im kinda weary of complicated stuff.
I'm afraid if that doesn't help, I'm not terribly clear on what you're
trying to do...

Well actually I get that feeling too sometimes, ...

I remember hearing somewhere there was so much information being generated
about
windows no one person could ever keep up with the new information let alone
know everything there is to know.

Colin =^.^=
 
M

Michael D. Ober

Jon Skeet said:
Okay - that sounds like you just need to use List<Point> and then
List<T>.Find with a predicate which matches based on the Vector3.

I'm afraid if that doesn't help, I'm not terribly clear on what you're
trying to do...

How about Dictionary<point, Vector3> ?.

Mike.
 
C

colin

Michael D. Ober said:
How about Dictionary<point, Vector3> ?.

hmm my Vector3 can change, ie the point can move,
the point is shared by numerous objects (Ie 3d surfaces)
wich each need to see the updated position.
I hadnt considerd sorting the lists but the following would cuase an issue I
hadnt even thought of before.

quote:-
As long as an object is used as a key in the Dictionary, it must not change
in any way that affects its hash value. Every key in a Dictionary must be
unique according to the dictionary's equality comparer. A key cannot be a
null reference (Nothing in Visual Basic), but a value can be, if the value
type TValue is a reference type.

Il look into Jon's sugestion soon but for now im bogged down with trying to
get XNA to draw the lines for my wire frames as wide as I tell it to in
rather than just 1 pixel wide.

thanks
Colin =^.^=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top