root/tags/rel-5-0-2/mapserver/classobject.c

Revision 6434, 5.9 kB (checked in by dmorissette, 1 year ago)

Removed unused styleObj.isachild member (#2169)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /******************************************************************************
2  *
3  * Project:  MapServer
4  * Purpose:  Functions for operating on a classObj that don't belong in a
5  *           more specific file such as mapfile.c. 
6  *           Adapted from mapobject.c.
7  * Author:   Sean Gillies, sgillies@frii.com
8  *
9  ******************************************************************************
10  * Copyright (c) 2004, Sean Gillies
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included in
20  * all copies of this Software or works derived from this Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  * DEALINGS IN THE SOFTWARE.
29  ****************************************************************************/
30
31 #include "mapserver.h"
32
33 #ifdef USE_GDAL
34 include "gdal.h"
35 include "cpl_conv.h"
36 #endif
37
38 MS_CVSID("$Id$")
39
40 /**
41  * Move the style up inside the array of styles.
42  */ 
43 int msMoveStyleUp(classObj *class, int nStyleIndex)
44 {
45     styleObj *psTmpStyle = NULL;
46     if (class && nStyleIndex < class->numstyles && nStyleIndex >0)
47     {
48         psTmpStyle = (styleObj *)malloc(sizeof(styleObj));
49         initStyle(psTmpStyle);
50        
51         msCopyStyle(psTmpStyle, class->styles[nStyleIndex]);
52
53         msCopyStyle(class->styles[nStyleIndex],
54                     class->styles[nStyleIndex-1]);
55        
56         msCopyStyle(class->styles[nStyleIndex-1], psTmpStyle);
57
58         return(MS_SUCCESS);
59     }
60     msSetError(MS_CHILDERR, "Invalid index: %d", "msMoveStyleUp()",
61                nStyleIndex);
62     return (MS_FAILURE);
63 }
64
65
66 /**
67  * Move the style down inside the array of styles.
68  */ 
69 int msMoveStyleDown(classObj *class, int nStyleIndex)
70 {
71     styleObj *psTmpStyle = NULL;
72
73     if (class && nStyleIndex < class->numstyles-1 && nStyleIndex >=0)
74     {
75         psTmpStyle = (styleObj *)malloc(sizeof(styleObj));
76         initStyle(psTmpStyle);
77        
78         msCopyStyle(psTmpStyle, class->styles[nStyleIndex]);
79
80         msCopyStyle(class->styles[nStyleIndex],
81                     class->styles[nStyleIndex+1]);
82        
83         msCopyStyle(class->styles[nStyleIndex+1], psTmpStyle);
84
85         return(MS_SUCCESS);
86     }
87     msSetError(MS_CHILDERR, "Invalid index: %d", "msMoveStyleDown()",
88                nStyleIndex);
89     return (MS_FAILURE);
90 }
91
92 /* Moved here from mapscript.i
93  *
94  * Returns the index at which the style was inserted
95  *
96  */
97 int msInsertStyle(classObj *class, styleObj *style, int nStyleIndex) {
98     int i;
99
100     if (!style)
101     {
102         msSetError(MS_CHILDERR, "Can't insert a NULL Style", "msInsertStyle()");
103         return -1;
104     }
105
106     /* Ensure there is room for a new style */
107     if (msGrowClassStyles(class) == NULL) {
108         return -1;
109     }
110     /* Catch attempt to insert past end of styles array */
111     else if (nStyleIndex >= class->numstyles) {
112         msSetError(MS_CHILDERR, "Cannot insert style beyond index %d", "insertStyle()", class->numstyles-1);
113         return -1;
114     }
115     else if (nStyleIndex < 0) { /* Insert at the end by default */
116         class->styles[class->numstyles]=style;
117         MS_REFCNT_INCR(style);
118         class->numstyles++;
119         return class->numstyles-1;
120     }
121     else if (nStyleIndex >= 0 && nStyleIndex < class->numstyles) {
122         /* Move styles existing at the specified nStyleIndex or greater */
123         /* to a higher nStyleIndex */
124         for (i=class->numstyles-1; i>=nStyleIndex; i--) {
125             class->styles[i+1] = class->styles[i];
126         }
127         class->styles[nStyleIndex]=style;
128         MS_REFCNT_INCR(style);
129         class->numstyles++;
130         return nStyleIndex;
131     }
132     else {
133         msSetError(MS_CHILDERR, "Invalid nStyleIndex", "insertStyle()");
134         return -1;
135     }
136 }
137
138 styleObj *msRemoveStyle(classObj *class, int nStyleIndex) {
139     int i;
140     styleObj *style;
141     if (class->numstyles == 1) {
142         msSetError(MS_CHILDERR, "Cannot remove a class's sole style", "removeStyle()");
143         return NULL;
144     }
145     else if (nStyleIndex < 0 || nStyleIndex >= class->numstyles) {
146         msSetError(MS_CHILDERR, "Cannot remove style, invalid nStyleIndex %d", "removeStyle()", nStyleIndex);
147         return NULL;
148     }
149     else {
150         style=class->styles[nStyleIndex];
151         for (i=nStyleIndex; i<class->numstyles-1; i++) {
152              class->styles[i]=class->styles[i+1];
153         }
154         class->styles[class->numstyles-1]=NULL;
155         class->numstyles--;
156         MS_REFCNT_DECR(style);
157         return style;
158     }
159 }
160
161 /**
162  * Delete the style identified by the index and shift
163  * styles that follows the deleted style.
164  */ 
165 int msDeleteStyle(classObj *class, int nStyleIndex)
166 {
167     int i = 0;
168     if (class && nStyleIndex < class->numstyles && nStyleIndex >=0)
169     {
170         if (freeStyle(class->styles[nStyleIndex]) == MS_SUCCESS)
171             msFree(class->styles[nStyleIndex]);
172         for (i=nStyleIndex; i< class->numstyles-1; i++)
173         {
174             class->styles[i] = class->styles[i+1];
175         }
176         class->styles[class->numstyles-1] = NULL;
177         class->numstyles--;
178         return(MS_SUCCESS);
179     }
180     msSetError(MS_CHILDERR, "Invalid index: %d", "msDeleteStyle()",
181                nStyleIndex);
182     return (MS_FAILURE);
183 }
Note: See TracBrowser for help on using the browser.