473,795 Members | 2,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Wild Cards?

Hi, I was wondering if there is any type of way to specify a generic
type for a list. I basicaly have

class shape {
}

class circle: public shape {
};

class triangle: public shape {
};

template <class T>
class red : public T {
}

template <class T>
class blue : public T {
}

template <class T>
class Blueish : public blue<T{
}

now I have a class that manages all blueish objects

class BlueishManager {
public:
void Add(Blueish<sha pe>* ent) ....
private:
list<Blueish<sh ape>* __list;
}

The problem is casting a Blueish<triangl eto a Blueish<shapeca uses
all the functions of the Blueish<triange to be overwritten. The shape
part still will call all of the Triangle data, but I create a new
Blueish class. Is there anyway I can make a functions like in java
(I'm no java programer but I have seen it)

list<Blueish<? shape>*__list; So I don't have to cast my objects to
add them?

Right now I have to have a diffrent list for each object

list<Blueish<tr iangle>*__listT riangle;
list<Blueish<ci rcle>*__listCir cle;

but that might be a pain later if I add a new shape!

Thanks

Matt

Dec 5 '06 #1
4 5200

Ma************* @gmail.com wrote:
Hi, I was wondering if there is any type of way to specify a generic
type for a list. I basicaly have

class shape {
}

class circle: public shape {
};

class triangle: public shape {
};

template <class T>
class red : public T {
}

template <class T>
class blue : public T {
}

template <class T>
class Blueish : public blue<T{
}

now I have a class that manages all blueish objects

class BlueishManager {
public:
void Add(Blueish<sha pe>* ent) ....
private:
list<Blueish<sh ape>* __list;
}

The problem is casting a Blueish<triangl eto a Blueish<shapeca uses
all the functions of the Blueish<triange to be overwritten. The shape
part still will call all of the Triangle data, but I create a new
Blueish class. Is there anyway I can make a functions like in java
(I'm no java programer but I have seen it)

list<Blueish<? shape>*__list; So I don't have to cast my objects to
add them?

Right now I have to have a diffrent list for each object

list<Blueish<tr iangle>*__listT riangle;
list<Blueish<ci rcle>*__listCir cle;

but that might be a pain later if I add a new shape!

Thanks

Matt
Your inheritance hierachy is a little strange. I see more in common
between a red_triangle and a blue_triangle than between a red_rectangle
and a red_circle.
Anyway, You could argue that all shapes have_a color, including a
default of Gray or B&W.
Note that is not an is_a relationship. A shape is *not* a color.

class Color { ... };
class Gray : public Color { ... };
class Blue : public Color { ... }; // etc

template < typename C = Gray >
class shape
{
C color; // shapes -have- color
public:
shape() : color() { } // default ctor for target color invoked
virtual ~shape() = 0;
virtual double area() const = 0;
};

template< typename C = Gray >
class triangle : public: shape< C >
{
double height;
double width;
public:
triangle() : height(0.0), width(0.0) { }
...
double area() const { return 0.5 * height * width; }
};

#include <list>

int main()
{
triangle< /*Gray*/ gray_tri;
std::list< shape< /*Gray*/ >* graylist;
graylist.push_b ack( &gray_tri );

std::list < shape< Blue >* bluelist;
// and so on
}

What you may not want to sacrifice, is those properties that make a
traingle a triangle. Example: how you calculate its area() vs how a
rectangle or circle calculate area().
Color is nothing more than part of the object's composition.

Dec 5 '06 #2

Thank you so much for the quick responce! That is a great sugestion,
but it was just an example. I wanted to more get down to the wild card
equivelent in C++, I will look at my code again and see if I can
restructure it, but here is how it rests right now. It's a computer
graphics program that allows you to create diffrent types of tangable
entities, Mobile, Fixed, Active, and asigning them modifiers, a mesh or
camera

class Entity {}

class MobileEntity {}

class FixedEntity {}

template <class T>
class Mobile: public MobileEntity, public T {}

template <class T>
class Fixed:public FixedEntity, public T {}

template <clas T>
class Active: public Mobile<T{}

class Modifier {}

class Mesh : public Modifier {}

class Camera: public Modifier {}
The diffrence between mobile and fixed is the functions they have for
moving around the 3d world.
Active give the function addKey() and then recieves key presses which
can move the mobile object

Now to make an object i say

Mobile<Mesh>* actMesh= new Mobile<Mesh>;

Now Mobile<Meshis a mobile entity, that is a mesh

I don't know if it would make sence to say it is a MobileEntity that
HAS a Mesh because of how the functions are accessed, if I want to
dynamicaly call mesh functions for a list of all types of Mobile,
Fixed, and Active entities i can cast it as a mesh and call thoes,
instead of having to have something inside Mobile Active, and Fixed
classes

((Mesh*)actMesh )->getBoudningSph ere();
I will have to think of it a little more I'm sure it is quite possible
to change it to the format you sugested, and if this format still seems
strange to you I will look more into it! But using it so far has
seemed intuitive, the only problem comes when I can have a list of a
Entities with diffrent modifiers I.E. Mobile<MeshMobi le<Camera>, I
have to store a diffrent list for each one.

but again, is there any way to do wildcards in c++? Or is it nessisary
to figure out a diffrent structure?

list<Active<? Modifier>*__lis t

On Dec 5, 2:37 pm, "Salt_Peter " <pj_h...@yahoo. comwrote:
MattWilson.6... @gmail.com wrote:
Hi, I was wondering if there is any type of way to specify a generic
type for a list. I basicaly have
class shape {
}
class circle: public shape {
};
class triangle: public shape {
};
template <class T>
class red : public T {
}
template <class T>
class blue : public T {
}
template <class T>
class Blueish : public blue<T{
}
now I have a class that manages all blueish objects
class BlueishManager {
public:
void Add(Blueish<sha pe>* ent) ....
private:
list<Blueish<sh ape>* __list;
}
The problem is casting a Blueish<triangl eto a Blueish<shapeca uses
all the functions of the Blueish<triange to be overwritten. The shape
part still will call all of the Triangle data, but I create a new
Blueish class. Is there anyway I can make a functions like in java
(I'm no java programer but I have seen it)
list<Blueish<? shape>*__list; So I don't have to cast my objects to
add them?
Right now I have to have a diffrent list for each object
list<Blueish<tr iangle>*__listT riangle;
list<Blueish<ci rcle>*__listCir cle;
but that might be a pain later if I add a new shape!
Thanks
MattYour inheritance hierachy is a little strange. I see more in common
between a red_triangle and a blue_triangle than between a red_rectangle
and a red_circle.
Anyway, You could argue that all shapes have_a color, including a
default of Gray or B&W.
Note that is not an is_a relationship. A shape is *not* a color.

class Color { ... };
class Gray : public Color { ... };
class Blue : public Color { ... }; // etc

template < typename C = Gray >
class shape
{
C color; // shapes -have- color
public:
shape() : color() { } // default ctor for target color invoked
virtual ~shape() = 0;
virtual double area() const = 0;

};template< typename C = Gray >
class triangle : public: shape< C >
{
double height;
double width;
public:
triangle() : height(0.0), width(0.0) { }
...
double area() const { return 0.5 * height * width; }

};#include <list>

int main()
{
triangle< /*Gray*/ gray_tri;
std::list< shape< /*Gray*/ >* graylist;
graylist.push_b ack( &gray_tri );

std::list < shape< Blue >* bluelist;
// and so on

}What you may not want to sacrifice, is those properties that make a
traingle a triangle. Example: how you calculate its area() vs how a
rectangle or circle calculate area().
Color is nothing more than part of the object's composition.
Dec 5 '06 #3
Ma************* @gmail.com wrote:
Thank you so much for the quick responce! That is a great sugestion,
but it was just an example. I wanted to more get down to the wild card
equivelent in C++, I will look at my code again and see if I can
restructure it, but here is how it rests right now.
Forget wildcards. Java's generics have almost nothing in common with C++
templates other than notation.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Dec 5 '06 #4
Alright thank you! So the best solution then is to restructure?

Matt

On Dec 5, 3:57 pm, Pete Becker <p...@versatile coding.comwrote :
MattWilson.6... @gmail.com wrote:
Thank you so much for the quick responce! That is a great sugestion,
but it was just an example. I wanted to more get down to the wild card
equivelent in C++, I will look at my code again and see if I can
restructure it, but here is how it rests right now.Forget wildcards. Java's generics have almost nothing in common with C++
templates other than notation.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Dec 5 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1727
by: Steve T | last post by:
I have just contracted with a firm that is using a front-end web interface to access our sales data. They developed it with Microsoft Dotnet, and it uses Microsoft SQL as the database. When I search test/note fields, they say I have to do a wild card search *word* to pull up any records with "word" in that field. With our previous vendor, and with many other web accessable data bases I search you usually do not need the wild cards,...
2
2173
by: kelvSYC | last post by:
I'm trying to program something along the lines of a "trading card" idea: I have a single copy of the "card" in the program, yet there may be multiple "instances" of the "card", with differing information (such as the owner of the "card") in each instance. struct Person; Person Bob; Person Joe;
2
3143
by: Pawe³ | last post by:
Hello! I'm looking for efficient code or site where I can find code for finding one string in another string. String which I search should have "wild" characters like '?' for any one char and '*' for any string of characters. I'm looking for way to effective getting string from text file and then searching it like I write above. Thanks in advance for any helps, notices or sites
3
2395
by: topmind | last post by:
I need to search for database text with underlines in it. However, underlines are interpreted as wild-cards in LIKE clause text . I need to know how to escape the underlines so as to be able to search them. Some DB's use an "Escape" keyword and others use a back-slash to escape wild-cards. However, Jet does not seem to support either of these. Note that I am accessing Access files via ODBC and ADO (or is it DAO?) and not through Access...
1
2765
by: panchaga | last post by:
Hi, could any one help me with this select statement. i am using as part of JSP page. i want to use wild cards as part of this select. i am getting error when i use % along with the name. rs = statement.executeQuery("SELECT * FROM lessons WHERE fname='"+ name+ "'"); Thanks
10
4963
by: Arun Nair | last post by:
Can any one help me with this im not getting it even after reading books because there is not much of discussion anywhere a> Implement a calss that represents a playing card. The class should implement the following methods: _ _ init _ _ (self, rank, suit) Creates a card. rank is an integer in range of 1 to 13 (Ace:1, King 13), suit is a character in set {'h','d','c','s'} getRank(self) Returns the rank of the card
1
1876
by: Nitinkcv | last post by:
Hi, I have a textbox and a button. In my textbox i have to enter the query string(say shoes) and on clicking the button takes me to a page show all item related to the search string( in this case shoes). But on mixing the search string with wildcards it displays that no items could be found. For eg: for search string s@h^o$e@s it would go to the error page. So is there ant way i could like extract the wildcards out of my search string...
8
29171
by: garyrowell | last post by:
I have been at this programme for hours trying to work out what is wrong. Any help would be very much appricated. Here is the breif I received. The program This week you are going to write three classes: Card.java, Deck.java and DeckTester.java. The specification for each class is given below. Card.Java This is a simple class that represents a playing card. Card has two attributes: • rank which is a String that represents the value...
7
9261
by: W. eWatson | last post by:
Is it possible to do a search for a wild card string in another string. For example, I'd like to find "v*.dat" in a string called bingo. v must be matched against only the first character in bingo, and not simply found somewhere in bingo, as might be the case for "*v*.dat". -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.