polymorphism with vars?

This is a discussion on polymorphism with vars? within the C++ Programming forums, part of the General Programming Boards category; how to do something similar to what in http://cboard.cprogramming.com/showthread.php?t=109803 "partial polymorphism" but this time with variables and specifically with enum ...

  1. #1
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251

    polymorphism with vars?

    how to do something similar to what in partial polymorphism
    "partial polymorphism"

    but this time with variables and specifically with enum
    I want a var to be enum and have certain values defined for a base class while other values predefined in the base class and redefined by derived classes

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,306
    What is the purpose of this enum?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I don't think you can do what you want exactly - but if you describe better what you are trying to do, perhaps we can help you with a solution.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251
    well i have different stations with parameters that can be written or read
    there is a set of parameters which is common to all stations
    other parameters instead are specific for each station

    i need an uint index to identify which parameter to read (or write) upon request
    i need this index to be for instance of kind enum with a base set for the common indexing and a derived specific set of values for the specific indexing

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,306
    Quote Originally Posted by mynickmynick
    well i have different stations with parameters that can be written or read
    there is a set of parameters which is common to all stations
    other parameters instead are specific for each station
    I am afraid that I do not quite understand what is a "station" and what is a "parameter", and how they are related. When you say that you have different stations, do you mean that you have different station objects, or that you have different station subtypes?

    Quote Originally Posted by mynickmynick
    i need an uint index to identify which parameter to read (or write) upon request
    i need this index to be for instance of kind enum with a base set for the common indexing and a derived specific set of values for the specific indexing
    Let's not go into implementation detail so soon. What is a "request"? Who will be making such a request?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251
    Here follows what the code i am writing looks like
    Station is a Vision System with one or more cameras
    parameters are image processing parameters or camera parameters

    Code:
    typedef class c_StationParameters
    {
    public:
    	Type_StationArgs * Args;
    	unsigned int ToBeSaved;//periodically checked. If ==1 old parameters are backupped, new parameters are saved then this bool is reset
    	MUTEX  ReadImageMutex;
    	//List of Station non specific parameters (they can have different values for every station but there type is the same for all)
    	float MaxProcessingMsec;	float MaxProcessingMsecRI;
    	
    	//..other parameters to be added here
    	//..
    	
    	//METHODS
    	virtual ~c_StationParameters(){};
    	
    	//General methods
    	int LoadStationParameters( unsigned int Backup);
    	int CheckStationParameters(); //to be rewritten like Load with the non virtual interface
    	int SaveStationParameters();
    	int UpdateStationParametersReadImage();
    	
    	//Specific methods
    	virtual int LoadStationSpecificParameters( FILE  *ParFile)=0;//{printf("Calling wrong method!! ######################\n");return(0);};
    	virtual int CheckStationSpecificParameters()=0;
    	virtual int BackupStationSpecificParameters(FILE  *ParFile, FILE  *ParFile_BP)=0;//{return(0);};
    	virtual int SaveStationSpecificParameters(FILE  *ParFile)=0;//{return(0);};
    	virtual int UpdateStationSpecificParametersReadImage()=0;
    	
    } ALIGN Type_StationParameters;
    
    
    
    typedef class c_Station1_Parameters : public c_StationParameters
    {//this part is strictly station dependent
    
    public:	
    
    	
    
    	
    	virtual int LoadStationSpecificParameters(  FILE  *ParFile);
    	virtual int CheckStationSpecificParameters();
    	virtual int BackupStationSpecificParameters(FILE  *ParFile, FILE  *ParFile_BP);
    	virtual int SaveStationSpecificParameters(FILE  *ParFile);	
    	
    public:
    	//first image processing parameters
    	//0...1024
    	float Img1RulerX;  float Img1RulerXRI;
    
    	
    	//second image processing parameters
    	//0...1024
    	float Img2RulerX;  float Img2RulerXRI;
    
    	
    	//Processing parameters
    	//0...2048
    	float PacketAngleTolerance; float PacketAngleToleranceRI;
    
    
    } ALIGN Type_Station1_Parameters;
    Last edited by mynickmynick; 01-07-2009 at 03:51 AM.

  7. #7
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251
    RI="ReadImage"
    Of each parameter is made periodically a Read Copy so that each parameter has one copy used only by the station and another copy shared between the Station thread and the socket server thread for read requests (protected by ReadImageMutex)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polymorphism - "pointers" or "references"?
    By Petike in forum C++ Programming
    Replies: 10
    Last Post: 06-04-2009, 06:06 PM
  2. A C++ program examples showing Polymorphism, please help.
    By MarkSquall in forum C++ Programming
    Replies: 19
    Last Post: 06-06-2008, 05:41 AM
  3. Polymorphism
    By GiN0 in forum C++ Programming
    Replies: 1
    Last Post: 03-23-2007, 07:18 PM
  4. change sorting method using polymorphism
    By Forever82 in forum C++ Programming
    Replies: 2
    Last Post: 07-31-2003, 02:21 PM
  5. Polymorphism & Overloaded Operators :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 09-13-2002, 09:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21