typeutil.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2003 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// psrchive/Util/genutil/typeutil.h
10
11#ifndef __typeutil_h
12#define __typeutil_h
13
14#include "Reference.h"
15#include <typeinfo>
16
17using namespace std;
18
19template<class T>
20unsigned find (const vector< Reference::To<T> >& array, const T* instance)
21try
22{
23 unsigned index;
24
25 if (!instance)
26 throw Error (InvalidParam, "typeinfo find", "null pointer to instance");
27
28#ifdef _DEBUG
29 cerr << "typeinfo find array size = " << array.size()
30 << " ptr=" << instance
31 << " name=" << instance->get_extension_name() << endl;
32#endif
33
34 for (index=0; index<array.size(); index++)
35 {
36#ifdef _DEBUG
37 cerr << "typeinfo find test index=" << index
38 << " ptr=" << array[index].ptr();
39 cerr << " name=" << array[index]->get_extension_name () << endl;
40#endif
41 if ( typeid(*instance) == typeid(*array[index].get()) )
42 break;
43 }
44
45#ifdef _DEBUG
46 cerr << "typinfo find return index = " << index << endl;
47#endif
48
49 return index;
50}
51catch (Error& error)
52{
53 throw error += "typeutil find";
54}
55
56#endif
57
A convenient exception handling class.
Definition Error.h:54
Template class manages Reference::Able objects.
Definition ReferenceTo.h:25
STL namespace.

Generated using doxygen 1.14.0