RTOpPack: Extra C/C++ Code for Vector Reduction/Transformation Operators Version of the Day
RTOp_obj_values_vtbl.c
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 "RTOp_obj_values_vtbl.h"
00032 #include "RTOp_obj_free_free.h"
00033 
00034 #include <stdlib.h>
00035 
00036 /* Local function definitions */
00037 
00038 static int get_obj_type_num_entries(
00039   const struct RTOp_obj_type_vtbl_t* vtbl
00040   ,const void* instance_data
00041   ,int* num_values
00042   ,int* num_indexes
00043   ,int* num_chars
00044   )
00045 {
00046   *num_values  = *(RTOp_index_type*)instance_data;
00047   *num_indexes = 0;
00048   *num_chars   = 0;
00049   return 0;
00050 }
00051 
00052 static int obj_create(
00053   const struct RTOp_obj_type_vtbl_t* vtbl, const void* instance_data, void** obj )
00054 {
00055   int k;
00056   const int
00057     num_values = *(RTOp_index_type*)instance_data,
00058     mem_size = sizeof(RTOp_value_type) * num_values;
00059   *obj = malloc( mem_size );
00060   for( k = 0; k < num_values; ++k )
00061     ((RTOp_value_type*)*obj)[k] = 0.0;
00062   return 0;
00063 }
00064 
00065 static int obj_reinit(
00066   const struct RTOp_obj_type_vtbl_t* vtbl, const void* instance_data, void* obj )
00067 {
00068   const int num_values = *(RTOp_index_type*)instance_data;
00069   int k;
00070   for( k = 0; k < num_values; ++k )
00071     ((RTOp_value_type*)obj)[k] = 0.0;
00072   return 0;
00073 }
00074 
00075 static int extract_state(
00076   const struct RTOp_obj_type_vtbl_t* vtbl
00077   ,const void *       instance_data
00078   ,void *             obj
00079   ,int                num_values
00080   ,RTOp_value_type    value_data[]
00081   ,int                num_indexes
00082   ,RTOp_index_type    index_data[]
00083   ,int                num_chars
00084   ,RTOp_char_type     char_data[]
00085   )
00086 {
00087   int num_values_state;
00088   int k;
00089   assert(instance_data);
00090   num_values_state = *(RTOp_index_type*)instance_data;
00091   assert(obj);
00092   assert( num_values  == num_values_state );
00093   assert( num_indexes == 0 );
00094   assert( num_chars   == 0 );
00095   for( k = 0; k < num_values; ++k )
00096     value_data[k] = ((RTOp_value_type*)obj)[k];
00097   return 0;
00098 }
00099 
00100 static int load_state(
00101   const struct RTOp_obj_type_vtbl_t* vtbl
00102   ,const void *            instance_data
00103   ,int                     num_values
00104   ,const RTOp_value_type   value_data[]
00105   ,int                     num_indexes
00106   ,const RTOp_index_type   index_data[]
00107   ,int                     num_chars
00108   ,const RTOp_char_type    char_data[]
00109   ,void **                 obj
00110   )
00111 {
00112   int num_values_state;
00113   int k;
00114   assert(instance_data);
00115   num_values_state = *(RTOp_index_type*)instance_data;
00116   assert( obj );
00117   assert( num_values  == num_values_state );
00118   assert( num_indexes == 0 );
00119   assert( num_chars   == 0 );
00120   if(*obj == NULL)
00121     obj_create(vtbl,instance_data,obj);
00122   for( k = 0; k < num_values; ++k )
00123     ((RTOp_value_type*)*obj)[k] = value_data[k];
00124   return 0;
00125 }
00126 
00127 const struct RTOp_obj_type_vtbl_t   RTOp_obj_values_vtbl =
00128 {
00129    get_obj_type_num_entries
00130   ,obj_create
00131   ,obj_reinit
00132   ,RTOp_obj_free_free
00133   ,extract_state
00134   ,load_state
00135 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends