Project

Profile

Help

Support #2625 » XdmValue.h

Duygu Colak, 2016-02-23 10:01

 
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
class XdmValue {
34

    
35

    
36
public:
37
/**
38
     * A default Constructor. Create a empty value
39
     */
40
        XdmValue(){
41
                xdmSize = 0;
42
                refCount = 1;
43
                jValues = NULL;                
44
        }
45

    
46
        XdmValue(SaxonProcessor * p){
47
                proc = p;
48
                jValues = NULL;
49
                refCount = 1;
50
        }
51

    
52

    
53
    /**
54
     * A copy constructor.
55
     * @param val - Xdmvalue
56
     */
57
        //XdmValue(const XdmValue &other);
58

    
59
     /**
60
     * Constructor. Create a value from a collection of items
61
     * @param val - Xdmvalue
62
     */
63
        //XdmValue(XdmValue * items, int length);
64

    
65
     /**
66
     * Constructor. Create a value from a collection of items
67
     * @param container - entire container is expected
68
     */
69
     template <class ContainerType>
70
     XdmValue(const ContainerType& container);
71

    
72
     /**
73
     * Constructor. Create a value from a collection of items
74
     * @param container - entire container is expected
75
     */
76
     template <class ForwardIteratorType> 
77
     XdmValue(ForwardIteratorType begin, ForwardIteratorType end);
78
 
79
     /**
80
     * Constructor. Create a value from a collection of items
81
     * @param val - Xdmvalue
82
     */
83
        //XdmValue(XdmItem *items, int length);
84

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

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

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

    
106
  
107

    
108
        //TODO XdmValue with constructor of sequence of values
109

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

    
116

    
117
        virtual ~XdmValue();
118

    
119
        void releaseXdmValue();
120

    
121

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

    
128
  /**
129
     * Get the n'th item in the value, counting from zero.
130
     *
131
     * @param n the item that is required, counting the first item in the sequence as item zero
132
     * @return the n'th item in the sequence making up the value, counting from zero
133
     * return NULL  if n is less than zero or greater than or equal to the number
134
     *                                    of items in the value
135
     * return NULL if the value is lazily evaluated and the delayed
136
     *                                    evaluation fails with a dynamic error.
137
     */
138
        virtual XdmItem * itemAt(int n);
139

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

    
146
      int getRefCount(){
147
        return refCount;
148
      }
149

    
150

    
151
        
152
      void incrementRefCount(){
153
        refCount++;
154
        //std::cerr<<"refCount-inc-xdmVal="<<refCount<<" ob ref="<<(this)<<std::endl;
155
      }
156

    
157
      void decrementRefCount(){
158
        if(refCount >0)
159
                refCount--;
160
        //std::cerr<<"refCount-dec-xdmVal="<<refCount<<" ob ref="<<(this)<<std::endl;
161
      }
162

    
163
        void setProcessor(SaxonProcessor *p){proc = p;}
164

    
165
        /*const char * getErrorMessage(int i);
166
        const char * getErrorCode(int i);
167
        int exceptionCount();*/
168
        const char * checkFailures(){return failure;}
169

    
170
   /**
171
     * Get Java XdmValue object.
172
     * @return jobject - The Java object of the XdmValue in its JNI representation
173
     */
174
        virtual  jobject getUnderlyingValue(SaxonProcessor * proc);
175

    
176
        /**
177
        * Get the type of the object
178
        */
179
        virtual XDM_TYPE getType();
180

    
181
protected:
182
        SaxonProcessor *proc;
183
        char* valueType;  /*!< Cached. The type of the XdmValue */
184
        //string valueStr;  /*!< Cached. String representation of the XdmValue, if available */
185

    
186
        std::vector<XdmItem*> values;
187
        int xdmSize;         /*!< Cached. The count of items in the XdmValue */
188
        int refCount;
189
private:
190
        
191
        jobjectArray jValues;
192
};
193

    
194
#endif /** SAXON_XDMVALUE_H **/
(7-7/10)