Project

Profile

Help

Revision 6304fb8b

Added by O'Neil Delpratt 5 months ago

Saxon/C bug fixes and development work

View differences:

latest10/hec/Saxon.C.API/XdmItem.cpp
3 3
#include "XdmItem.h"
4 4

  
5 5
XdmItem::XdmItem(): XdmValue(){
6
	value = NULL;
6
	value = nullptr;
7 7
}
8 8

  
9 9
    XdmItem::XdmItem(const XdmItem &other): XdmValue(other){
10
	    value = (sxnc_value *)malloc(sizeof(sxnc_value));
11
        value->xdmvalue = other.value->xdmvalue;
10
        value = other.value;
12 11
	    xdmSize =1;
13 12
	    refCount = other.refCount;
14 13
    }
15 14

  
16 15

  
17 16
XdmItem::XdmItem(jobject obj){
18
	value = (sxnc_value *)malloc(sizeof(sxnc_value));
19
        value->xdmvalue = obj;
17
	value = obj;
20 18
	xdmSize =1;
21 19
	refCount =1;
22 20
}
......
32 30

  
33 31
  XdmItem * XdmItem::itemAt(int n){
34 32
	if (n < 0 || n >= size()) {
35
		return NULL;	
33
		return nullptr;	
36 34
	}
37 35
	return this;
38 36
  }
......
47 45
#ifdef DEBUG
48 46
	std::cerr<<std::endl<<"XdmItem-getUnderlyingValue:"<<std::endl; 
49 47
#endif 
50
	if(value == NULL) {
51
		return NULL;	
48
	if(value == nullptr) {
49
		return nullptr;	
52 50
	}
53
	return value->xdmvalue;
51
	return value;
54 52
}
55 53

  
56 54
    const char * XdmItem::getStringValue(){
......
62 60
    		if (!sbmID) {
63 61
    			std::cerr << "Error: Saxonc." << "getStringValue"
64 62
    				<< " not found\n" << std::endl;
65
    			return NULL;
63
    			return nullptr;
66 64
    		} else {
67
    			jstring result = (jstring)(SaxonProcessor::sxn_environ->env->CallObjectMethod(value->xdmvalue, sbmID));
65
    			jstring result = (jstring)(SaxonProcessor::sxn_environ->env->CallObjectMethod(value, sbmID));
68 66
    			if(result) {
69
    					const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result, NULL);
67
    					const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result, nullptr);
70 68
    					stringValue = std::string(str);
71 69
                        return stringValue.c_str();
72 70
    			}
73
    			return NULL;
71
    			return nullptr;
74 72
    		}
75 73
    	} else {
76 74
    		return stringValue.c_str();
......
83 81
	XDM_TYPE XdmItem::getType(){
84 82
		return XDM_ITEM;
85 83
	}
84

  
85
XdmItem::~XdmItem() {
86
    //std::cerr<<std::endl<<"XdmItem destructor called, refCount"<<getRefCount()<<std::endl;
87
    if(getRefCount()<1){
88
        if(value !=nullptr && proc != nullptr && SaxonProcessor::jvmCreatedCPP>0) {
89
            SaxonProcessor::sxn_environ->env->DeleteGlobalRef(value);
90
        }
91
        free(value);
92
        if(stringValue.empty()) {
93
            stringValue.clear();
94
        }
95
    }
96
}
97

  
98
void XdmItem::incrementRefCount() {
99
    refCount++;
100
    //std::cerr<<"refCount-inc-xdmItem="<<refCount<<" ob ref="<<(this)<<std::endl;
101
}
102

  
103
void XdmItem::decrementRefCount() {
104
    if (refCount > 0)
105
        refCount--;
106
    //std::cerr<<"refCount-dec-xdmItem="<<refCount<<" ob ref="<<(this)<<std::endl;
107
}

Also available in: Unified diff