1 : /******************************************************************************
2 : * $Id: ntf_codelist.cpp 10645 2007-01-18 02:22:39Z warmerdam $
3 : *
4 : * Project: NTF Translator
5 : * Purpose: NTFCodeList class implementation.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2001, Frank Warmerdam
10 : *
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #include <stdarg.h>
31 : #include "ntf.h"
32 : #include "cpl_conv.h"
33 : #include "cpl_string.h"
34 :
35 : CPL_CVSID("$Id: ntf_codelist.cpp 10645 2007-01-18 02:22:39Z warmerdam $");
36 :
37 : /************************************************************************/
38 : /* NTFCodeList */
39 : /************************************************************************/
40 :
41 0 : NTFCodeList::NTFCodeList( NTFRecord * poRecord )
42 :
43 : {
44 : int iThisField;
45 : const char *pszText;
46 :
47 : CPLAssert( EQUAL(poRecord->GetField(1,2),"42") );
48 :
49 0 : strcpy( szValType, poRecord->GetField(13,14) );
50 0 : strcpy( szFInter, poRecord->GetField(15,19) );
51 :
52 0 : nNumCode = atoi(poRecord->GetField(20,22));
53 :
54 0 : papszCodeVal = (char **) CPLMalloc(sizeof(char*) * nNumCode );
55 0 : papszCodeDes = (char **) CPLMalloc(sizeof(char*) * nNumCode );
56 :
57 0 : pszText = poRecord->GetData() + 22;
58 0 : for( iThisField=0;
59 : *pszText != '\0' && iThisField < nNumCode;
60 : iThisField++ )
61 : {
62 : char szVal[128], szDes[128];
63 : int iLen;
64 :
65 0 : iLen = 0;
66 0 : while( *pszText != '\\' && *pszText != '\0' )
67 0 : szVal[iLen++] = *(pszText++);
68 0 : szVal[iLen] = '\0';
69 :
70 0 : if( *pszText == '\\' )
71 0 : pszText++;
72 :
73 0 : iLen = 0;
74 0 : while( *pszText != '\\' && *pszText != '\0' )
75 0 : szDes[iLen++] = *(pszText++);
76 0 : szDes[iLen] = '\0';
77 :
78 0 : if( *pszText == '\\' )
79 0 : pszText++;
80 :
81 0 : papszCodeVal[iThisField] = CPLStrdup(szVal);
82 0 : papszCodeDes[iThisField] = CPLStrdup(szDes);
83 : }
84 :
85 0 : if( iThisField < nNumCode )
86 : {
87 0 : nNumCode = iThisField;
88 : CPLDebug( "NTF",
89 0 : "Didn't get all the expected fields from a CODELIST." );
90 : }
91 0 : }
92 :
93 : /************************************************************************/
94 : /* ~NTFCodeList() */
95 : /************************************************************************/
96 :
97 0 : NTFCodeList::~NTFCodeList()
98 :
99 : {
100 0 : for( int i = 0; i < nNumCode; i++ )
101 : {
102 0 : CPLFree( papszCodeVal[i] );
103 0 : CPLFree( papszCodeDes[i] );
104 : }
105 :
106 0 : CPLFree( papszCodeVal );
107 0 : CPLFree( papszCodeDes );
108 0 : }
109 :
110 : /************************************************************************/
111 : /* Lookup() */
112 : /************************************************************************/
113 :
114 0 : const char *NTFCodeList::Lookup( const char * pszCode )
115 :
116 : {
117 0 : for( int i = 0; i < nNumCode; i++ )
118 : {
119 0 : if( EQUAL(pszCode,papszCodeVal[i]) )
120 0 : return papszCodeDes[i];
121 : }
122 :
123 0 : return NULL;
124 : }
125 :
126 :
|