RTOpPack: Extra C/C++ Code for Vector Reduction/Transformation Operators  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RTOp_obj_value_index_vtbl.c
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
6 // Copyright (2003) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
44 #include "RTOp_obj_value_index_vtbl.h"
45 #include "RTOp_obj_free_free.h"
46 
47 #include <stdlib.h>
48 
49 /* Local function definitions */
50 
51 static int get_obj_type_num_entries(
52  const struct RTOp_obj_type_vtbl_t* vtbl
53  ,const void* instance_data
54  ,int* num_values
55  ,int* num_indexes
56  ,int* num_chars
57  )
58 {
59 #ifdef RTOp_DEBUG
60  assert(num_values);
61  assert(num_indexes);
62  assert(num_chars);
63 #endif
64  *num_values = 1;
65  *num_indexes = 1;
66  *num_chars = 0;
67  return 0;
68 }
69 
70 static int obj_create( const struct RTOp_obj_type_vtbl_t* vtbl, const void* instance_data, void** obj )
71 {
72  struct RTOp_value_index_type* vi_obj;
73  const int mem_size = sizeof(struct RTOp_value_index_type);
74 #ifdef RTOp_DEBUG
75  assert(obj);
76 #endif
77  *obj = malloc( mem_size );
78  vi_obj = (struct RTOp_value_index_type*)*obj;
79  vi_obj->value = 0.0;
80  vi_obj->index = 0;
81  return 0;
82 }
83 
84 static int obj_reinit( const struct RTOp_obj_type_vtbl_t* vtbl, const void* instance_data, void* obj )
85 {
86  struct RTOp_value_index_type* vi_obj;
87 #ifdef RTOp_DEBUG
88  assert(obj);
89 #endif
90  vi_obj = (struct RTOp_value_index_type*)obj;
91  vi_obj->value = 0.0;
92  vi_obj->index = 0;
93  return 0;
94 }
95 
96 static int extract_state(
97  const struct RTOp_obj_type_vtbl_t* vtbl
98  ,const void * instance_data
99  ,void * obj
100  ,int num_values
101  ,RTOp_value_type value_data[]
102  ,int num_indexes
103  ,RTOp_index_type index_data[]
104  ,int num_chars
105  ,RTOp_char_type char_data[]
106  )
107 {
108  struct RTOp_value_index_type* vi_obj;
109 #ifdef RTOp_DEBUG
110  assert( obj );
111  assert( num_values == 1 );
112  assert( num_indexes == 1 );
113  assert( num_chars == 0 );
114 #endif
115  vi_obj = (struct RTOp_value_index_type*)obj;
116  value_data[0] = vi_obj->value;
117  index_data[0] = vi_obj->index;
118  return 0;
119 }
120 
121 static int load_state(
122  const struct RTOp_obj_type_vtbl_t* vtbl
123  ,const void * instance_data
124  ,int num_values
125  ,const RTOp_value_type value_data[]
126  ,int num_indexes
127  ,const RTOp_index_type index_data[]
128  ,int num_chars
129  ,const RTOp_char_type char_data[]
130  ,void ** obj
131  )
132 {
133  struct RTOp_value_index_type* vi_obj;
134 #ifdef RTOp_DEBUG
135  assert( obj );
136  assert( num_values == 1 );
137  assert( num_indexes == 1 );
138  assert( num_chars == 0 );
139 #endif
140  if(*obj == NULL)
141  obj_create(vtbl,instance_data,obj);
142  vi_obj = (struct RTOp_value_index_type*)*obj;
143  vi_obj->value = value_data[0];
144  vi_obj->index = index_data[0];
145  return 0;
146 }
147 
148 const struct RTOp_obj_type_vtbl_t RTOp_obj_value_index_vtbl =
149 {
151  ,obj_create
152  ,obj_reinit
153  ,RTOp_obj_free_free
155  ,load_state
156 };
int(* get_obj_type_num_entries)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, int *num_values, int *num_indexes, int *num_chars)
Definition: RTOp.h:907
int(* obj_create)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void **obj)
Definition: RTOp.h:941
int(* extract_state)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void *obj, int num_values, RTOp_value_type value_data[], int num_indexes, RTOp_index_type index_data[], int num_chars, RTOp_char_type char_data[])
Definition: RTOp.h:1052
int(* obj_reinit)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void *obj)
Definition: RTOp.h:979
int(* load_state)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, int num_values, const RTOp_value_type value_data[], int num_indexes, const RTOp_index_type index_data[], int num_chars, const RTOp_char_type char_data[], void **obj)
Definition: RTOp.h:1097