Filter Library Camera Interface Physics

ControlIntegerEdit.cpp

00001 /*
00002  * ControlIntegerEdit.cpp - an integer entry field.
00003  *
00004  * This file is part of the Camera Filter Library.
00005  * Computer Aided Measurement Environment for Realtime Atomic imaging (Camera)
00006  *
00007  * Copyright (C) 2004, Leiden Probe Microscopy.
00008  * Copyright (C) 2004, Universiteit Leiden.
00009  *
00010  * Authors: Martin J. Moene (original)
00011  *
00012  * $Id: ControlIntegerEdit.cpp 150 2005-04-25 09:02:30Z moene $
00013  */
00014 
00015 #include "stdafx.h"                     // for common (pre-compiled) headers
00016 //#include <cfl/stdafx.h>                 // for common (pre-compiled) headers
00017 #include <cfl/ControlIntegerEdit.h>     // for class CIntegerEdit
00018 
00019 IMPLEMENT_DYNAMIC( CIntegerEdit, CFilterEdit )
00020 
00021 /**
00022  * true if input is complete and valid.
00023  */
00024 
00025 bool CIntegerEdit::Check( const CString &csText )
00026 {
00027    char *ePtr;
00028    (void) _tcstol( csText, &ePtr, m_bUseBase ? 0 : 10 );
00029    return _TCHAR('\0') == *ePtr;
00030 }
00031 
00032 /**
00033  * true if partial input is acceptable.
00034  */
00035 
00036 bool CIntegerEdit::Match( const CString &csText )
00037 {
00038    int base = 10;
00039 
00040    const TCHAR* cPtr = csText;
00041 
00042    // optional sign?
00043 
00044    if ( _TCHAR('+') == *cPtr || ( m_bSigned && _TCHAR('-') == *cPtr ) )
00045    {
00046       ++cPtr;
00047    }
00048 
00049    // test for leading octal/hexadecimal 0, unless base not used:
00050 
00051    if ( m_bUseBase && _TCHAR('0') == *cPtr )
00052    {
00053       ++cPtr;
00054       base = 8;
00055    }
00056 
00057    // test for leading hexadecimal 0x, 0X, unless base not used (base is 10):
00058 
00059    if ( 8 == base && ( _TCHAR('x') == *cPtr || _TCHAR('X') == *cPtr ) )
00060    {
00061       ++cPtr;
00062       base = 16;
00063    }
00064 
00065    // scan remaining digits:
00066 
00067    if ( 8 == base )
00068    {
00069       while ( *cPtr && _TCHAR('0') <= *cPtr && *cPtr <= _TCHAR('7') )
00070         ++cPtr;
00071    }
00072    else if ( 10 == base )
00073    {
00074       while ( *cPtr && _istdigit( *cPtr ) )
00075         ++cPtr;
00076    }
00077    else if ( 16 == base )
00078    {
00079       while ( *cPtr && _istxdigit( *cPtr ) )
00080         ++cPtr;
00081    }
00082 
00083    // ok if all characters matched:
00084    return cPtr == (const TCHAR*) csText + csText.GetLength();
00085 }
00086 
00087 /*
00088  * end of file
00089  */

Camera Filter Library documentation © 2004-2007 by Leiden Probe Microscopy