Click here to Skip to main content
Click here to Skip to main content

A set of universal data check functions

, 24 Dec 2002
Rate this:
Please Sign up or sign in to vote.
A set of universal data check functions can be used in any systems with checking requirement.
<!-- Add the rest of your HTML here -->

Introduction

We need to check the range of user data in many program. It is a hell for us to verify all data for a program with several thousands parameters. The best way is to check it automatically. In order to make it running , the trivial thing is how to write check routings in uniform way. I got it. Just a simple tips in C++. I provide the source code for every body. In later articles , I will give you a special control for using these routines in universal way. Smile | :)

Checking theory

The basic theory to check the range of data is very simple but trivial. In mathematical, the range of data is domain. In a 1D condition , a domain has one or two limits, one for large boundary and one for small boundary . Usually , we write it as [min,max] for close domain or (min , max ) as open domain. Our check routines shall include all kinds conditions we may encountered.

I list the following condition:

1) Let it be , no any check !
2) given number must be less than the limit.                    number < min
3) given number must be great than the limit.                    number > max
4) given number must be within a range                        min < number < max
5) given number must be less or equal to limit                    number <= min
6) given number must be great or equal to limit                    number >= max
7) given number must be within a range with lower equal                    min<= number < max
8) given number must be within a range with greater equal              min < number <= max
9) given number must be within a range equal to bound                min <= number <= max
10) given number must be outside a range without equal                  number < min  AND number > max
11) given number must be outside a range with lower equal              number <= min  AND number > max
12) given number must be outside a range with lower equal              number < min  AND number >= max
13) given number must be outside a range with lower equal              number <= min  AND number >= max
 The following condition is important for compatility.
14 ) given number must be less than the limit ( the limit is set as max )    number <max
15 ) given number must be great than the limit ( the limit is set as min )    number >min
16 ) given number must be less than or equal to  the limit ( the limit is set as max ) number <= max
17 ) given number must be great than or equal to  the limit ( the limit is set as min ) number >=min

Dealing data type

Another headache is how to use these rulers on every kind of data structures. C++ provides server method, such as string , double , int ,long , datetime etc. Each has different way to check. That the relation sign has different meaning. The unsafe way is providing a macro. I think the better way is using template of C++, which is strong type , can make our code more safe when running.

template<class T>
BOOL internalCheckLess( T& value , T& minv, T& maxv)
{
    return value < minv;
}

template<class T>
BOOL internalCheckGreat( T& value , T& minv, T& maxv)
{
    return value > maxv;
}

template<class T>
BOOL internalCheckLessMax( T& value , T& minv, T& maxv)
{
    return value < maxv;
}

template<class T>
BOOL internalCheckGreatMin( T& value , T& minv, T& maxv)
{
    return value > minv;
}

template<class T>
BOOL internalCheckLessMaxEqu( T& value , T& minv, T& maxv)
{
    return value <= maxv;
}

template<class T>
BOOL internalCheckGreatMinEqu( T& value , T& minv, T& maxv)
{
    return value >= minv;
}


template<class T>
BOOL internalCheckBoth( T& value , T& minv, T& maxv)
{
    return value > minv && value < maxv ;
}


template<class T>
BOOL internalCheckLessEqu( T& value , T& minv, T& maxv)
{
    return value <= minv;
}

template<class T>
BOOL internalCheckGreatEqu( T& value , T& minv, T& maxv)
{
    return value >= maxv;
}


template<class T>
BOOL internalCheckBothEqu( T& value , T& minv, T& maxv)
{
    return value >= minv && value <= maxv ;
}

template<class T>
BOOL internalCheckBothLessEqu( T& value , T& minv, T& maxv)
{
    return value >= minv && value < maxv ;
}

template<class T>
BOOL internalCheckBothGreatEqu( T& value , T& minv, T& maxv)
{
    return value > minv && value <= maxv ;
}
template<class T>
BOOL internalCheckOutEqu( T& value , T& minv, T& maxv)
{
    return value <= minv && value >= maxv ;
}

template<class T>
BOOL internalCheckOutLessEqu( T& value , T& minv, T& maxv)
{
    return value <= minv && value > maxv ;
}

template<class T>
BOOL internalCheckOutGreatEqu( T& value , T& minv, T& maxv)
{
    return value < minv && value >= maxv ;
}

template<class T>
BOOL internalCheckOut( T& value , T& minv, T& maxv)
{
    return value < minv && value > maxv ;
}

Promption

When the checking routine found that an error occurred when user inputted data, we shall raise a message to user and tell him or her that what kind of error found. Normally , we will give out a messagebox with reason . The message will be displayed according to user specified. We collect all error message in a header file for easy to be change according to their language or more proper words. We can write a function for each data type.

Why not to use class

May be it is a good idea to write these function as a class . It is a light method to write these in functions . I think it is more covinent to use function than writing a class. I will demonstrate how to use these function in a control group in next article which will be coming soon.

That’s all ! Enjoy it.

History

  Version            Author                    Date                Content
  ===========================================================================
  0.9                Johnson Zhou        2002/08/01              Initial
  1.0                Johnson Zhou        2002/12/07              Write internal function as template
  1.01                Johnson Zhou        2002/12/25              Add function of 14)-17).

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Johnson Zhou
Software Developer (Senior)
China China
I'm write program from 1990. My research field is CAG,CAD and Image processing. I select C/C++, ASP, Java, XML as my usaully developing tools. Occasional , write code in Delphi and VB. I'm using Visual C++ from 1996. If you have anything unclear, e-mail to :zhou_cn123@sina.com Software Engineering and CAD is my mainly research program.
 
You also can reach me on msn: zhoujohnson@hotmail.com

Comments and Discussions

 
Generalomg PinmemberHeToC21-Dec-06 0:29 
QuestionBOOL ? PinmemberChristian Graus26-Dec-02 15:00 
GeneralNot necessary PinmemberReinout Hillmann25-Dec-02 23:08 
GeneralRe: Not necessary PinmemberJohnson Zhou26-Dec-02 19:41 
QuestionHuh? PinmemberDaniel Turini25-Dec-02 10:08 
AnswerRe: Huh? PinmemberJohnson Zhou26-Dec-02 19:38 
GeneralHum... PinmemberTak25-Dec-02 6:46 
GeneralRe: Hum... PinmemberJohnson Zhou26-Dec-02 19:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411023.1 | Last Updated 25 Dec 2002
Article Copyright 2002 by Johnson Zhou
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid