RTOp_obj_values_vtbl.c

Go to the documentation of this file.
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 /* Local function definitions */
00035 
00036 static int get_obj_type_num_entries(
00037   const struct RTOp_obj_type_vtbl_t* vtbl
00038   ,const void* instance_data
00039   ,int* num_values
00040   ,int* num_indexes
00041   ,int* num_chars
00042   )
00043 {
00044   *num_values  = *(RTOp_index_type*)instance_data;
00045   *num_indexes = 0;
00046   *num_chars   = 0;
00047   return 0;
00048 }
00049 
00050 static int obj_create(
00051   const struct RTOp_obj_type_vtbl_t* vtbl, const void* instance_data, void** obj )
00052 {
00053   int k;
00054   const int
00055     num_values = *(RTOp_index_type*)instance_data,
00056     mem_size = sizeof(RTOp_value_type) * num_values;
00057   *obj = malloc( mem_size );
00058   for( k = 0; k < num_values; ++k )
00059     ((RTOp_value_type*)*obj)[k] = 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   const int num_values = *(RTOp_index_type*)instance_data;
00067   int k;
00068   for( k = 0; k < num_values; ++k )
00069     ((RTOp_value_type*)obj)[k] = 0.0;
00070   return 0;
00071 }
00072 
00073 static int extract_state(
00074   const struct RTOp_obj_type_vtbl_t* vtbl
00075   ,const void *       instance_data
00076   ,void *             obj
00077   ,int                num_values
00078   ,RTOp_value_type    value_data[]
00079   ,int                num_indexes
00080   ,RTOp_index_type    index_data[]
00081   ,int                num_chars
00082   ,RTOp_char_type     char_data[]
00083   )
00084 {
00085   int num_values_state;
00086   int k;
00087   assert(instance_data);
00088   num_values_state = *(RTOp_index_type*)instance_data;
00089   assert(obj);
00090   assert( num_values  == num_values_state );
00091   assert( num_indexes == 0 );
00092   assert( num_chars   == 0 );
00093   for( k = 0; k < num_values; ++k )
00094     value_data[k] = ((RTOp_value_type*)obj)[k];
00095   return 0;
00096 }
00097 
00098 static int load_state(
00099   const struct RTOp_obj_type_vtbl_t* vtbl
00100   ,const void *            instance_data
00101   ,int                     num_values
00102   ,const RTOp_value_type   value_data[]
00103   ,int                     num_indexes
00104   ,const RTOp_index_type   index_data[]
00105   ,int                     num_chars
00106   ,const RTOp_char_type    char_data[]
00107   ,void **                 obj
00108   )
00109 {
00110   int num_values_state;
00111   int k;
00112   assert(instance_data);
00113   num_values_state = *(RTOp_index_type*)instance_data;
00114   assert( obj );
00115   assert( num_values  == num_values_state );
00116   assert( num_indexes == 0 );
00117   assert( num_chars   == 0 );
00118   if(*obj == NULL)
00119     obj_create(vtbl,instance_data,obj);
00120   for( k = 0; k < num_values; ++k )
00121     ((RTOp_value_type*)*obj)[k] = value_data[k];
00122   return 0;
00123 }
00124 
00125 const struct RTOp_obj_type_vtbl_t   RTOp_obj_values_vtbl =
00126 {
00127    get_obj_type_num_entries
00128   ,obj_create
00129   ,obj_reinit
00130   ,RTOp_obj_free_free
00131   ,extract_state
00132   ,load_state
00133 };

Generated on Thu Sep 18 12:35:19 2008 for MOOCHO (Single Doxygen Collection) by doxygen 1.3.9.1