473,386 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

RTTI - how to ?

I am passing data as a string arg to a function. I'd like to determine
whether the data is 'text' (i.e. alpha || alphanumeric), ineteger or
double).

enum
{
TEXT,
INTEGER,
DOUBLE
}DataType ;

DataType foo(const string& arg)
{
//determine data type
...
};

Any ideas how to do this ?

Jul 25 '06 #1
2 1228
Bit Byte wrote:
I am passing data as a string arg to a function. I'd like to determine
whether the data is 'text' (i.e. alpha || alphanumeric), ineteger or
double).

enum
{
TEXT,
INTEGER,
DOUBLE
}DataType ;

DataType foo(const string& arg)
{
//determine data type
...
};

Any ideas how to do this ?
Look up functions 'isalpha', 'isdigit', etc. The usual algorithm is: if
you can convert it *entirely* into a number, it's a number. If you try
converting and you have some symbols left over, it's not a number.

Also, read FAQ 5.2.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 25 '06 #2
Bit Byte wrote:
I am passing data as a string arg to a function. I'd like to determine
whether the data is 'text' (i.e. alpha || alphanumeric), ineteger or
double).

enum
{
TEXT,
INTEGER,
DOUBLE
}DataType ;

DataType foo(const string& arg)
{
//determine data type
...
};

Any ideas how to do this ?
First you'd have to come up with a list of criteria that define your 'text',
'integer' and 'double'. It is probably natural thing to do to arrange the
criteria in hierarchical fashion: first test for 'double', then for 'integer'
and the rest is 'text'. But what about the details of each format? Are you
planning to use the C++ language definitions for integer and floating-point
literals? Or maybe formats recognized by string conversion functions (like
'scanf' and 'strtol')? Or you have something else in mind? For example, is '0x1'
an 'integer' or a 'text'? Is '1e+5' an allowed format of your 'double'? What
about ' 5 ' (with these extra spaces)? Is it an 'integer' or a 'text'?

--
Best regards,
Andrey Tarasevich
Jul 25 '06 #3

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

Similar topics

9
by: Rick | last post by:
Hi, I wrote a few classes recently and am writing a small GC implementation for C++. I will be implementing my own gc_ptr type maintain a list where I'll store pointers to allocated memory. I...
2
by: shishir | last post by:
Please consider the following //file test.cpp #include <iostream> int main() { int x; try { throw x;
6
by: Kleidemos | last post by:
If I implement a simple RTTI system, more simple than C++ RTTI system for my program and this system is plus or minus: #define DEF_RTTI_BASE(name) virtual inline const char *Name(){ return...
9
by: Agoston Bejo | last post by:
Hello there, I would like to know what overheads there are to think of when using RTTI. I understand that enabling RTTI increases the sizes of the classes, but not the objects themselves. This...
2
by: denny | last post by:
Hey all, I know that dynamic_cast<> takes some time, but , for instance, is there a memoy cost associated in with it? Does it have to maintain a table in memory, thus bloating the runtime ram...
3
by: Steven T. Hatton | last post by:
I'm trying to work out a design for dynamically determining file types, and for generating new files of a given type. I'm curious to know what others think of my current strategy. Is it "so...
10
by: Neo | last post by:
what is RTTI? and how to implements it? give me sourceful link for learn and implements it (using standard C mean portable). regards, -aims
3
by: Neo | last post by:
Hi Friends, I have a question about RTTI. 1) In C++ we have vptr pointing to vtables which helps to make use of pointer as polymorphic entities. 2) Without knowing object type I can call methods...
5
by: dotNeter | last post by:
I'm studying the RTTI, and my current work is concern for how to get the self-defined type at runtime, that's exactly what the RTTI does. I mean, in my application, I built several self-defined...
2
by: Chameleon | last post by:
I know than dynamic_cast check string name of derived to base class and if one of them match, return the pointer of that object or else zero. I suppose, I dynamic_cast instead of strings, checks...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...

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.