Project

Profile

Help

Download (5.01 KB) Statistics
| Branch: | Revision:

he / src / main / c / Saxon.C.API / XdmValue.h @ 7728ae0b

1 72bf04c6 Norman Walsh
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright (c) 2014 Saxonica Limited.
3
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8
#ifndef SAXON_XDMVALUE_H
9
#define SAXON_XDMVALUE_H
10
11
12
#include <string.h>
13
#include "SaxonProcessor.h"
14
#include <typeinfo> //used for testing only
15
#include <vector>
16
#include <deque>
17
#include <list>
18
#include "SaxonCGlue.h"
19
#include "SaxonCXPath.h"
20
21
22 55b80284 O'Neil Delpratt
23 72bf04c6 Norman Walsh
/*! <code>XdmValue</code>. Value in the XDM data model. A value is a sequence of zero or more items,
24
 * each item being either an atomic value or a node. This class is a wrapper of the the XdmValue object created in Java.
25
 * <p/>
26
 */
27
28
class SaxonProcessor;
29
class XdmItem;
30
class XdmAtomicValue;
31
class XdmNode;
32
33
34 55b80284 O'Neil Delpratt
35 72bf04c6 Norman Walsh
typedef enum eXdmType { XDM_VALUE = 1, XDM_ITEM = 2, XDM_NODE = 3, XDM_ATOMIC_VALUE = 4, XDM_FUNCTION_ITEM = 5 } XDM_TYPE;
36
37
typedef enum saxonTypeEnum
38
{
39
        enumNode,
40
        enumString,
41
        enumInteger,
42
        enumDouble,
43
        enumFloat,
44
        enumBool,
45
        enumArrXdmValue
46
} PRIMITIVE_TYPE;
47
48
class XdmValue {
49
50
51
public:
52
        /**
53
                 * A default Constructor. Create a empty value
54
                 */
55
    XdmValue() {
56
        initialize();
57
    }
58
59 55b80284 O'Neil Delpratt
    /*void * operator new(size_t size)
60
    {
61 72bf04c6 Norman Walsh

62 55b80284 O'Neil Delpratt
        void * p = ::new XdmValue();
63
        //void * p = malloc(size); will also work fine
64
        std::cerr<< "new called on XdmValue size= " << size << " p="<<p<<std::endl;
65
        return p;
66
    }*/
67
68
69
    /**
70 72bf04c6 Norman Walsh
         * A copy constructor.
71
         * @param other - Xdmvalue
72
         */
73
        XdmValue(const XdmValue &other);
74
75
        /**
76
        * Constructor. Create a value from a collection of items
77
        * @param val - Xdmvalue
78
        */
79
        //XdmValue(XdmValue * items, int length);
80
81
82
83
         /**
84
         * Constructor. Create a value from a collection of items
85
         * @param val - Xdmvalue
86
         */
87
         //XdmValue(XdmItem *items, int length);
88
89
         /**
90
          * Add an XdmItem  to the sequence. This method is designed for the primitive types.
91
          * @param type - specify target type of the value
92
          * @param val - Value to convert
93
          */
94
        XdmValue * addXdmValueWithType(const char * tStr, const char * val);//TODO check and document
95
96
        /**
97
         * Add an XdmItem to the sequence.
98
         * See functions in SaxonCXPath of the C library
99
         * @param val - XdmItem object
100
         */
101
        void addXdmItem(XdmItem *val);
102
103
        /**
104
         * Add an Java XdmValue object to the sequence.
105
         * See methods the functions in SaxonCXPath of the C library
106
         * @param val - Java object
107
         */
108
        void addUnderlyingValue(jobject val);
109
110
111
112
113
        /**
114
         * A Constructor. Handles a sequence of XdmValues given as a  wrapped an Java XdmValue object.
115
         * @param val - Java XdmValue object
116
         * @param arrFlag - Currently not used but allows for overloading of constructor methods
117
         */
118
        XdmValue(jobject val, bool arrFlag);
119
120
        /**
121
         * A Constructor. Wrap an Java XdmValue object.
122
         * @param val - Java XdmValue object
123
         */
124
        XdmValue(jobject val);
125
126
127
        virtual ~XdmValue();
128
129
        void releaseXdmValue();
130
131
132
        /**
133
         * Get the first item in the sequence
134 ead48a5d O'Neil Delpratt
         * @return XdmItem or nullptr if sequence is empty
135 72bf04c6 Norman Walsh
         */
136
        virtual XdmItem * getHead();
137
138
        /**
139
           * Get the n'th item in the value, counting from zero.
140
           *
141
           * @param n the item that is required, counting the first item in the sequence as item zero
142
           * @return the n'th item in the sequence making up the value, counting from zero
143 ead48a5d O'Neil Delpratt
           * return nullptr  if n is less than zero or greater than or equal to the number
144 72bf04c6 Norman Walsh
           *                                    of items in the value
145
           */
146
        virtual XdmItem * itemAt(int n);
147
148
        /**
149
         * Get the number of items in the sequence
150
         *
151
         */
152
        virtual int size();
153
154
155
        /**
156
         * Create a string representation of the value. The is the result of serializing
157
         * the value using the adaptive serialization method.
158
         * @return a string representation of the value
159
         */
160
        virtual const char * toString();
161
162
        int getRefCount() {
163
                return refCount;
164
        }
165
166
167
168
        virtual void incrementRefCount();
169
170
        virtual void decrementRefCount();
171
172
173 901b6eca O'Neil Delpratt
    /*const char * getErrorMessage(int i);
174
    const char * getErrorCode(int i);
175 72bf04c6 Norman Walsh
int exceptionCount();*/
176
        const char * checkFailures() { return failure; }
177
178
        /**
179
          * Get Java XdmValue object.
180
          * @return jobject - The Java object of the XdmValue in its JNI representation
181
          */
182
        virtual  jobject getUnderlyingValue();
183
184
        /**
185
        * Get the type of the object
186
        */
187
        virtual XDM_TYPE getType();
188
189
protected:
190
   inline void initialize() noexcept {
191
    jValues   = nullptr;
192 a69dd173 O'Neil Delpratt
    refCount  = 0;
193 72bf04c6 Norman Walsh
    valueType = nullptr;
194
    xdmSize   = 0;
195
  }
196 901b6eca O'Neil Delpratt
197
    char* valueType;  /*!< Cached. The type of the XdmValue */
198 72bf04c6 Norman Walsh
199
200
        std::vector<XdmItem*> values;
201
        int xdmSize;         /*!< Cached. The count of items in the XdmValue */
202
        int refCount;
203
private:
204
        std::string toStringValue;  /*!< Cached. String representation of the XdmValue, if available */
205
        jobjectArray jValues;
206
};
207
208
#endif /** SAXON_XDMVALUE_H **/