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_values_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_values_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  *num_values = *(RTOp_index_type*)instance_data;
60  *num_indexes = 0;
61  *num_chars = 0;
62  return 0;
63 }
64 
65 static int obj_create(
66  const struct RTOp_obj_type_vtbl_t* vtbl, const void* instance_data, void** obj )
67 {
68  int k;
69  const int
70  num_values = *(RTOp_index_type*)instance_data,
71  mem_size = sizeof(RTOp_value_type) * num_values;
72  *obj = malloc( mem_size );
73  for( k = 0; k < num_values; ++k )
74  ((RTOp_value_type*)*obj)[k] = 0.0;
75  return 0;
76 }
77 
78 static int obj_reinit(
79  const struct RTOp_obj_type_vtbl_t* vtbl, const void* instance_data, void* obj )
80 {
81  const int num_values = *(RTOp_index_type*)instance_data;
82  int k;
83  for( k = 0; k < num_values; ++k )
84  ((RTOp_value_type*)obj)[k] = 0.0;
85  return 0;
86 }
87 
88 static int extract_state(
89  const struct RTOp_obj_type_vtbl_t* vtbl
90  ,const void * instance_data
91  ,void * obj
92  ,int num_values
93  ,RTOp_value_type value_data[]
94  ,int num_indexes
95  ,RTOp_index_type index_data[]
96  ,int num_chars
97  ,RTOp_char_type char_data[]
98  )
99 {
100  int num_values_state;
101  int k;
102  assert(instance_data);
103  num_values_state = *(RTOp_index_type*)instance_data;
104  assert(obj);
105  assert( num_values == num_values_state );
106  assert( num_indexes == 0 );
107  assert( num_chars == 0 );
108  for( k = 0; k < num_values; ++k )
109  value_data[k] = ((RTOp_value_type*)obj)[k];
110  return 0;
111 }
112 
113 static int load_state(
114  const struct RTOp_obj_type_vtbl_t* vtbl
115  ,const void * instance_data
116  ,int num_values
117  ,const RTOp_value_type value_data[]
118  ,int num_indexes
119  ,const RTOp_index_type index_data[]
120  ,int num_chars
121  ,const RTOp_char_type char_data[]
122  ,void ** obj
123  )
124 {
125  int num_values_state;
126  int k;
127  assert(instance_data);
128  num_values_state = *(RTOp_index_type*)instance_data;
129  assert( obj );
130  assert( num_values == num_values_state );
131  assert( num_indexes == 0 );
132  assert( num_chars == 0 );
133  if(*obj == NULL)
134  obj_create(vtbl,instance_data,obj);
135  for( k = 0; k < num_values; ++k )
136  ((RTOp_value_type*)*obj)[k] = value_data[k];
137  return 0;
138 }
139 
140 const struct RTOp_obj_type_vtbl_t RTOp_obj_values_vtbl =
141 {
143  ,obj_create
144  ,obj_reinit
145  ,RTOp_obj_free_free
147  ,load_state
148 };
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