D - What's the Solution?
- anderson (31/31) Jul 18 2002 Just to highlight a point, I would like to request how you would tackle ...
- Sean L. Palmer (46/77) Jul 19 2002 Lines are not Vertices. Polygons are not Triangles.
- anderson (17/59) Jul 19 2002 Thanks for your reply, but it doesn't meet the requirements.
- Sean L. Palmer (14/80) Jul 20 2002 You didn't specify that NO code could be added to the derived classes. ...
- anderson (8/15) Jul 20 2002 Only
- Sean L. Palmer (8/23) Jul 21 2002 the
- Pavel Minayev (8/8) Jul 21 2002 On Sun=2C 21 Jul 2002 09=3A36=3A30 -0700 =22Sean L=2E Palmer=22 =3Cseanp...
- anderson (10/12) Jul 22 2002 What type of numbers does ClassInfo return? Will the algorithm need a ha...
- Russ Lewis (8/10) Jul 22 2002 D provides associative arrays built-in. You don't have to worry about t...
- anderson (4/14) Jul 22 2002 Oh, I get that. Thanks.
- Pavel Minayev (3/5) Jul 22 2002 classinfo property is not a number, it's a reference to ClassInfo object...
- Walter (7/12) Aug 01 2002 wrote:
- Pavel Minayev (6/9) Aug 01 2002
- Walter (4/10) Aug 03 2002 the
- Pavel Minayev (6/12) Aug 03 2002
- Walter (3/11) Aug 03 2002 Yes.
-
anderson
(16/21)
Jul 22 2002
"Pavel Minayev"
wrote in message - anderson (4/24) Jul 22 2002 return countSelected[this.classinfo()];
- Pavel Minayev (23/23) Jul 22 2002 On Mon=2C 22 Jul 2002 18=3A19=3A01 +0800 =22anderson=22 =3Canderson=40fi...
- anderson (26/33) Jul 22 2002 Thanks. Cool, you could never do that in C++.
- anderson (4/36) Jul 22 2002 Whoops, forgot to remove the length++
-
Pavel Minayev
(3/4)
Jul 23 2002
Why? You can have map
, and use typeid() operator. - anderson (4/7) Jul 23 2002 wrote:
- Pavel Minayev (3/5) Jul 21 2002 abstract int getType();
- anderson (12/14) Jul 22 2002 Your right! I was thinking of anther project where we used a static mach...
Just to highlight a point, I would like to request how you would tackle a problem like this in D. Classes Vertex - Base class Line : Vertex Triangle : Line Polygon : Triangle ect... What I would like to determine is how many Vertexes, lines, Triangles and polygons are selected (individually). So for example 2 Vertexes are selected 5 lines are selected 6 Triangles are selected 3 Polygons are selected So for example you may have these methords //Although these could be done as an property VertexObject.setSelected() //Sets this object to selected VertexObject.getSelected() //Gets if this object is selected LineObject.setSelected() //Sets this object to selected ect.. VertexClass.getSelected() //gets the total amount of selected vertexes for the vertex class LineClass.getSelected() //gets the total amount of selected vertexes for the line class ect.. Easy right, heres a couple of important ground rules to make things more difficult: 1. All code details must be contained within the class itself. 2. This code should only need to be written once in the BASE class. Subsequent classes should inherit this property. 3. Needs to be resonably simple because the task is resonably simple.
Jul 18 2002
Lines are not Vertices. Polygons are not Triangles. You should be using HasA, not IsA relationships. So maybe they all derive from class GeometricPrimitive. Hiding this all in the base class is hard; what you'd have to do is have each subclass register itself with the base class and have some kind of virtual "GetType()" function to let the base class know what kind it is so it can keep a tally. Probably: class GeometricPrimitive { private: static int[] countSelected; // how many of each type are selected bool selected; // if this is selected protected: int getType() { assert(false); } // how do you make pure virtual functions in D? public: void setSelected() { selected = true; countSelected.length = max(countSelected.length, getType()+1); // does D have builtin min/max/range/swap ? ++countSelected[getType()]; } bool getSelected() { return selected; } int getTotalSelectedOfType() { return countSelected(getType()); } } class Vertex : GeometricPrimitive { int getType() { return 0; } } class Line : GeometricPrimitive { int getType() { return 1; } } Something like that perhaps. Sean "anderson" <anderson firestar.com.au> wrote in message news:ah82lm$16km$1 digitaldaemon.com...Just to highlight a point, I would like to request how you would tackle a problem like this in D. Classes Vertex - Base class Line : Vertex Triangle : Line Polygon : Triangle ect... What I would like to determine is how many Vertexes, lines, Triangles and polygons are selected (individually). So for example 2 Vertexes are selected 5 lines are selected 6 Triangles are selected 3 Polygons are selected So for example you may have these methords //Although these could be done as an property VertexObject.setSelected() //Sets this object to selected VertexObject.getSelected() //Gets if this object is selected LineObject.setSelected() //Sets this object to selected ect.. VertexClass.getSelected() //gets the total amount of selected vertexes for the vertex class LineClass.getSelected() //gets the total amount of selected vertexes fortheline class ect.. Easy right, heres a couple of important ground rules to make things more difficult: 1. All code details must be contained within the class itself. 2. This code should only need to be written once in the BASE class. Subsequent classes should inherit this property. 3. Needs to be resonably simple because the task is resonably simple.
Jul 19 2002
"Sean L. Palmer" <seanpalmer earthlink.net> wrote in message news:ah8k4f$1oop$1 digitaldaemon.com...Lines are not Vertices. Polygons are not Triangles.Thanks for your reply, but it doesn't meet the requirements. Have you ever created a drawing package? Polygons are made of triangles, triangles of Vertices ect... I didn't mention that each vertex (line, triangle) is a group. Anyhow that's beside the point. I don't care what names are used, it's just for example purposes only (I'm not actually implementing this code) as long as its hyracical in nature.You should be using HasA, not IsA relationships. So maybe they all derive from class GeometricPrimitive. Hiding this all in the base class is hard; what you'd have to do is have each subclass register itself with the base class and have some kind of virtual "GetType()" function to let the base class know what kind it is so it can keep a tally. Probably: class GeometricPrimitive { private: static int[] countSelected; // how many of each type are selected bool selected; // if this is selected protected: int getType() { assert(false); } // how do you make pure virtual functions in D? public: void setSelected() { selected = true; countSelected.length = max(countSelected.length, getType()+1); // does D have builtin min/max/range/swap ? ++countSelected[getType()]; } bool getSelected() { return selected; } int getTotalSelectedOfType() { return countSelected(getType()); } } class Vertex : GeometricPrimitive { int getType() { return 0; } } class Line : GeometricPrimitive { int getType() { return 1; } } Something like that perhaps.This breaks rule 2. These rules are not for breaking. Code should only be written in the base class. Writing it in the other classes not only means extra work for other programmers, but extra documentation. How do you suppose numbers are issued in your suggestion. One project could have many users that may not even be in the same company. Even I've solved that problem (using pointers) using a simular technique. I've use code like this all the time, it's not the question. I have an idea how D could be improved to deal with these problems. I think that other will draw to that some conclusion, so I won't mention it now.
Jul 19 2002
You didn't specify that NO code could be added to the derived classes. Only that the getSelected methods weren't to be implemented in the derived classes. ;) I've run into that same problem before and the best solution is to use the classinfo as the index somehow. I just wasn't sure of D's classinfo syntax and naming so I didn't put it into the example. Sean "anderson" <anderson firestar.com.au> wrote in message news:ahaq8u$ub4$1 digitaldaemon.com..."Sean L. Palmer" <seanpalmer earthlink.net> wrote in message news:ah8k4f$1oop$1 digitaldaemon.com...haveLines are not Vertices. Polygons are not Triangles.Thanks for your reply, but it doesn't meet the requirements. Have you ever created a drawing package? Polygons are made of triangles, triangles of Vertices ect... I didn't mention that each vertex (line, triangle) is a group. Anyhow that's beside the point. I don't care what names are used, it's just for example purposes only (I'm not actually implementing this code) as long as its hyracical in nature.You should be using HasA, not IsA relationships. So maybe they all derive from class GeometricPrimitive. Hiding this all in the base class is hard; what you'd have to do issoeach subclass register itself with the base class and have some kind of virtual "GetType()" function to let the base class know what kind it is//it can keep a tally. Probably: class GeometricPrimitive { private: static int[] countSelected; // how many of each type are selected bool selected; // if this is selected protected: int getType() { assert(false); } // how do you make pure virtual functions in D? public: void setSelected() { selected = true; countSelected.length = max(countSelected.length, getType()+1);thisdoes D have builtin min/max/range/swap ? ++countSelected[getType()]; } bool getSelected() { return selected; } int getTotalSelectedOfType() { return countSelected(getType()); } } class Vertex : GeometricPrimitive { int getType() { return 0; } } class Line : GeometricPrimitive { int getType() { return 1; } } Something like that perhaps.This breaks rule 2. These rules are not for breaking. Code should only be written in the base class. Writing it in the other classes not only means extra work for other programmers, but extra documentation. How do you suppose numbers are issued in your suggestion. One project could have many users that may not even be in the same company. Even I've solved that problem (using pointers) using a simular technique. I've use code likeall the time, it's not the question. I have an idea how D could beimprovedto deal with these problems. I think that other will draw to that some conclusion, so I won't mention it now.
Jul 20 2002
"Sean L. Palmer" <seanpalmer earthlink.net> wrote in message news:ahckrq$77p$1 digitaldaemon.com...You didn't specify that NO code could be added to the derived classes.Onlythat the getSelected methods weren't to be implemented in the derived classes. ;)Well that's what I ment by 2. 2. This code should only should be written once in the BASE class. Subsequent classes should inherit this property.I've run into that same problem before and the best solution is to use the classinfo as the index somehow. I just wasn't sure of D's classinfosyntaxand naming so I didn't put it into the example.That still doesn't solve 2.Sean
Jul 20 2002
"anderson" <anderson firestar.com.au> wrote in message news:ahd447$lu1$1 digitaldaemon.com..."Sean L. Palmer" <seanpalmer earthlink.net> wrote in message news:ahckrq$77p$1 digitaldaemon.com...theYou didn't specify that NO code could be added to the derived classes.Onlythat the getSelected methods weren't to be implemented in the derived classes. ;)Well that's what I ment by 2. 2. This code should only should be written once in the BASE class. Subsequent classes should inherit this property.I've run into that same problem before and the best solution is to useSure it does. Just replace getType() with int(&classinfo(*this)) or something similar. It would be nice if classinfo had some generated int identifier or perhaps enum? that could be used for this purpose. Haven't looked into it much. Seanclassinfo as the index somehow. I just wasn't sure of D's classinfosyntaxand naming so I didn't put it into the example.That still doesn't solve 2.
Jul 21 2002
On Sun=2C 21 Jul 2002 09=3A36=3A30 -0700 =22Sean L=2E Palmer=22 =3Cseanpalmer=40earthlink=2Enet=3E wrote=3A =3E Sure it does=2E Just replace getType=28=29 with int=28&classinfo=28*this=29=29 or =3E something similar=2E Better yet=2C use an associative array=3A =09 =09int=5BClassInfo=5D countSelected=3B Then=2C no need for getType=28=29=2E Just use =2Eclassinfo of object=2E
Jul 21 2002
What type of numbers does ClassInfo return? Will the algorithm need a hash table? "Pavel Minayev" <evilone omen.ru> wrote in message news:CFN374589713982292 news.digitalmars.com... On Sun, 21 Jul 2002 09:36:30 -0700 "Sean L. Palmer" <seanpalmer earthlink.net> wrote:Sure it does. Just replace getType() with int(&classinfo(*this)) or something similar.Better yet, use an associative array: int[ClassInfo] countSelected; Then, no need for getType(). Just use .classinfo of object.
Jul 22 2002
anderson wrote:What type of numbers does ClassInfo return? Will the algorithm need a hash table?D provides associative arrays built-in. You don't have to worry about the internals; Walter does that for you! -- The Villagers are Online! http://villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Jul 22 2002
Oh, I get that. Thanks. "Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message news:3D3BF7FB.6C9C809A deming-os.org...anderson wrote:hashWhat type of numbers does ClassInfo return? Will the algorithm need atable?D provides associative arrays built-in. You don't have to worry about the internals; Walter does that for you! -- The Villagers are Online! http://villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Jul 22 2002
On Mon, 22 Jul 2002 18:04:08 +0800 "anderson" <anderson firestar.com.au> wrote:What type of numbers does ClassInfo return? Will the algorithm need a hash table?classinfo property is not a number, it's a reference to ClassInfo object. But there's nothing wrong in using object references as hashtable keys. =)
Jul 22 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:CFN374600443827431 news.digitalmars.com...On Mon, 22 Jul 2002 18:04:08 +0800 "anderson" <anderson firestar.com.au>wrote:hashWhat type of numbers does ClassInfo return? Will the algorithm need aOne of my intentions is that it becomes easy to see if two handles are the same type with: if (h1.classinfo === h2.classinfo)table?classinfo property is not a number, it's a reference to ClassInfo object. But there's nothing wrong in using object references as hashtable keys. =)
Aug 01 2002
On Thu, 1 Aug 2002 02:54:15 -0700 "Walter" <walter digitalmars.com> wrote:One of my intentions is that it becomes easy to see if two handles are the same type with: if (h1.classinfo === h2.classinfo)I wonder why you use ===, not == ? I mean, there is only one ClassInfo object per class, so comparing references should do.
Aug 01 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:CFN374700122923032 news.digitalmars.com...On Thu, 1 Aug 2002 02:54:15 -0700 "Walter" <walter digitalmars.com> wrote:theOne of my intentions is that it becomes easy to see if two handles are=== does compare references!same type with: if (h1.classinfo === h2.classinfo)I wonder why you use ===, not == ? I mean, there is only one ClassInfo object per class, so comparing references should do.
Aug 03 2002
On Sat, 3 Aug 2002 11:37:11 -0700 "Walter" <walter digitalmars.com> wrote:Is it so both for arrays and objects? By the way, I've looked at default Object.cmp() - compares references as well. So it all doesn't really matter. =)=== does compare references!same type with: if (h1.classinfo === h2.classinfo)I wonder why you use ===, not == ? I mean, there is only one ClassInfo object per class, so comparing references should do.
Aug 03 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:CFN374721026579514 news.digitalmars.com...On Sat, 3 Aug 2002 11:37:11 -0700 "Walter" <walter digitalmars.com> wrote:Yes.Is it so both for arrays and objects?=== does compare references!same type with: if (h1.classinfo === h2.classinfo)I wonder why you use ===, not == ? I mean, there is only one ClassInfo object per class, so comparing references should do.
Aug 03 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:CFN374589713982292 news.digitalmars.com... On Sun, 21 Jul 2002 09:36:30 -0700 "Sean L. Palmer" <seanpalmer earthlink.net> wrote:Sure it does. Just replace getType() with int(&classinfo(*this)) or something similar.Better yet, use an associative array:int[ClassInfo] countSelected;Then, no need for getType(). Just use .classinfo of object.Which leads me to my point. So to call, " int getTotalSelectedOfType() { return countSelected(this.classinfo()); } " I'd have to be virutal and static right? Otherwise I'd have to have an existing object to call it. Also doesn't this denote the need for an object? I'd like to quarie the class.
Jul 22 2002
"anderson" <anderson firestar.com.au> wrote in message news:ahgls0$130b$1 digitaldaemon.com..."Pavel Minayev" <evilone omen.ru> wrote in message news:CFN374589713982292 news.digitalmars.com... On Sun, 21 Jul 2002 09:36:30 -0700 "Sean L. Palmer" <seanpalmer earthlink.net> wrote:return countSelected[this.classinfo()];Sure it does. Just replace getType() with int(&classinfo(*this)) or something similar.Better yet, use an associative array:int[ClassInfo] countSelected;Then, no need for getType(). Just use .classinfo of object.Which leads me to my point. So to call, " int getTotalSelectedOfType() {} " I'd have to be virutal and static right? Otherwise I'd have to have an existing object to call it. Also doesn'tthisdenote the need for an object? I'd like to quarie the class.
Jul 22 2002
On Mon=2C 22 Jul 2002 18=3A19=3A01 +0800 =22anderson=22 =3Canderson=40firestar=2Ecom=2Eau=3E wrote=3A =3E Which leads me to my point=2E =3E =3E So to call=2C =3E =3E =22 =3E int getTotalSelectedOfType=28=29 =3E { =3E return countSelected=28this=2Eclassinfo=28=29=29=3B =3E } =3E =22 =3E =3E I'd have to be virutal and static right=3F =3E =3E Otherwise I'd have to have an existing object to call it=2E Also doesn't this =3E denote the need for an object=3F I'd like to quarie the class=2E You can=2E Just let it take a classinfo as an argument=3A =09static int getTotalSelectedOfType=28ClassInfo ci=29 =09{ =09=09return countSelected=5Bci=5D=3B =09} And then=3A =09getTotalSelectedOfType=28Vertex=2Eclassinfo=29=3B
Jul 22 2002
Thanks. Cool, you could never do that in C++. CountSelected becomes practicly a VT anyway. I still think think things would have been simpler with virtual statics but this is close enough I suppose. //With virtual statics class GeometricPrimitive { private: static virtual int countSelected; bool selected; public: void setSelected() { selected = true; countSelected.length++; } bool isSelected() { return selected; } static virtual int getNumbSelected() { return countSelected; } } No need for arrays or anything, and it makes more sense.You can. Just let it take a classinfo as an argument:static int getTotalSelectedOfType(ClassInfo ci) { return countSelected[ci]; }And then:getTotalSelectedOfType(Vertex.classinfo);
Jul 22 2002
Whoops, forgot to remove the length++ "anderson" <anderson firestar.com.au> wrote in message news:ahia9e$2p7u$1 digitaldaemon.com...Thanks. Cool, you could never do that in C++. CountSelected becomes practicly a VT anyway. I still think think things would have been simpler with virtual statics but this is close enough I suppose. //With virtual statics class GeometricPrimitive { private: static virtual int countSelected; bool selected; public: void setSelected() { selected = true;countSelected++;} bool isSelected() { return selected; } static virtual int getNumbSelected() { return countSelected; } } No need for arrays or anything, and it makes more sense.You can. Just let it take a classinfo as an argument:static int getTotalSelectedOfType(ClassInfo ci) { return countSelected[ci]; }And then:getTotalSelectedOfType(Vertex.classinfo);
Jul 22 2002
On Tue, 23 Jul 2002 09:13:43 +0800 "anderson" <anderson firestar.com.au> wrote:Thanks. Cool, you could never do that in C++.Why? You can have map<type_info*, int>, and use typeid() operator.
Jul 23 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:CFN374606405046875 news.digitalmars.com...On Tue, 23 Jul 2002 09:13:43 +0800 "anderson" <anderson firestar.com.au>wrote:I should have rephrased that to "how could you do that in C++". Thanks.Thanks. Cool, you could never do that in C++.Why? You can have map<type_info*, int>, and use typeid() operator.
Jul 23 2002
On Fri, 19 Jul 2002 02:02:49 -0700 "Sean L. Palmer" <seanpalmer earthlink.net> wrote:int getType() { assert(false); } // how do you make pure virtual functions in D?abstract int getType();
Jul 21 2002
"Sean L. Palmer" <seanpalmer earthlink.net> wrote in message news:ah8k4f$1oop$1 digitaldaemon.com...Lines are not Vertices. Polygons are not Triangles. You should be using HasA, not IsA relationships.Your right! I was thinking of anther project where we used a static machine for with 4 states/modes: Vertex, edge, polygon and object. The idea was that the same operations (translate, scale, rotate, ect...) could be applied to groups of objects in differn't modes. Yes, getNumbSelected was one of them and could be used to get the total amount of vertexes, edges, polygons and objects. If in vertex mode it would return the number of vertexes for a single object. If in object mode it would return 1 if the object was selected. But that's besides the point. isA (I perfer java style here) should be applied to boolean types.
Jul 22 2002