00001 // Callback helper function implementation -*- C++ -*- 00002 00003 // $Id: callback_ref.cc 347 2008-02-06 15:20:01Z schilly $ 00004 // Copyright (C) 2004 Hermann Schichl 00005 // 00006 // This file is part of the COCONUT API. This library 00007 // is free software; you can redistribute it and/or modify it under the 00008 // terms of the Library GNU General Public License as published by the 00009 // Free Software Foundation; either version 2, or (at your option) 00010 // any later version. 00011 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // Library GNU General Public License for more details. 00016 00017 // As a special exception, you may use this file as part of a free software 00018 // library without restriction. Specifically, if other files instantiate 00019 // templates or use macros or inline functions from this file, or you compile 00020 // this file and link it with other files to produce an executable, this 00021 // file does not by itself cause the resulting executable to be covered by 00022 // the Library GNU General Public License. This exception does not however 00023 // invalidate any other reasons why the executable file might be covered by 00024 // the Library GNU General Public License. 00025 00028 #include <coconut_config.h> 00029 #include <callback_ref.h> 00030 #include <map> 00031 00033 00036 static cb_ref_handle _next_ref=0; 00037 00039 00043 static std::map<cb_ref_handle, void*> _ref_map; 00044 00045 cb_ref_handle _new_cb_ref(void* dest) 00046 { 00047 cb_ref_handle ret = _next_ref++; 00048 _ref_map[ret] = dest; 00049 return ret; 00050 } 00051 00052 int delete_cb_ref(cb_ref_handle ref) 00053 { 00054 std::map<cb_ref_handle, void*>::iterator _x(_ref_map.find(ref)); 00055 if(_x != _ref_map.end()) 00056 { 00057 _ref_map.erase(_x); 00058 return 0; 00059 } 00060 else 00061 return -1; 00062 } 00063 00064 void* cb_ref(cb_ref_handle ref) 00065 { 00066 std::map<cb_ref_handle, void*>::iterator _x(_ref_map.find(ref)); 00067 if(_x != _ref_map.end()) 00068 return (*_x).second; 00069 else 00070 return NULL; 00071 }