source: trunk/legacy/jvmlink/src/main/c++/JVMLinkObject.cpp @ 7820

Revision 7820, 4.7 KB checked in by mario, 8 years ago (diff)

complete constructors initialize all class-members with sane defaults

Line 
1//
2// JVMLinkObject.cpp
3//
4
5/*
6JVMLink client/server architecture for communicating between Java and
7non-Java programs using sockets.
8Copyright (c) 2008 Hidayath Ansari and Curtis Rueden. All rights reserved.
9
10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions are met:
12  * Redistributions of source code must retain the above copyright
13    notice, this list of conditions and the following disclaimer.
14  * Redistributions in binary form must reproduce the above copyright
15    notice, this list of conditions and the following disclaimer in the
16    documentation and/or other materials provided with the distribution.
17  * Neither the name of the UW-Madison LOCI nor the names of its
18    contributors may be used to endorse or promote products derived from
19    this software without specific prior written permission.
20
21THIS SOFTWARE IS PROVIDED BY THE UW-MADISON LOCI ``AS IS'' AND ANY
22EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
25DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31*/
32
33#include "stdafx.h"
34#include "JVMLinkObject.h"
35
36JVMLinkObject::JVMLinkObject(const std::string& name) {
37        this->name = name;
38        this->size = 0;
39        this->length = 0;
40        this->type = NULL_TYPE;
41        this->insideType = NULL_TYPE;
42        this->data = NULL;
43}
44
45// Constructor for single primitives
46JVMLinkObject::JVMLinkObject(const std::string& name, Type type, const void* data) {
47        this->name = name;
48        this->size = getSize(type);
49        this->length = 1;
50        this->type = type;
51        this->insideType = NULL_TYPE;
52        this->data = data;
53}
54
55// Constructor for arrays
56JVMLinkObject::JVMLinkObject(const std::string& name, Type type, int length, const void* data) {
57        this->name = name;
58        this->size = getSize(type);
59        this->length = length;
60        this->type = ARRAY_TYPE;
61        this->insideType = type;
62        this->data = data;
63}
64
65// Destructor
66JVMLinkObject::~JVMLinkObject(void)
67{
68}
69
70int JVMLinkObject::getDataAsInt() {
71        int retval = *(int*) data;
72        return retval;
73}
74
75int* JVMLinkObject::getDataAsIntArray() {
76        int* retval = (int*) data;
77        return retval;
78}
79
80std::string* JVMLinkObject::getDataAsString() {
81        std::string* retval = (std::string*) data;
82        return retval;
83}
84
85std::string* JVMLinkObject::getDataAsStringArray() {
86        std::string* retval = (std::string*) data;
87        return retval;
88}
89
90Byte JVMLinkObject::getDataAsByte() {
91        Byte retval;
92        retval.data = *(char*) data;
93        return retval;
94}
95
96Byte* JVMLinkObject::getDataAsByteArray() {
97        Byte* retval = (Byte*) data;
98        return retval;
99}
100
101char JVMLinkObject::getDataAsChar() {
102        char retval = *(char*) data;
103        return retval;
104}
105
106char* JVMLinkObject::getDataAsCharArray() {
107        char* retval = (char*) data;
108        return retval;
109}
110
111float JVMLinkObject::getDataAsFloat() {
112        float retval = *(float*) data;
113        return retval;
114}
115
116float* JVMLinkObject::getDataAsFloatArray() {
117        float* retval = (float*) data;
118        return retval;
119}
120
121bool JVMLinkObject::getDataAsBool() {
122        bool retval = *(bool*) data;
123        return retval;
124}
125
126bool* JVMLinkObject::getDataAsBoolArray() {
127        bool* retval = (bool*) data;
128        return retval;
129}
130
131double JVMLinkObject::getDataAsDouble() {
132        double retval = *(double*) data;
133        return retval;
134}
135
136double* JVMLinkObject::getDataAsDoubleArray() {
137        double* retval = (double*) data;
138        return retval;
139}
140
141long long JVMLinkObject::getDataAsLong() {
142        long long retval = *(long long*) data;
143        return retval;
144}
145
146long long* JVMLinkObject::getDataAsLongArray() {
147        long long* retval = (long long*) data;
148        return retval;
149}
150
151short JVMLinkObject::getDataAsShort() {
152        short retval = *(short*) data;
153        return retval;
154}
155
156short* JVMLinkObject::getDataAsShortArray() {
157        short* retval = (short*) data;
158        return retval;
159}
160
161bool JVMLinkObject::isDataNull() {
162        return type == NULL_TYPE;
163}
164
165int JVMLinkObject::getSize(Type type) {
166        switch (type) {
167                case BYTE_TYPE:
168                case CHAR_TYPE:
169                case BOOL_TYPE:
170                        return 1;
171                case SHORT_TYPE:
172                        return 2;
173                case INT_TYPE:
174                case FLOAT_TYPE:
175                        return 4;
176                case DOUBLE_TYPE:
177                case LONG_TYPE:
178                        return 8;
179                case NULL_TYPE:
180                case STRING_TYPE: // string size is variable
181                default:
182                        return 0;
183        }
184}
Note: See TracBrowser for help on using the repository browser.