Project

Profile

Help

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

he / tags / 9.8.0.14 / hec / Saxon.C.API / XdmValue.h @ 02f8308b

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

    
30

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

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

    
44
class XdmValue {
45

    
46

    
47
public:
48
/**
49
     * A default Constructor. Create a empty value
50
     */
51
        XdmValue(){
52
                xdmSize = 0;
53
                refCount = 1;
54
                jValues = NULL;
55
                valueType = NULL;
56
        }
57

    
58
        XdmValue(SaxonProcessor * p){
59
                proc = p;
60
                jValues = NULL;
61
                refCount = 1;
62
                valueType = NULL;
63
        }
64

    
65

    
66
    /**
67
     * A copy constructor.
68
     * @param val - Xdmvalue
69
     */
70
        //XdmValue(const XdmValue &other);
71

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

    
78
     /**
79
     * Constructor. Create a value from a collection of items
80
     * @param container - entire container is expected
81
     */
82
     template <class ContainerType>
83
     XdmValue(const ContainerType& container);
84

    
85
     /**
86
     * Constructor. Create a value from a collection of items
87
     * @param container - entire container is expected
88
     */
89
     template <class ForwardIteratorType> 
90
     XdmValue(ForwardIteratorType begin, ForwardIteratorType end);
91
 
92
     /**
93
     * Constructor. Create a value from a collection of items
94
     * @param val - Xdmvalue
95
     */
96
        //XdmValue(XdmItem *items, int length);
97

    
98
    /**
99
     * Add an XdmItem  to the sequence. This method is designed for the primitive types.
100
     * @param type - specify target type of the value  
101
     * @param val - Value to convert
102
     */
103
        XdmValue * addXdmValueWithType(const char * tStr, const char * val);//TODO check and document
104

    
105
    /**
106
     * Add an XdmItem to the sequence. 
107
     * See methods the functions in SaxonCXPath of the C library
108
     * @param val - XdmItem object
109
     */
110
     void addXdmItem(XdmItem *val);
111

    
112
    /**
113
     * Add an Java XdmValue object to the sequence. 
114
     * See methods the functions in SaxonCXPath of the C library
115
     * @param val - Java object
116
     */
117
     XdmValue * addUnderlyingValue(jobject val);
118

    
119
  
120

    
121
        //TODO XdmValue with constructor of sequence of values
122

    
123
    /**
124
     * A Constructor. Wrap an Java XdmValue object.
125
     * @param val - Java XdmValue object
126
     */
127
        XdmValue(jobject val);
128

    
129

    
130
        virtual ~XdmValue();
131

    
132
        void releaseXdmValue();
133

    
134

    
135
    /**
136
     * Get the first item in the sequence
137
     * @return XdmItem or null if sequence is empty
138
     */
139
        virtual XdmItem * getHead();
140

    
141
  /**
142
     * Get the n'th item in the value, counting from zero.
143
     *
144
     * @param n the item that is required, counting the first item in the sequence as item zero
145
     * @return the n'th item in the sequence making up the value, counting from zero
146
     * return NULL  if n is less than zero or greater than or equal to the number
147
     *                                    of items in the value
148
     * return NULL if the value is lazily evaluated and the delayed
149
     *                                    evaluation fails with a dynamic error.
150
     */
151
        virtual XdmItem * itemAt(int n);
152

    
153
    /**
154
     * Get the number of items in the sequence
155
     *
156
     */
157
      virtual int size();
158

    
159
      int getRefCount(){
160
        return refCount;
161
      }
162

    
163

    
164
        
165
      void incrementRefCount(){
166
        refCount++;
167
        //std::cerr<<"refCount-inc-xdmVal="<<refCount<<" ob ref="<<(this)<<std::endl;
168
      }
169

    
170
      void decrementRefCount(){
171
        if(refCount >0)
172
                refCount--;
173
        //std::cerr<<"refCount-dec-xdmVal="<<refCount<<" ob ref="<<(this)<<std::endl;
174
      }
175

    
176
        void setProcessor(SaxonProcessor *p){proc = p;}
177

    
178
        /*const char * getErrorMessage(int i);
179
        const char * getErrorCode(int i);
180
        int exceptionCount();*/
181
        const char * checkFailures(){return failure;}
182

    
183
   /**
184
     * Get Java XdmValue object.
185
     * @return jobject - The Java object of the XdmValue in its JNI representation
186
     */
187
        virtual  jobject getUnderlyingValue(SaxonProcessor * proc);
188

    
189
        /**
190
        * Get the type of the object
191
        */
192
        virtual XDM_TYPE getType();
193

    
194
protected:
195
        SaxonProcessor *proc;
196
        char* valueType;  /*!< Cached. The type of the XdmValue */
197
        //string valueStr;  /*!< Cached. String representation of the XdmValue, if available */
198

    
199
        std::vector<XdmItem*> values;
200
        int xdmSize;         /*!< Cached. The count of items in the XdmValue */
201
        int refCount;
202
private:
203
        
204
        jobjectArray jValues;
205
};
206

    
207
#endif /** SAXON_XDMVALUE_H **/
(28-28/45)