f



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 ObjectDescription.
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<typename aProperty> class ObjectProperty
	{
	private:
		std::string PropertyName;
		std::string PropertyType;
		std::string PropertyDescription;

	public:
		ObjectProperty(
			const std::string& _PropertyName,
			const std::string& _PropertyType,
			const std::string& _PropertyDescription ):
			PropertyName(_PropertyName),
			PropertyType(_PropertyType),
			PropertyDescription(_PropertyDescription){}

		ObjectProperty(
			const std::string& _PropertyName,
			const std::string& _PropertyDescription ):
			PropertyName(_PropertyName),
			PropertyType(typeid(aProperty).name()),
			PropertyDescription(_PropertyDescription){}

		ObjectProperty():
			PropertyName(),
			PropertyType(typeid(aProperty).name()),
			PropertyDescription(){}

		~ObjectProperty(){}

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

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

		const std::string& getPropertyDescription() const
		{
			return PropertyDescription;
		}

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

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

		void setPropertyDescription( const std::string& _PropertyDescription
)
		{
			PropertyDescription = _PropertyDescription;
		}
	};

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

		// public functions such as....
		// void displayProperties();
		// const list<ObjectProperty*>& getProperties();
		// bool compareProperties(PropertyList&, PropertyList&);
		// ....
	};

};

// ObjectPropertyDriver.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.theProperties.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::ObjectProperty<aProperty> *' to
'Properties::ObjectProperty *const &'	...\objectpropertydriver.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.

0
2/6/2006 10:16:23 PM
comp.lang.c++ 49423 articles. 7 followers. Post Follow

2 Replies
658 Views

Similar Articles

[PageSpeed] 14

DirtyClamDigger wrote:
> 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 ObjectDescription.
> 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:

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:
> 
> // ObjectProperty.hpp
> #pragma once
> #include <string>
> #include <list>
> #include <typeinfo>
> 
> 
> namespace Properties
> {
> 	template<typename aProperty> class ObjectProperty
> 	{
> 	private:
> 		std::string PropertyName;
> 		std::string PropertyType;
> 		std::string PropertyDescription;
> 
> 	public:
> 		ObjectProperty(
> 			const std::string& _PropertyName,
> 			const std::string& _PropertyType,
> 			const std::string& _PropertyDescription ):
> 			PropertyName(_PropertyName),
> 			PropertyType(_PropertyType),
> 			PropertyDescription(_PropertyDescription){}
> 
> 		ObjectProperty(
> 			const std::string& _PropertyName,
> 			const std::string& _PropertyDescription ):
> 			PropertyName(_PropertyName),
> 			PropertyType(typeid(aProperty).name()),
> 			PropertyDescription(_PropertyDescription){}
> 
> 		ObjectProperty():
> 			PropertyName(),
> 			PropertyType(typeid(aProperty).name()),
> 			PropertyDescription(){}
> 
> 		~ObjectProperty(){}
> 
> 		const std::string& getPropertyName() const
> 		{
> 			return PropertyName;
> 		}
> 
> 		const std::string& getPropertyType() const
> 		{
> 			return PropertyType;
> 		}
> 
> 		const std::string& getPropertyDescription() const
> 		{
> 			return PropertyDescription;
> 		}
> 
> 		void setPropertyName( const std::string& _PropertyName )
> 		{
> 			PropertyName = _PropertyName;
> 		}
> 
> 		void setPropertyType( const std::string& _PropertyType )
> 		{
> 			PropertyType = _PropertyType;
> 		}
> 
> 		void setPropertyDescription( const std::string& _PropertyDescription
> )
> 		{
> 			PropertyDescription = _PropertyDescription;
> 		}
> 	};
> 
> 	// a simple wrapper to have further functionality added
> 	class PropertyList
> 	{
> 	public:
> 		// will be made private later after I get it working :o)
> 		std::list<ObjectProperty*> theProperties;
// ITYM:
                 std::list<ObjectProperty<aProperty>*> theProperties;

// as ObjectProperty is a templated class
> 
> 		// public functions such as....
> 		// void displayProperties();
> 		// const list<ObjectProperty*>& getProperties();
> 		// bool compareProperties(PropertyList&, PropertyList&);
> 		// ....
> 	};
> 
> };
> 
> // ObjectPropertyDriver.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.theProperties.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::ObjectProperty<aProperty> *' to
> 'Properties::ObjectProperty *const &'	...\objectpropertydriver.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....
> 
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!"
0
artiegold (849)
2/7/2006 3:41:09 AM
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>("aDouble", "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

0
2/7/2006 6:35:43 AM
Reply: