⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fields.cpp

📁 一个通讯管理机的源代码。比较好用。推荐
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************                          fields.cpp  -  description                             -------------------    begin                : Thu Jan 17 2002    copyright            : (C) 2002 by     email                :  ***************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************//*  $Id: fields.cpp,v 1.8 2001/01/27 05:00:32 dbryson Exp $    Xbase project source code    This file contains the basic X-Base routines for reading and writing    Xbase fields.    Copyright (C) 1997  StarTech, Gary A. Kunkel       This library is free software; you can redistribute it and/or    modify it under the terms of the GNU Lesser General Public    License as published by the Free Software Foundation; either    version 2.1 of the License, or (at your option) any later version.    This library is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public    License along with this library; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    Contact:      Mail:        Technology Associates, Inc.        XBase Project        1455 Deming Way #11        Sparks, NV 89434        USA      Email:        xbase@techass.com      See our website at:        xdb.sourceforge.net    V 1.0    10/10/97   - Initial release of software    V 1.5    1/2/98     - Added Dbase IV Memo field support    V 1.6a   4/1/98     - Added expression support    V 1.6b   4/8/98     - Numeric index keys    V 1.7.4b 7/2/98     - Changed gcvt to sprintf for portability reasons - PS             9/29/98    - Added GetLogicalField()             10/7/98    - Modified PutFloatField - was broke    V 1.8    11/30/98   - Version 1.8 upgrade - additional PutFloat Field fix*/#ifdef __WIN32__#include "xbconfigw32.h"#else#include "xbconfig.h"#endif#include "xbase.h"#include <stdlib.h>#include <string.h>#include "xbexcept.h"/*! \file fields.cpp*//************************************************************************//* This function returns true if the data is valid logical data         *///! Determines if data is valid logical data./*! Determines if the data in buf is valid for a logical field value.        \param buf data to be tested    \returns TRUE (non-zero) if valid, FALSE (zero) if not.*/xbShort xbDbf::ValidLogicalData(const char * buf) {   if( buf[0] )     if( buf[0] == 'T' || buf[0] == 't' || buf[0] == 'F' || buf[0] == 'f' ||         buf[0] == 'Y' || buf[0] == 'y' || buf[0] == 'N' || buf[0] == 'n' ||         buf[0] == '?' )       return 1;   return 0; }/************************************************************************//* This function returns true if the data is valid numeric data         *///! Determines if data is valid numeric data./*! Determines if the data in buf is valid for a numeric field value.    \param buf    \returns TRUE (non-zero) if valid, FALSE (zero) if not.*/xbShort xbDbf::ValidNumericData(const char * buf) {   const char *p;   p = buf;   while( *p )   {      if( *p != '+' && *p != '-' && *p != '.' && *p != '0' && *p != '1' &&          *p != '2' && *p != '3' && *p != '4' && *p != '5' && *p != '6' &&          *p != '7' && *p != '8' && *p != '9' )         return 0;      else         p++;   }   return 1;}/************************************************************************//* This function returns a fields length *///! Returns the length of the specified field./*! Returns the length of the field specified by FieldNo.    \param FieldNo Number of field.    \returns Length of the specified field in bytes.*/xbShort xbDbf::GetFieldLen( const xbShort FieldNo ){   if( FieldNo >= 0 && FieldNo < NoOfFields )   {     if( SchemaPtr[FieldNo].Type == 'C' && SchemaPtr[FieldNo].NoOfDecs > 0 )       return SchemaPtr[FieldNo].LongFieldLen;     else           return SchemaPtr[FieldNo].FieldLen;   }   else      return 0;}/************************************************************************//* This function returns a fields decimal length *///! Returns the number of decimals in the specified field./*! Returns the number decimals in the field specified by FieldNo.      \param FieldNo Number of field.    \returns Number of decimals in the specified field.*/xbShort xbDbf::GetFieldDecimal( const xbShort FieldNo ){   if( FieldNo >= 0 && FieldNo < NoOfFields )      return SchemaPtr[FieldNo].NoOfDecs;   else      return 0;}/************************************************************************//* This function returns a fields type *///! Returns the type of the specified field./*! Returns the type of the field specified by FieldNo.    \param FieldNo Number of field.    \returns Type of specified field.*/char xbDbf::GetFieldType( const xbShort FieldNo ) const{   if( FieldNo >= 0 && FieldNo < NoOfFields )      return SchemaPtr[FieldNo].Type;   else      return 0;}/************************************************************************//* This function returns a fields name *///! Returns the name of the specified field./*! Returns a pointer to the name for the field specified by FieldNo.    \param FieldNo Number of field.    \returns A pointer to the name of the field.*/char * xbDbf::GetFieldName( const xbShort FieldNo ){   if( FieldNo >= 0 && FieldNo < NoOfFields )      return SchemaPtr[FieldNo].FieldName;   else      return 0;}/************************************************************************//* This function returns the field ID number for a given field   or -1 if the field is not one of the fields of the database  *///! Returns the field number of the specified field./*! Returns the field number for the named field.    \param name Name of field.    \returns Number of field named name.*/xbShort xbDbf::GetFieldNo( const char * name ) const{   int i, len1, len2;   if(( len1 = strlen( name )) > 10 )      return -1;   for( i = 0; i < NoOfFields; i++ )   {     len2 = strlen( SchemaPtr[i].FieldName );     if( len1 == len2 )//        if( strstr( SchemaPtr[i].FieldName, name )) return i;#ifndef __WIN32__        if(!strcasecmp( SchemaPtr[i].FieldName, name )) #else        if(!stricmp( SchemaPtr[i].FieldName, name )) #endif           return i;   }   return -1;}/************************************************************************//*   Helpers*///! Get the value of the specified field./*! Get the value of the field referenced by Name and place its value    in buf.        \param Name Name of field.    \param buf Buffer to hold field value.  Must be large enough to hold               the entire field value.  Use GetFieldLen() to determine               the length of the field, if necessary.    \param RecBufSw    \returns One of the following:*/xbShort xbDbf::GetField(const char *Name, char *buf,         const xbShort RecBufSw ) const{   return GetField(GetFieldNo(Name), buf, RecBufSw);}//! Get the value of the specified field./*! Get the value of the field specified by Name and place its value    in buf.        \param Name Name of field.    \param buf Buffer to hold field value.  Must be large enough to hold               the entire field value.  Use GetFieldLen() to determine               the length of the field, if necessary.    \returns One of the following:*/xbShort xbDbf::GetField(const char *Name, char *buf) const{   return GetField(GetFieldNo(Name), buf);}//! Get the raw value of the specified field./*! Get the value of the field specified by Name and place its value    in buf.        \param Name Name of field.    \param buf Buffer to hold field value.  Must be large enough to hold               the entire field value.  Use GetFieldLen() to determine               the length of the field, if necessary.    \returns One of the following:*/xbShort xbDbf::GetRawField(const char *Name, char *buf) const{   return GetRawField(GetFieldNo(Name), buf);}static char __buf[1024];static void trim(char *s) {  int len = strlen(s)-1;  if (len > 0) {    while ((len != 0) && (s[len] == ' '))      len--;    s[len+1] = 0;  }}//! Get the value of the specified field./*! Returns the value of the field specified by Name.    \param Name Name of field.    \returns Value of the specified field.*/const char *xbDbf::GetField(const char *Name) const {   GetField(GetFieldNo(Name), __buf);   trim(__buf);   return __buf;}//! Get the value of the specified field./*! Returns the value of the field specified by FieldNo.    \param FieldNo Number of field.    \returns Value of the specified field.*/const char *xbDbf::GetField(xbShort FieldNo) const {   GetField(FieldNo, __buf);   trim(__buf);   return __buf;}/************************************************************************//* This function fills a buffer with data from the record buffer   for a particular field number.    Use GetFieldNo to get a number based on a field's name    If successful, this function returns the field size.*///! Get the value of the specified field./*! Get the value of the field specified by FieldNo and place its value    in buf.        \param FieldNo Number of field.    \param buf Buffer to hold field value.  Must be large enough to hold               the entire field value.  Use GetFieldLen() to determine               the length of the field, if necessary.    \param RecBufSw    \returns The length of the field.*/xbShort xbDbf::GetField(const xbShort FieldNo, char * buf,          const xbShort RecBufSw) const{     xbShort length = 0;             if( FieldNo < 0 || FieldNo >= NoOfFields ) {#ifdef HAVE_EXCEPTIONS       xb_error(XB_INVALID_FIELDNO);#else       buf[0] = 0x00;       return 0x00;#endif      }   // Check for existence of a long field length   if( SchemaPtr[FieldNo].Type == 'C' && SchemaPtr[FieldNo].NoOfDecs > 0 )     length = SchemaPtr[FieldNo].LongFieldLen;   else     length = SchemaPtr[FieldNo].FieldLen;   if( RecBufSw )     memcpy( buf, SchemaPtr[FieldNo].Address2, length );   else     memcpy( buf, SchemaPtr[FieldNo].Address, length );   buf[length] = 0x00;   return( length ); }/************************************************************************/xbShort xbDbf::GetField(const xbShort FieldNo, xbString & sf,          const xbShort RecBufSw) const{     xbShort length = 0;             if( FieldNo < 0 || FieldNo >= NoOfFields ) {#ifdef HAVE_EXCEPTIONS       sf = "";       xb_error(XB_INVALID_FIELDNO);#else        sf = "";       return 0;#endif      }   // Check for existence of a long field length

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -