MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RTOp_obj_value_vtbl.c
Go to the documentation of this file.
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 <assert.h>
45 
46 #include "RTOp_obj_value_vtbl.h"
47 #include "RTOp_obj_free_free.h"
48 
49 #include <stdlib.h>
50 
51 /* Local function definitions */
52 
54  const struct RTOp_obj_type_vtbl_t* vtbl
55  ,const void* instance_data
56  ,int* num_values
57  ,int* num_indexes
58  ,int* num_chars
59  )
60 {
61  *num_values = 1;
62  *num_indexes = 0;
63  *num_chars = 0;
64  return 0;
65 }
66 
67 static int obj_create(
68  const struct RTOp_obj_type_vtbl_t* vtbl, const void* instance_data, void** obj )
69 {
70  const int mem_size = sizeof(RTOp_value_type);
71  *obj = malloc( mem_size );
72  *((RTOp_value_type*)*obj) = 0.0;
73  return 0;
74 }
75 
76 static int obj_reinit(
77  const struct RTOp_obj_type_vtbl_t* vtbl, const void* instance_data, void* obj )
78 {
79  *((RTOp_value_type*)obj) = 0.0;
80  return 0;
81 }
82 
83 static int extract_state(
84  const struct RTOp_obj_type_vtbl_t* vtbl
85  ,const void * instance_data
86  ,void * obj
87  ,int num_values
88  ,RTOp_value_type value_data[]
89  ,int num_indexes
90  ,RTOp_index_type index_data[]
91  ,int num_chars
92  ,RTOp_char_type char_data[]
93  )
94 {
95  assert(obj);
96  assert( num_values == 1 );
97  assert( num_indexes == 0 );
98  assert( num_chars == 0 );
99  value_data[0] = *((RTOp_value_type*)obj);
100  return 0;
101 }
102 
103 static int load_state(
104  const struct RTOp_obj_type_vtbl_t* vtbl
105  ,const void * instance_data
106  ,int num_values
107  ,const RTOp_value_type value_data[]
108  ,int num_indexes
109  ,const RTOp_index_type index_data[]
110  ,int num_chars
111  ,const RTOp_char_type char_data[]
112  ,void ** obj
113  )
114 {
115  assert( obj );
116  assert( num_values == 1 );
117  assert( num_indexes == 0 );
118  assert( num_chars == 0 );
119  if(*obj == NULL)
120  obj_create(vtbl,instance_data,obj);
121  *((RTOp_value_type*)*obj) = value_data[0];
122  return 0;
123 }
124 
126 {
128  ,obj_create
129  ,obj_reinit
132  ,load_state
133 };
double RTOp_value_type
Definition: RTOp.h:69
char RTOp_char_type
Definition: RTOp.h:70
static 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[])
static 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)
int RTOp_obj_free_free(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void **obj)
static int obj_create(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void **obj)
static 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)
const struct RTOp_obj_type_vtbl_t RTOp_obj_value_vtbl
static int obj_reinit(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void *obj)
Teuchos_Ordinal RTOp_index_type
Definition: RTOp.h:68