Pointers for these pointers...?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DirtyClamDigger

    #1

    Pointers for these pointers...?

    Hi Everyone: I'm trying to develop a property list to include as
    metadata about my object classes. i.e. I want each class I'm developing
    to include a PropertyList which will contain ObjectProperty pointers.
    ObjectProperty is a class containing the typeid.name() of a type as
    it's ObjectType as well as an ObjectName and ObjectDescripti on.
    Basically 3 strings of metadata describing each of a class' member
    variables (and hopefully functions) so that the class can report to a
    query from another class what properties it has available for access at
    run time.

    Here is what I have and the error I'm getting:

    // ObjectProperty. hpp
    #pragma once
    #include <string>
    #include <list>
    #include <typeinfo>


    namespace Properties
    {
    template<typena me aProperty> class ObjectProperty
    {
    private:
    std::string PropertyName;
    std::string PropertyType;
    std::string PropertyDescrip tion;

    public:
    ObjectProperty(
    const std::string& _PropertyName,
    const std::string& _PropertyType,
    const std::string& _PropertyDescri ption ):
    PropertyName(_P ropertyName),
    PropertyType(_P ropertyType),
    PropertyDescrip tion(_PropertyD escription){}

    ObjectProperty(
    const std::string& _PropertyName,
    const std::string& _PropertyDescri ption ):
    PropertyName(_P ropertyName),
    PropertyType(ty peid(aProperty) .name()),
    PropertyDescrip tion(_PropertyD escription){}

    ObjectProperty( ):
    PropertyName(),
    PropertyType(ty peid(aProperty) .name()),
    PropertyDescrip tion(){}

    ~ObjectProperty (){}

    const std::string& getPropertyName () const
    {
    return PropertyName;
    }

    const std::string& getPropertyType () const
    {
    return PropertyType;
    }

    const std::string& getPropertyDesc ription() const
    {
    return PropertyDescrip tion;
    }

    void setPropertyName ( const std::string& _PropertyName )
    {
    PropertyName = _PropertyName;
    }

    void setPropertyType ( const std::string& _PropertyType )
    {
    PropertyType = _PropertyType;
    }

    void setPropertyDesc ription( const std::string& _PropertyDescri ption
    )
    {
    PropertyDescrip tion = _PropertyDescri ption;
    }
    };

    // a simple wrapper to have further functionality added
    class PropertyList
    {
    public:
    // will be made private later after I get it working :o)
    std::list<Objec tProperty*> theProperties;

    // public functions such as....
    // void displayProperti es();
    // const list<ObjectProp erty*>& getProperties() ;
    // bool compareProperti es(PropertyList &, PropertyList&);
    // ....
    };

    };

    // ObjectPropertyD river.cpp
    #include <iostream>
    #include "ObjectProperty .hpp"

    using namespace Properties;
    using namespace std;

    int main(void)
    {
    try
    {
    // active code

    PropertyList pl;
    ObjectProperty< char* >* op = new ObjectProperty< char* >("My char*
    Property", "My char* Property Description");
    pl.thePropertie s.push_back(op) ;

    return 0;
    }
    catch(...) // any old exception not already caught
    {
    cerr << "OOooops ... unexpected exception\n";
    }

    }

    Error 1 error C2664: 'std::list<_Ty> ::push_back' : cannot convert
    parameter 1 from 'Properties::Ob jectProperty<aP roperty> *' to
    'Properties::Ob jectProperty *const &' ...\objectprope rtydriver.cpp 15

    compiler is devstudio 8.blah....

    If I'm going about it completely wrong then a pointer in the right
    direction would be helpful, otherwise any suggestions at all are
    welcome....

    TIA,
    LJH.

  • Artie Gold

    #2
    Re: Pointers for these pointers...?

    DirtyClamDigger wrote:[color=blue]
    > Hi Everyone: I'm trying to develop a property list to include as
    > metadata about my object classes. i.e. I want each class I'm developing
    > to include a PropertyList which will contain ObjectProperty pointers.
    > ObjectProperty is a class containing the typeid.name() of a type as
    > it's ObjectType as well as an ObjectName and ObjectDescripti on.
    > Basically 3 strings of metadata describing each of a class' member
    > variables (and hopefully functions) so that the class can report to a
    > query from another class what properties it has available for access at
    > run time.
    >
    > Here is what I have and the error I'm getting:[/color]

    I'm not entirely clear on what you're doing (and I haven't spent
    sufficient time looking) but I this might help. See below:[color=blue]
    >
    > // ObjectProperty. hpp
    > #pragma once
    > #include <string>
    > #include <list>
    > #include <typeinfo>
    >
    >
    > namespace Properties
    > {
    > template<typena me aProperty> class ObjectProperty
    > {
    > private:
    > std::string PropertyName;
    > std::string PropertyType;
    > std::string PropertyDescrip tion;
    >
    > public:
    > ObjectProperty(
    > const std::string& _PropertyName,
    > const std::string& _PropertyType,
    > const std::string& _PropertyDescri ption ):
    > PropertyName(_P ropertyName),
    > PropertyType(_P ropertyType),
    > PropertyDescrip tion(_PropertyD escription){}
    >
    > ObjectProperty(
    > const std::string& _PropertyName,
    > const std::string& _PropertyDescri ption ):
    > PropertyName(_P ropertyName),
    > PropertyType(ty peid(aProperty) .name()),
    > PropertyDescrip tion(_PropertyD escription){}
    >
    > ObjectProperty( ):
    > PropertyName(),
    > PropertyType(ty peid(aProperty) .name()),
    > PropertyDescrip tion(){}
    >
    > ~ObjectProperty (){}
    >
    > const std::string& getPropertyName () const
    > {
    > return PropertyName;
    > }
    >
    > const std::string& getPropertyType () const
    > {
    > return PropertyType;
    > }
    >
    > const std::string& getPropertyDesc ription() const
    > {
    > return PropertyDescrip tion;
    > }
    >
    > void setPropertyName ( const std::string& _PropertyName )
    > {
    > PropertyName = _PropertyName;
    > }
    >
    > void setPropertyType ( const std::string& _PropertyType )
    > {
    > PropertyType = _PropertyType;
    > }
    >
    > void setPropertyDesc ription( const std::string& _PropertyDescri ption
    > )
    > {
    > PropertyDescrip tion = _PropertyDescri ption;
    > }
    > };
    >
    > // a simple wrapper to have further functionality added
    > class PropertyList
    > {
    > public:
    > // will be made private later after I get it working :o)
    > std::list<Objec tProperty*> theProperties;[/color]
    // ITYM:
    std::list<Objec tProperty<aProp erty>*> theProperties;

    // as ObjectProperty is a templated class[color=blue]
    >
    > // public functions such as....
    > // void displayProperti es();
    > // const list<ObjectProp erty*>& getProperties() ;
    > // bool compareProperti es(PropertyList &, PropertyList&);
    > // ....
    > };
    >
    > };
    >
    > // ObjectPropertyD river.cpp
    > #include <iostream>
    > #include "ObjectProperty .hpp"
    >
    > using namespace Properties;
    > using namespace std;
    >
    > int main(void)
    > {
    > try
    > {
    > // active code
    >
    > PropertyList pl;
    > ObjectProperty< char* >* op = new ObjectProperty< char* >("My char*
    > Property", "My char* Property Description");
    > pl.thePropertie s.push_back(op) ;
    >
    > return 0;
    > }
    > catch(...) // any old exception not already caught
    > {
    > cerr << "OOooops ... unexpected exception\n";
    > }
    >
    > }
    >
    > Error 1 error C2664: 'std::list<_Ty> ::push_back' : cannot convert
    > parameter 1 from 'Properties::Ob jectProperty<aP roperty> *' to
    > 'Properties::Ob jectProperty *const &' ...\objectprope rtydriver.cpp 15
    >
    > compiler is devstudio 8.blah....
    >
    > If I'm going about it completely wrong then a pointer in the right
    > direction would be helpful, otherwise any suggestions at all are
    > welcome....
    >[/color]
    See above.

    HTH,
    --ag


    --
    Artie Gold -- Austin, Texas
    http://goldsays.blogspot.com (new post 8/5)
    http://www.cafepress.com/goldsays
    "If you have nothing to hide, you're not trying!"

    Comment

    • DirtyClamDigger

      #3
      Re: Pointers for these pointers...?

      Thanks, Artie, but that doesn't seem to work either. What is bugging me
      is that if I comment out the push_back call in the code above then it
      compiles and runs fine. I'm simply trying to find a way to have a
      property list associated with each class I create so that I can query
      objects of that class as to the descriptions of their data. i.e. data
      about the data is called 'meta'data. In my mind that means having a
      static list of name/type/description triplets describing the
      datamembers of a class..

      e.g. // this code is just off the top of my head to demo my
      intent...don't expect correctness! :o)

      class aClass{
      public:

      int anInt;
      double aDouble;
      static PropertyList dataProperties;

      //...class def'ns etc...
      void loadProperites( ){
      ObjectProperty* <double> op = new ObjectProperty< double>("aDoubl e", "A
      Double defined for this dummy class);
      dataProperties. push_back(*op);
      }
      };...//end class

      Anyway, I tried your suggestion and it still fetches up with a type
      mismatch error. I guess I'm going to have to sit and think on it a bit
      more....

      Thanks anyway.

      regards,
      LJH

      Comment

      Working...