Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > overloaded name + inheritance

Reply
Thread Tools

overloaded name + inheritance

 
 
jrraines
Guest
Posts: n/a
 
      03-20-2010
There is an arduino library for LCD displays called LiquidCrystal. At
present the class has the ability to handle either 4 or 8 data pins
and various forms of testing the LCD's busy flag. The initial part of
the declaration looks like this:
class LiquidCrystal : public Print {
public:
LiquidCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);

LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);


LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);

LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, uint8_t en2,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); //4x40 LCD w
2x HD44780 controller chips, 2 enable lines to select between them 4
data pins

LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, uint8_t en2,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, void (*userFunc)
(int8_t chip) ); //4x40 LCD w 2x HD44780 controller chips, 2 enable
lines to select between them 4 data pins

LiquidCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);

LiquidCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3 , void (*userFunc)
(int8_t chip));

The overloaded versions here imply that either 4 or 8 data pins will
be used and all but one implies the specific form of the busy flag
test. Presently each user gets object code that includes both 4 and 8
bit capability and all versions of the busy test. It strikes me that I
could refactor this with a protoclass that would include the common
elements, then create new protoclasses that would handle either 4 or 8
bits and finally create 7 classes that included just the appropriate
busy test and code for 4 or 8 pins. I think each user would save
several hundred bytes by eliminating the unnecessary portions of code.
Some flags and flag testing would also vanish. On a little 8 bit
Arduino, that is a significant benefit. The piece that I'm struggling
with is whether it is possible to do this without changing the
apparent API--can I have 7 versions that have the same overloaded name
and have each of them inherit differently?
 
Reply With Quote
 
 
 
 
Michael Tsang
Guest
Posts: n/a
 
      03-22-2010
On Sunday, March 21, 2010 03:58 AM, jrraines wrote:
> There is an arduino library for LCD displays called LiquidCrystal. At
> present the class has the ability to handle either 4 or 8 data pins
> and various forms of testing the LCD's busy flag. The initial part of
> the declaration looks like this:
> class LiquidCrystal : public Print {
> public:
> LiquidCrystal(uint8_t rs, uint8_t enable,
> uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
> uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
>
> LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
> uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
> uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
>
>
> LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
> uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
>
> LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, uint8_t en2,
> uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); //4x40 LCD w
> 2x HD44780 controller chips, 2 enable lines to select between them 4
> data pins
>
> LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, uint8_t en2,
> uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, void (*userFunc)
> (int8_t chip) ); //4x40 LCD w 2x HD44780 controller chips, 2 enable
> lines to select between them 4 data pins
>
> LiquidCrystal(uint8_t rs, uint8_t enable,
> uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
>
> LiquidCrystal(uint8_t rs, uint8_t enable,
> uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3 , void (*userFunc)
> (int8_t chip));
>
> The overloaded versions here imply that either 4 or 8 data pins will
> be used and all but one implies the specific form of the busy flag
> test. Presently each user gets object code that includes both 4 and 8
> bit capability and all versions of the busy test. It strikes me that I
> could refactor this with a protoclass that would include the common
> elements, then create new protoclasses that would handle either 4 or 8
> bits and finally create 7 classes that included just the appropriate
> busy test and code for 4 or 8 pins. I think each user would save
> several hundred bytes by eliminating the unnecessary portions of code.
> Some flags and flag testing would also vanish. On a little 8 bit
> Arduino, that is a significant benefit. The piece that I'm struggling
> with is whether it is possible to do this without changing the
> apparent API--can I have 7 versions that have the same overloaded name
> and have each of them inherit differently?


You are showing the constructors only. Constructors cannot be inherited.
(although you can explicitly inherit them by a using declaration in C++0x)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inheritance of overloaded ++ operator issue John Wickerbee C++ 0 10-02-2011 05:24 PM
Inheritance of overloaded vararg methods RobertEstelle@gmail.com C++ 8 12-17-2007 12:06 AM
Re: Inheritance of overloaded functions Joe P C++ 1 06-21-2005 01:52 AM
overloaded functions in multiple inheritance. DX C++ 3 06-11-2004 09:05 PM
overloaded functions in multiple inheritance. DX C++ 0 06-11-2004 08:47 PM



Advertisments