?? ogrfielddefn.cpp
字號:
/******************************************************************************
* $Id: ogrfielddefn.cpp 10646 2007-01-18 02:38:10Z warmerdam $
*
* Project: OpenGIS Simple Features Reference Implementation
* Purpose: The OGRFieldDefn class implementation.
* Author: Frank Warmerdam, warmerda@home.com
*
******************************************************************************
* Copyright (c) 1999, Les Technologies SoftMap Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
****************************************************************************/
#include "ogr_feature.h"
#include "ogr_api.h"
#include "ogr_p.h"
CPL_CVSID("$Id: ogrfielddefn.cpp 10646 2007-01-18 02:38:10Z warmerdam $");
/************************************************************************/
/* OGRFieldDefn() */
/************************************************************************/
/**
* Constructor.
*
* @param pszNameIn the name of the new field.
* @param eTypeIn the type of the new field.
*/
OGRFieldDefn::OGRFieldDefn( const char * pszNameIn, OGRFieldType eTypeIn )
{
Initialize( pszNameIn, eTypeIn );
}
/************************************************************************/
/* OGRFieldDefn() */
/************************************************************************/
/**
* Constructor.
*
* Create by cloning an existing field definition.
*
* @param poPrototype the field definition to clone.
*/
OGRFieldDefn::OGRFieldDefn( OGRFieldDefn *poPrototype )
{
Initialize( poPrototype->GetNameRef(), poPrototype->GetType() );
SetJustify( poPrototype->GetJustify() );
SetWidth( poPrototype->GetWidth() );
SetPrecision( poPrototype->GetPrecision() );
// SetDefault( poPrototype->GetDefaultRef() );
}
/************************************************************************/
/* OGR_Fld_Create() */
/************************************************************************/
/**
* Create a new field definition.
*
* This function is the same as the CPP method OGRFieldDefn::OGRFieldDefn().
*
* @param pszName the name of the new field definition.
* @param eType the type of the new field definition.
* @return handle to the new field definition.
*/
OGRFieldDefnH OGR_Fld_Create( const char *pszName, OGRFieldType eType )
{
return (OGRFieldDefnH) (new OGRFieldDefn(pszName,eType));
}
/************************************************************************/
/* Initialize() */
/************************************************************************/
void OGRFieldDefn::Initialize( const char * pszNameIn, OGRFieldType eTypeIn )
{
pszName = CPLStrdup( pszNameIn );
eType = eTypeIn;
eJustify = OJUndefined;
nWidth = 0; // should these be defined in some particular way
nPrecision = 0; // for numbers?
memset( &uDefault, 0, sizeof(OGRField) );
}
/************************************************************************/
/* ~OGRFieldDefn() */
/************************************************************************/
OGRFieldDefn::~OGRFieldDefn()
{
CPLFree( pszName );
}
/************************************************************************/
/* OGR_Fld_Destroy() */
/************************************************************************/
/**
* Destroy a field definition.
*
* @param hDefn handle to the field definition to destroy.
*/
void OGR_Fld_Destroy( OGRFieldDefnH hDefn )
{
delete (OGRFieldDefn *) hDefn;
}
/************************************************************************/
/* SetName() */
/************************************************************************/
/**
* Reset the name of this field.
*
* This method is the same as the C function OGR_Fld_SetName().
*
* @param pszNameIn the new name to apply.
*/
void OGRFieldDefn::SetName( const char * pszNameIn )
{
CPLFree( pszName );
pszName = CPLStrdup( pszNameIn );
}
/************************************************************************/
/* OGR_Fld_SetName() */
/************************************************************************/
/**
* Reset the name of this field.
*
* This function is the same as the CPP method OGRFieldDefn::SetName().
*
* @param hDefn handle to the field definition to apply the new name to.
* @param pszName the new name to apply.
*/
void OGR_Fld_SetName( OGRFieldDefnH hDefn, const char *pszName )
{
((OGRFieldDefn *) hDefn)->SetName( pszName );
}
/************************************************************************/
/* GetNameRef() */
/************************************************************************/
/**
* \fn const char *OGRFieldDefn::GetNameRef();
*
* Fetch name of this field.
*
* This method is the same as the C function OGR_Fld_GetNameRef().
*
* @return pointer to an internal name string that should not be freed or
* modified.
*/
/************************************************************************/
/* OGR_Fld_GetNameRef() */
/************************************************************************/
/**
* Fetch name of this field.
*
* This function is the same as the CPP method OGRFieldDefn::GetNameRef().
*
* @param hDefn handle to the field definition.
* @return the name of the field definition.
*
*/
const char *OGR_Fld_GetNameRef( OGRFieldDefnH hDefn )
{
return ((OGRFieldDefn *) hDefn)->GetNameRef();
}
/************************************************************************/
/* GetType() */
/************************************************************************/
/**
* \fn OGRFieldType OGRFieldDefn::GetType();
*
* Fetch type of this field.
*
* This method is the same as the C function OGR_Fld_GetType().
*
* @return field type.
*/
/************************************************************************/
/* OGR_Fld_GetType() */
/************************************************************************/
/**
* Fetch type of this field.
*
* This function is the same as the CPP method OGRFieldDefn::GetType().
*
* @param hDefn handle to the field definition to get type from.
* @return field type.
*/
OGRFieldType OGR_Fld_GetType( OGRFieldDefnH hDefn )
{
return ((OGRFieldDefn *) hDefn)->GetType();
}
/************************************************************************/
/* SetType() */
/************************************************************************/
/**
* \fn void OGRFieldDefn::SetType( OGRFieldType eType );
*
* Set the type of this field. This should never be done to an OGRFieldDefn
* that is already part of an OGRFeatureDefn.
*
* This method is the same as the C function OGR_Fld_SetType().
*
* @param eType the new field type.
*/
/************************************************************************/
/* OGR_Fld_SetType() */
/************************************************************************/
/**
* Set the type of this field. This should never be done to an OGRFieldDefn
* that is already part of an OGRFeatureDefn.
*
* This function is the same as the CPP method OGRFieldDefn::SetType().
*
* @param hDefn handle to the field definition to set type to.
* @param eType the new field type.
*/
void OGR_Fld_SetType( OGRFieldDefnH hDefn, OGRFieldType eType )
{
((OGRFieldDefn *) hDefn)->SetType( eType );
}
/************************************************************************/
/* SetDefault() */
/************************************************************************/
/**
* Set default field value.
*
* Currently use of OGRFieldDefn "defaults" is discouraged. This feature
* may be fleshed out in the future.
*
*/
void OGRFieldDefn::SetDefault( const OGRField * puDefaultIn )
{
switch( eType )
{
case OFTInteger:
case OFTReal:
uDefault = *puDefaultIn;
break;
case OFTString:
// CPLFree( uDefault.String );
// uDefault.String = CPLStrdup( puDefaultIn->String );
break;
default:
// add handling for other complex types.
CPLAssert( FALSE );
break;
}
}
/************************************************************************/
/* GetFieldTypeName() */
/************************************************************************/
/**
* Fetch human readable name for a field type.
*
* This static method is the same as the C function OGR_GetFieldTypeName().
*
* @param eType the field type to get name for.
*
* @return pointer to an internal static name string. It should not be
* modified or freed.
*/
const char * OGRFieldDefn::GetFieldTypeName( OGRFieldType eType )
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -