Hi, sorry for another problem... i have a simple question to ask...


lets say say i have base class


struct GeomObject
{
  // draws an wire shape
   virtual void drawAbstract(const GLfloat& x, const GLfloat& y, const GLfloat& z) = 0;
   // draws a solid shape.
   virtual void drawSolid(const GLfloat& x, const GLfloat& y, const GLfloat& z) = 0;
}


Now i have bunch of stuff that inherits it..

Like class Circle, class Sphere, class Cylinder, class Cone and all of them implement drawSolid and drawAbstract (radius base assumed).

I have a function call drawCircle(const std::string& r, (someBoostFunctionParam))
{
    Circle cir(4.0, r); // construct a circle with radius 4.0 and name r
    cir.someBoostFunctionParam(x, y, z);
}

thus if i say drawCircle("solid", &Circle::drawSolid);
drawCircle("abstract", &Circle::drawAbstract);
 
 
How do you do that? Or whats the best way to do it.

 
On 8/22/06, François Duranleau <duranlef@iro.umontreal.ca > wrote:
On Mon, 21 Aug 2006, chun ping wang wrote:

[...]
> template <class T>
> boost::function<void*(const T&, const T&, const T&)> getVerxFunc3()
> {
>  BOOST_STATIC_ASSERT(boost::is_integral<T>::value ||
> boost::is_floating_point<T>::value);
>  return (boost::is_integral<T>::value) ? &glVertex3i : &glVertex3d;
> }
>
[...]
>
> template <class T>
> void drawDot(const T& x, const T& y, const T& z) {
>    boost::function<void(const T&, const T&, const T&)>
> myFunc(getVerxFunc3<T>());
>    glBegin(GL_POINTS);
>       myFunc(x, y, z);
>    glEnd();
>    glFlush();
> }
>
[just kept one example from the above]

Isn't using boost::function overkill here? I would rather do this:

template < typename T >
void gl_vertex( const T& x , const T& y , const T& z )
{
    // you can use the BOOST_STATIC_ASSERT as above here, or use
    // boost::enable_if with the same condition around the void return

    if ( boost::is_floating_point< T >::value )
    {
        glVertex3d( x , y , z ) ;
    }
    else
    {
        glVertex3i( x , y , z ) ;
    }
}

or even simply this:

void gl_vertex( GLdouble x , GLdouble y , GLdouble z )
{
    glVertex3d( x , y , z ) ;
}

void gl_vertex( GLint x , GLint y , GLint z )
{
    glVertex3i( x , y , z ) ;
}

and then:

template < typename T >
void drawDot( const T& x , const T& y , const T& z )
{
    glBegin( GL_POINTS ) ;
    gl_vertex( x , y , z ) ;
    glEnd() ;
}

That should be more efficient and, especially for the second case, is a
simpler to read overall.

Anyway, just my two cents.

--
François Duranleau
LIGUM, Université de Montréal

"Sacrifices are a necessary factor in creating a new destiny. A small
misfortune becomes the cornerstone of a greater happiness."
                         - Emperor Dornkirk, in _The Vision of Escaflowne_

_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users