summaryrefslogtreecommitdiffstats
path: root/sdo-cpp/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SequenceImpl.h
blob: 90505d047e9da3212586eb4bd12e8d8e3bbfd7c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 *   
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

/* $Rev$ $Date$ */

#ifndef _SEQUENCEIMPL_H_
#define _SEQUENCEIMPL_H_

#include "commonj/sdo/disable_warn.h"

#include <vector>


#include "commonj/sdo/Sequence.h"
#include "commonj/sdo/SDODate.h"

#define SequenceImplPtr RefCountingPointer<SequenceImpl> 

namespace commonj{
namespace sdo{

class Property; /* forward declaration */
class DataObjectImpl;

/**  SequenceImpl implements the abstract class Sequence.
 *
 * A sequence is a heterogeneous list of properties and corresponding values.
 * It represents an ordered arbitrary mixture of data values from more 
 * than one property of a {@link DataObject data object}.
 */

class SequenceImpl : public Sequence 
{
    public:
    ///////////////////////////////////////////////////////////////////////////
    // Returns the number of entries in the sequence.
    // @return the number of entries.
    ///////////////////////////////////////////////////////////////////////////
    virtual unsigned int size();

    ///////////////////////////////////////////////////////////////////////////
    // Returns the property for the given entry index.
    ///////////////////////////////////////////////////////////////////////////
    virtual const Property& getProperty(unsigned int index);

    /**
     * Return the data object associated with this sequence
     */

    SDO_API virtual const DataObjectPtr getDataObject();

    ///////////////////////////////////////////////////////////////////////////
    // Returns the property for the given entry index.
    ///////////////////////////////////////////////////////////////////////////
    virtual unsigned int getIndex(const Property& p, unsigned int pindex=0);
    virtual unsigned int getIndex(const char* propName, unsigned int pindex=0);

    virtual unsigned int getListIndex(unsigned int index);
    
    Type::Types getTypeEnum(unsigned int index);

    
    ///////////////////////////////////////////////////////////////////////////
    // Returns the property value for the given entry index.
    // @param index the index of the entry.
    // @return the value for the given entry index..
    ///////////////////////////////////////////////////////////////////////////
    virtual const char* getCStringValue(unsigned int index);
    virtual bool        getBooleanValue(unsigned int index);
    virtual char        getByteValue(unsigned int index);
    virtual wchar_t     getCharacterValue(unsigned int index);
    virtual unsigned int getStringValue(unsigned int index, wchar_t* val, unsigned int max);
    virtual unsigned int getBytesValue(unsigned int index, char* val, unsigned int max);
    virtual short       getShortValue(unsigned int index);
    virtual long         getIntegerValue(unsigned int index);    
    virtual int64_t     getLongValue(unsigned int index);
    virtual float       getFloatValue(unsigned int index);
    virtual long double getDoubleValue(unsigned int index);
    virtual const SDODate   getDateValue(unsigned int index);
    virtual DataObjectPtr getDataObjectValue(unsigned int index);
    virtual const SDOValue&        getSDOValue(unsigned int index);

    virtual unsigned int getLength(unsigned int index);
 
    ///////////////////////////////////////////////////////////////////////////
    // sets the entry at a specified index to the new value.
    // @param index the index of the entry.
    // @param value the new value for the entry.
    ///////////////////////////////////////////////////////////////////////////

    virtual void setCStringValue(   unsigned int index, const char* s );
    virtual void setBooleanValue(   unsigned int index, bool        b );
    virtual void setByteValue(      unsigned int index, char        c );
    virtual void setCharacterValue( unsigned int index, wchar_t     c );
    virtual void setBytesValue(     unsigned int index, const char* s , unsigned int len);
    virtual void setStringValue(    unsigned int index, const wchar_t* s , unsigned int len);
    virtual void setShortValue(     unsigned int index, short       s );
    virtual void setIntegerValue(       unsigned int index, long         i );    
    virtual void setLongValue(  unsigned int index, int64_t     l );
    virtual void setFloatValue(     unsigned int index, float       f );
    virtual void setDoubleValue(    unsigned int index, long double d );
    virtual void setDateValue(    unsigned int index, const SDODate t );
    virtual void setDataObjectValue(unsigned int index, DataObjectPtr d );
    

        ///////////////////////////////////////////////////////////////////////////
    // adds a new entry with the specified property name and value
    // to the end of the entries.
    // @param propertyName the name of the entry's property.
    // @param value the value for the entry.
    ///////////////////////////////////////////////////////////////////////////
    virtual bool addCString(   const char* propertyName,const char* s );
    virtual bool addBoolean(   const char* propertyName,bool        b );
    virtual bool addByte(      const char* propertyName,char        c );
    virtual bool addCharacter( const char* propertyName,wchar_t     c );
    virtual bool addString(    const char* propertyName,const wchar_t* s , unsigned int len);
    virtual bool addBytes(     const char* propertyName,const char* s , unsigned int len);
    virtual bool addShort(     const char* propertyName,short       s );
    virtual bool addInteger(   const char* propertyName,long         i );    
    virtual bool addLong(      const char* propertyName,int64_t     l );
    virtual bool addFloat(     const char* propertyName,float       f );
    virtual bool addDouble(    const char* propertyName,long double d );
    virtual bool addDate(      const char* propertyName,const SDODate t );
    virtual bool addDataObject(const char* propertyName,DataObjectPtr d );
    virtual bool addSDOValue(const char* propertyName, const SDOValue& sval);

    
    ///////////////////////////////////////////////////////////////////////////
    // adds a new entry with the specified property index and value
    // to the end of the entries.
    // @param propertyIndex the index of the entry's property.
    // @param value the value for the entry.
    ///////////////////////////////////////////////////////////////////////////
    virtual bool addCString(   unsigned int propertyIndex,const char* s );
    virtual bool addBoolean(   unsigned int propertyIndex,bool        b );
    virtual bool addByte(      unsigned int propertyIndex,char        c );
    virtual bool addCharacter( unsigned int propertyIndex,wchar_t     c );
    virtual bool addString(    unsigned int propertyIndex,const wchar_t* s , unsigned int len);
    virtual bool addBytes(     unsigned int propertyIndex,const char* s , unsigned int len);
    virtual bool addShort(     unsigned int propertyIndex,short       s );
    virtual bool addInteger(   unsigned int propertyIndex,long         i );    
    virtual bool addLong(      unsigned int propertyIndex,int64_t     l );
    virtual bool addFloat(     unsigned int propertyIndex,float       f );
    virtual bool addDouble(    unsigned int propertyIndex,long double d );
    virtual bool addDate(      unsigned int propertyIndex,const SDODate t );
    virtual bool addDataObject(unsigned int propertyIndex,DataObjectPtr d );
    virtual bool addSDOValue(unsigned int propertyIndex, const SDOValue& sval);


    ///////////////////////////////////////////////////////////////////////////
    // adds a new entry with the specified property and value
    // to the end of the entries.
    // @param property the property of the entry.
    // @param value the value for the entry.
    ///////////////////////////////////////////////////////////////////////////

    virtual bool addCString(   const Property& property,const char* s );
    virtual bool addBoolean(   const Property& property,bool        b );
    virtual bool addByte(      const Property& property,char        c );
    virtual bool addCharacter( const Property& property,wchar_t     c );
    virtual bool addString(    const Property& property,const wchar_t* s , unsigned int len);
    virtual bool addBytes(     const Property& property,const char* s , unsigned int len);
    virtual bool addShort(     const Property& property,short       s );
    virtual bool addInteger(   const Property& property,long         i );    
    virtual bool addLong(      const Property& property,int64_t     l );
    virtual bool addFloat(     const Property& property,float       f );
    virtual bool addDouble(    const Property& property,long double d );
    virtual bool addDate(      const Property& property,const SDODate t );
    virtual bool addDataObject(const Property& property,DataObjectPtr d );
    virtual bool addSDOValue(const Property& property, const SDOValue& sval);


    ///////////////////////////////////////////////////////////////////////////
    // adds a new entry with the specified property name and value
    // at the specified entry index.
    // @param index the index at which to add the entry.
    // @param propertyName the name of the entry's property.
    // @param value the value for the entry.
    ///////////////////////////////////////////////////////////////////////////
    virtual bool addCString(   unsigned int index,const char* propertyName,const char* s );
    virtual bool addBoolean(   unsigned int index,const char* propertyName,bool        b );
    virtual bool addByte(      unsigned int index,const char* propertyName,char        c );
    virtual bool addCharacter( unsigned int index,const char* propertyName,wchar_t     c );
    virtual bool addString(    unsigned int index,const char* propertyName,const wchar_t* s , unsigned int len);
    virtual bool addBytes(     unsigned int index,const char* propertyName,const char* s , unsigned int len);
    virtual bool addShort(     unsigned int index,const char* propertyName,short       s );
    virtual bool addInteger(   unsigned int index,const char* propertyName,long         i );    
    virtual bool addLong(      unsigned int index,const char* propertyName,int64_t     l );
    virtual bool addFloat(     unsigned int index,const char* propertyName,float       f );
    virtual bool addDouble(    unsigned int index,const char* propertyName,long double d );
    virtual bool addDate(      unsigned int index,const char* propertyName,const SDODate t );
    virtual bool addDataObject(unsigned int index,const char* propertyName,DataObjectPtr d );
    virtual bool addSDOValue(unsigned int index, const char* propertyName, const SDOValue& sval);

    ///////////////////////////////////////////////////////////////////////////
    // adds a new entry with the specified property index and value
    // at the specified entry index.
    // @param index the index at which to add the entry.
    // @param propertyIndex the index of the entry's property.
    // @param value the value for the entry.
    ///////////////////////////////////////////////////////////////////////////
    virtual bool addCString(   unsigned int index,unsigned int propertyIndex,const char* s );
    virtual bool addBoolean(   unsigned int index,unsigned int propertyIndex,bool        b );
    virtual bool addByte(      unsigned int index,unsigned int propertyIndex,char        c );
    virtual bool addCharacter( unsigned int index,unsigned int propertyIndex,wchar_t     c );
    virtual bool addString(    unsigned int index,unsigned int propertyIndex,const wchar_t* s , unsigned int len);
    virtual bool addBytes(     unsigned int index,unsigned int propertyIndex,const char* s , unsigned int len);
    virtual bool addShort(     unsigned int index,unsigned int propertyIndex,short       s );
    virtual bool addInteger(   unsigned int index,unsigned int propertyIndex,long         i );    
    virtual bool addLong(      unsigned int index,unsigned int propertyIndex,int64_t     l );
    virtual bool addFloat(     unsigned int index,unsigned int propertyIndex,float       f );
    virtual bool addDouble(    unsigned int index,unsigned int propertyIndex,long double d );
    virtual bool addDate(      unsigned int index,unsigned int propertyIndex,const SDODate t );
    virtual bool addDataObject(unsigned int index,unsigned int propertyIndex,DataObjectPtr d );
    virtual bool addSDOValue(unsigned int index, unsigned int propertyIndex, const SDOValue& sval);

    ///////////////////////////////////////////////////////////////////////////
    // adds a new entry with the specified property and value
    // at the specified entry index.
    // @param index the index at which to add the entry.
    // @param property the property of the entry.
    // @param value the value for the entry.
    ///////////////////////////////////////////////////////////////////////////
    virtual bool addCString(   unsigned int index,const Property& property,const char* s );
    virtual bool addBoolean(   unsigned int index,const Property& property,bool        b );
    virtual bool addByte(      unsigned int index,const Property& property,char        c );
    virtual bool addCharacter( unsigned int index,const Property& property,wchar_t     c );
    virtual bool addString(    unsigned int index,const Property& property,const wchar_t* s , unsigned int len);
    virtual bool addBytes(     unsigned int index,const Property& property,const char* s , unsigned int len);
    virtual bool addShort(     unsigned int index,const Property& property,short       s );
    virtual bool addInteger(   unsigned int index,const Property& property,long         i );    
    virtual bool addLong(      unsigned int index,const Property& property,int64_t     l );
    virtual bool addFloat(     unsigned int index,const Property& property,float       f );
    virtual bool addDouble(    unsigned int index,const Property& property,long double d );
    virtual bool addDate(      unsigned int index,const Property& property,const SDODate t );
    virtual bool addDataObject(unsigned int index,const Property& property,DataObjectPtr d );
    virtual bool addSDOValue(unsigned int index, const Property& property, const SDOValue& sval);
 
    ///////////////////////////////////////////////////////////////////////////
    // removes the entry at the given entry index.
    // @param index the index of the entry
    ///////////////////////////////////////////////////////////////////////////
    virtual void remove(unsigned int index);
    virtual void removeAll(const Property& p);

    ///////////////////////////////////////////////////////////////////////////
    // pushes a new entry without setting the property.
    // @param index the index of the entry
    ///////////////////////////////////////////////////////////////////////////
    virtual void push(const Property& p, unsigned int index);

    ///////////////////////////////////////////////////////////////////////////
    // Moves the entry at <code>fromIndex</code> to <code>toIndex</code>.
    // @param toIndex the index of the entry destination.
    // @param fromIndex the index of the entry to move.
    ///////////////////////////////////////////////////////////////////////////
    virtual void move(unsigned int toIndex, unsigned int fromIndex);

    ///////////////////////////////////////////////////////////////////////////
    // adds a new Setting with the SDO text Property
    // to the end of the Settings.
    // @param text value of the Setting.
    ///////////////////////////////////////////////////////////////////////////
    virtual bool addText(const char* text);

    ///////////////////////////////////////////////////////////////////////////
    // adds a new Setting with the SDO text Property
    // to the Settings.
    // @param index the index at which to add the entry.
    // @param text value of the Setting.
    ///////////////////////////////////////////////////////////////////////////
    virtual bool addText(unsigned int index, const char* text);

    ///////////////////////////////////////////////////////////////////////////
    // sets a text Property
    // @param index the index at which to set the entry.
    // @param text value of the Setting.
    ///////////////////////////////////////////////////////////////////////////
    bool setText(unsigned int index, const char* text);

    ///////////////////////////////////////////////////////////////////////////
    // Checks if an entry is text or a setting.
    ///////////////////////////////////////////////////////////////////////////
    virtual bool isText(unsigned int index);

    SequenceImpl(DataObject* the_do);
    SequenceImpl(SequenceImpl* s);
  
    private:

    SequenceImpl();

    DataObjectImpl* the_do;

    class seq_item {
       public:
          // Constructors
          seq_item(const Property* p, unsigned int i):
             the_prop(p), index(i), freeText(0)
          {
          }
          seq_item(const char* t) :
             the_prop(0)
          {
             freeText = new SDOValue(t);
          }
          // Copy constructor
          seq_item(const seq_item& sin) :
             index(sin.index), freeText(0), the_prop(sin.the_prop)
          {
             if (sin.freeText != 0)
             {
                freeText = new SDOValue(*sin.freeText);
             }
          }

          // Copy assignment
             seq_item& operator=(const seq_item& sin)
             {
                 if (this != &sin)
                 {
                     if (freeText)
                     {
                         delete freeText;
                     }
                     if (sin.freeText != 0)
                     {
                         freeText = new SDOValue(*sin.freeText);
                     }
                 }
                 return *this;
             }
            
          // Destructor
          ~seq_item()
          {
             if (freeText)
             {
                delete freeText;
             }
          }


           const Property* getProp() {return the_prop;}
           unsigned int getIndex() { return index;}

          const char* getText()
          {
             return freeText->getCString();
          }

          const SDOValue* getFreeText()
          {
             return freeText;
          }

           void setProp(Property* p) { the_prop = p;}

          void setText(const char* intext)
          {
             if (intext != 0)
             {
                if (freeText != 0)
                {
                   delete freeText;
                }
                freeText = new SDOValue(intext);
             }
          }
           void setIndex(unsigned int i)
           {
               index = i;
           }
       private:
       const Property* the_prop;
       unsigned int index;
       SDOValue* freeText;
    };

    typedef std::list<seq_item> SEQUENCE_ITEM_LIST;
    virtual void checkRange(unsigned int index, SEQUENCE_ITEM_LIST::iterator& i);

    SEQUENCE_ITEM_LIST the_list;

};
};
};

#endif //_SEQUENCE_H_