Project

Profile

Help

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

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

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

    
58
        /**
59
         * A copy constructor.
60
         * @param other - Xdmvalue
61
         */
62
        XdmValue(const XdmValue &other);
63

    
64
        /**
65
        * Constructor. Create a value from a collection of items
66
        * @param val - Xdmvalue
67
        */
68
        //XdmValue(XdmValue * items, int length);
69

    
70

    
71

    
72
         /**
73
         * Constructor. Create a value from a collection of items
74
         * @param val - Xdmvalue
75
         */
76
         //XdmValue(XdmItem *items, int length);
77

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

    
85
        /**
86
         * Add an XdmItem to the sequence.
87
         * See functions in SaxonCXPath of the C library
88
         * @param val - XdmItem object
89
         */
90
        void addXdmItem(XdmItem *val);
91

    
92
        /**
93
         * Add an Java XdmValue object to the sequence.
94
         * See methods the functions in SaxonCXPath of the C library
95
         * @param val - Java object
96
         */
97
        void addUnderlyingValue(jobject val);
98

    
99

    
100

    
101

    
102
        /**
103
         * A Constructor. Handles a sequence of XdmValues given as a  wrapped an Java XdmValue object.
104
         * @param val - Java XdmValue object
105
         * @param arrFlag - Currently not used but allows for overloading of constructor methods
106
         */
107
        XdmValue(jobject val, bool arrFlag);
108

    
109
        /**
110
         * A Constructor. Wrap an Java XdmValue object.
111
         * @param val - Java XdmValue object
112
         */
113
        XdmValue(jobject val);
114

    
115

    
116
        virtual ~XdmValue();
117

    
118
        void releaseXdmValue();
119

    
120

    
121
        /**
122
         * Get the first item in the sequence
123
         * @return XdmItem or nullptr if sequence is empty
124
         */
125
        virtual XdmItem * getHead();
126

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

    
137
        /**
138
         * Get the number of items in the sequence
139
         *
140
         */
141
        virtual int size();
142

    
143

    
144
        /**
145
         * Create a string representation of the value. The is the result of serializing
146
         * the value using the adaptive serialization method.
147
         * @return a string representation of the value
148
         */
149
        virtual const char * toString();
150

    
151
        int getRefCount() {
152
                return refCount;
153
        }
154

    
155

    
156

    
157
        virtual void incrementRefCount();
158

    
159
        virtual void decrementRefCount();
160

    
161

    
162
    /*const char * getErrorMessage(int i);
163
    const char * getErrorCode(int i);
164
int exceptionCount();*/
165
        const char * checkFailures() { return failure; }
166

    
167
        /**
168
          * Get Java XdmValue object.
169
          * @return jobject - The Java object of the XdmValue in its JNI representation
170
          */
171
        virtual  jobject getUnderlyingValue();
172

    
173
        /**
174
        * Get the type of the object
175
        */
176
        virtual XDM_TYPE getType();
177

    
178
protected:
179
   inline void initialize() noexcept {
180
    jValues   = nullptr;
181
    refCount  = 0;
182
    valueType = nullptr;
183
    xdmSize   = 0;
184
  }
185

    
186
    char* valueType;  /*!< Cached. The type of the XdmValue */
187

    
188

    
189
        std::vector<XdmItem*> values;
190
        int xdmSize;         /*!< Cached. The count of items in the XdmValue */
191
        int refCount;
192
private:
193
        std::string toStringValue;  /*!< Cached. String representation of the XdmValue, if available */
194
        jobjectArray jValues;
195
};
196

    
197
#endif /** SAXON_XDMVALUE_H **/
(36-36/55)