Project

Profile

Help

How to connect?
Download (4.91 KB) Statistics
| Branch: | Tag: | Revision:

he / latest10 / hec / Saxon.C.API / XdmValue.h @ 6304fb8b

1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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
/*! <code>XdmValue</code>. Value in the XDM data model. A value is a sequence of zero or more items,
23
 * each item being either an atomic value or a node. This class is a wrapper of the the XdmValue object created in Java.
24
 * <p/>
25
 */
26

    
27
class SaxonProcessor;
28
class XdmItem;
29
class XdmAtomicValue;
30
class XdmNode;
31

    
32

    
33
typedef enum eXdmType { XDM_VALUE = 1, XDM_ITEM = 2, XDM_NODE = 3, XDM_ATOMIC_VALUE = 4, XDM_FUNCTION_ITEM = 5 } XDM_TYPE;
34

    
35
typedef enum saxonTypeEnum
36
{
37
        enumNode,
38
        enumString,
39
        enumInteger,
40
        enumDouble,
41
        enumFloat,
42
        enumBool,
43
        enumArrXdmValue
44
} PRIMITIVE_TYPE;
45

    
46
class XdmValue {
47

    
48

    
49
public:
50
        /**
51
                 * A default Constructor. Create a empty value
52
                 */
53
    XdmValue() {
54
        initialize();
55
    }
56

    
57
  XdmValue(SaxonProcessor * p) {
58
    initialize();
59
    proc = p;
60
  }
61

    
62

    
63
        /**
64
         * A copy constructor.
65
         * @param other - Xdmvalue
66
         */
67
        XdmValue(const XdmValue &other);
68

    
69
        /**
70
        * Constructor. Create a value from a collection of items
71
        * @param val - Xdmvalue
72
        */
73
        //XdmValue(XdmValue * items, int length);
74

    
75

    
76

    
77
         /**
78
         * Constructor. Create a value from a collection of items
79
         * @param val - Xdmvalue
80
         */
81
         //XdmValue(XdmItem *items, int length);
82

    
83
         /**
84
          * Add an XdmItem  to the sequence. This method is designed for the primitive types.
85
          * @param type - specify target type of the value
86
          * @param val - Value to convert
87
          */
88
        XdmValue * addXdmValueWithType(const char * tStr, const char * val);//TODO check and document
89

    
90
        /**
91
         * Add an XdmItem to the sequence.
92
         * See functions in SaxonCXPath of the C library
93
         * @param val - XdmItem object
94
         */
95
        void addXdmItem(XdmItem *val);
96

    
97
        /**
98
         * Add an Java XdmValue object to the sequence.
99
         * See methods the functions in SaxonCXPath of the C library
100
         * @param val - Java object
101
         */
102
        void addUnderlyingValue(jobject val);
103

    
104

    
105

    
106

    
107
        /**
108
         * A Constructor. Handles a sequence of XdmValues given as a  wrapped an Java XdmValue object.
109
         * @param val - Java XdmValue object
110
         * @param arrFlag - Currently not used but allows for overloading of constructor methods
111
         */
112
        XdmValue(jobject val, bool arrFlag);
113

    
114
        /**
115
         * A Constructor. Wrap an Java XdmValue object.
116
         * @param val - Java XdmValue object
117
         */
118
        XdmValue(jobject val);
119

    
120

    
121
        virtual ~XdmValue();
122

    
123
        void releaseXdmValue();
124

    
125

    
126
        /**
127
         * Get the first item in the sequence
128
         * @return XdmItem or nullptr if sequence is empty
129
         */
130
        virtual XdmItem * getHead();
131

    
132
        /**
133
           * Get the n'th item in the value, counting from zero.
134
           *
135
           * @param n the item that is required, counting the first item in the sequence as item zero
136
           * @return the n'th item in the sequence making up the value, counting from zero
137
           * return nullptr  if n is less than zero or greater than or equal to the number
138
           *                                    of items in the value
139
           */
140
        virtual XdmItem * itemAt(int n);
141

    
142
        /**
143
         * Get the number of items in the sequence
144
         *
145
         */
146
        virtual int size();
147

    
148

    
149
        /**
150
         * Create a string representation of the value. The is the result of serializing
151
         * the value using the adaptive serialization method.
152
         * @return a string representation of the value
153
         */
154
        virtual const char * toString();
155

    
156
        int getRefCount() {
157
                return refCount;
158
        }
159

    
160

    
161

    
162
        virtual void incrementRefCount();
163

    
164
        virtual void decrementRefCount();
165

    
166
        void setProcessor(SaxonProcessor *p);
167

    
168

    
169
        /*const char * getErrorMessage(int i);
170
        const char * getErrorCode(int i);
171
int exceptionCount();*/
172
        const char * checkFailures() { return failure; }
173

    
174
        /**
175
          * Get Java XdmValue object.
176
          * @return jobject - The Java object of the XdmValue in its JNI representation
177
          */
178
        virtual  jobject getUnderlyingValue();
179

    
180
        /**
181
        * Get the type of the object
182
        */
183
        virtual XDM_TYPE getType();
184

    
185
protected:
186
   inline void initialize() noexcept {
187
    jValues   = nullptr;
188
    proc      = nullptr;
189
    refCount  = 1;
190
    valueType = nullptr;
191
    xdmSize   = 0;
192
  }
193
        SaxonProcessor *proc;
194
        char* valueType;  /*!< Cached. The type of the XdmValue */
195

    
196

    
197
        std::vector<XdmItem*> values;
198
        int xdmSize;         /*!< Cached. The count of items in the XdmValue */
199
        int refCount;
200
private:
201
        std::string toStringValue;  /*!< Cached. String representation of the XdmValue, if available */
202
        jobjectArray jValues;
203
};
204

    
205
#endif /** SAXON_XDMVALUE_H **/
(30-30/49)