|
RTOpPack: Extra C/C++ Code for Vector Reduction/Transformation Operators Version of the Day
|
00001 /* 00002 // @HEADER 00003 // *********************************************************************** 00004 // 00005 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization 00006 // Copyright (2003) Sandia Corporation 00007 // 00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00009 // license for use of this work by or on behalf of the U.S. Government. 00010 // 00011 // This library is free software; you can redistribute it and/or modify 00012 // it under the terms of the GNU Lesser General Public License as 00013 // published by the Free Software Foundation; either version 2.1 of the 00014 // License, or (at your option) any later version. 00015 // 00016 // This library is distributed in the hope that it will be useful, but 00017 // WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 // Lesser General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU Lesser General Public 00022 // License along with this library; if not, write to the Free Software 00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00024 // USA 00025 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00026 // 00027 // *********************************************************************** 00028 // @HEADER 00029 */ 00030 00031 #include <assert.h> 00032 00033 #include "RTOp_obj_value_vtbl.h" 00034 #include "RTOp_obj_free_free.h" 00035 00036 #include <stdlib.h> 00037 00038 /* Local function definitions */ 00039 00040 static int get_obj_type_num_entries( 00041 const struct RTOp_obj_type_vtbl_t* vtbl 00042 ,const void* instance_data 00043 ,int* num_values 00044 ,int* num_indexes 00045 ,int* num_chars 00046 ) 00047 { 00048 *num_values = 1; 00049 *num_indexes = 0; 00050 *num_chars = 0; 00051 return 0; 00052 } 00053 00054 static int obj_create( 00055 const struct RTOp_obj_type_vtbl_t* vtbl, const void* instance_data, void** obj ) 00056 { 00057 const int mem_size = sizeof(RTOp_value_type); 00058 *obj = malloc( mem_size ); 00059 *((RTOp_value_type*)*obj) = 0.0; 00060 return 0; 00061 } 00062 00063 static int obj_reinit( 00064 const struct RTOp_obj_type_vtbl_t* vtbl, const void* instance_data, void* obj ) 00065 { 00066 *((RTOp_value_type*)obj) = 0.0; 00067 return 0; 00068 } 00069 00070 static int extract_state( 00071 const struct RTOp_obj_type_vtbl_t* vtbl 00072 ,const void * instance_data 00073 ,void * obj 00074 ,int num_values 00075 ,RTOp_value_type value_data[] 00076 ,int num_indexes 00077 ,RTOp_index_type index_data[] 00078 ,int num_chars 00079 ,RTOp_char_type char_data[] 00080 ) 00081 { 00082 assert(obj); 00083 assert( num_values == 1 ); 00084 assert( num_indexes == 0 ); 00085 assert( num_chars == 0 ); 00086 value_data[0] = *((RTOp_value_type*)obj); 00087 return 0; 00088 } 00089 00090 static int load_state( 00091 const struct RTOp_obj_type_vtbl_t* vtbl 00092 ,const void * instance_data 00093 ,int num_values 00094 ,const RTOp_value_type value_data[] 00095 ,int num_indexes 00096 ,const RTOp_index_type index_data[] 00097 ,int num_chars 00098 ,const RTOp_char_type char_data[] 00099 ,void ** obj 00100 ) 00101 { 00102 assert( obj ); 00103 assert( num_values == 1 ); 00104 assert( num_indexes == 0 ); 00105 assert( num_chars == 0 ); 00106 if(*obj == NULL) 00107 obj_create(vtbl,instance_data,obj); 00108 *((RTOp_value_type*)*obj) = value_data[0]; 00109 return 0; 00110 } 00111 00112 const struct RTOp_obj_type_vtbl_t RTOp_obj_value_vtbl = 00113 { 00114 get_obj_type_num_entries 00115 ,obj_create 00116 ,obj_reinit 00117 ,RTOp_obj_free_free 00118 ,extract_state 00119 ,load_state 00120 };
1.7.4