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

Revision 7818, 4.5 KB checked in by mario, 8 years ago (diff)

use again a bit stricter types, and use const reference for some JVMLinkObjects (instead of new and delete objects)

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}
39
40// Constructor for single primitives
41JVMLinkObject::JVMLinkObject(const std::string& name, Type type, const void* data) {
42        this->name = name;
43        this->size = getSize(type);
44        this->length = 1;
45        this->type = type;
46        this->data = data;
47}
48
49// Constructor for arrays
50JVMLinkObject::JVMLinkObject(const std::string& name, Type type, int length, const void* data) {
51        this->name = name;
52        this->size = getSize(type);
53        this->length = length;
54        this->type = ARRAY_TYPE;
55        this->insideType = type;
56        this->data = data;
57}
58
59// Destructor
60JVMLinkObject::~JVMLinkObject(void)
61{
62}
63
64int JVMLinkObject::getDataAsInt() {
65        int retval = *(int*) data;
66        return retval;
67}
68
69int* JVMLinkObject::getDataAsIntArray() {
70        int* retval = (int*) data;
71        return retval;
72}
73
74std::string* JVMLinkObject::getDataAsString() {
75        std::string* retval = (std::string*) data;
76        return retval;
77}
78
79std::string* JVMLinkObject::getDataAsStringArray() {
80        std::string* retval = (std::string*) data;
81        return retval;
82}
83
84Byte JVMLinkObject::getDataAsByte() {
85        Byte retval;
86        retval.data = *(char*) data;
87        return retval;
88}
89
90Byte* JVMLinkObject::getDataAsByteArray() {
91        Byte* retval = (Byte*) data;
92        return retval;
93}
94
95char JVMLinkObject::getDataAsChar() {
96        char retval = *(char*) data;
97        return retval;
98}
99
100char* JVMLinkObject::getDataAsCharArray() {
101        char* retval = (char*) data;
102        return retval;
103}
104
105float JVMLinkObject::getDataAsFloat() {
106        float retval = *(float*) data;
107        return retval;
108}
109
110float* JVMLinkObject::getDataAsFloatArray() {
111        float* retval = (float*) data;
112        return retval;
113}
114
115bool JVMLinkObject::getDataAsBool() {
116        bool retval = *(bool*) data;
117        return retval;
118}
119
120bool* JVMLinkObject::getDataAsBoolArray() {
121        bool* retval = (bool*) data;
122        return retval;
123}
124
125double JVMLinkObject::getDataAsDouble() {
126        double retval = *(double*) data;
127        return retval;
128}
129
130double* JVMLinkObject::getDataAsDoubleArray() {
131        double* retval = (double*) data;
132        return retval;
133}
134
135long long JVMLinkObject::getDataAsLong() {
136        long long retval = *(long long*) data;
137        return retval;
138}
139
140long long* JVMLinkObject::getDataAsLongArray() {
141        long long* retval = (long long*) data;
142        return retval;
143}
144
145short JVMLinkObject::getDataAsShort() {
146        short retval = *(short*) data;
147        return retval;
148}
149
150short* JVMLinkObject::getDataAsShortArray() {
151        short* retval = (short*) data;
152        return retval;
153}
154
155bool JVMLinkObject::isDataNull() {
156        return type == NULL_TYPE;
157}
158
159int JVMLinkObject::getSize(Type type) {
160        switch (type) {
161                case BYTE_TYPE:
162                case CHAR_TYPE:
163                case BOOL_TYPE:
164                        return 1;
165                case SHORT_TYPE:
166                        return 2;
167                case INT_TYPE:
168                case FLOAT_TYPE:
169                        return 4;
170                case DOUBLE_TYPE:
171                case LONG_TYPE:
172                        return 8;
173                case NULL_TYPE:
174                case STRING_TYPE: // string size is variable
175                default:
176                        return 0;
177        }
178}
Note: See TracBrowser for help on using the repository browser.