This file is indexed.

/usr/include/trilinos/CTrilinos_Table.hpp is in libtrilinos-dev 10.4.0.dfsg-1ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/*! @HEADER */
/*
************************************************************************

                CTrilinos:  C interface to Trilinos
                Copyright (2009) Sandia Corporation

Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
license for use of this work by or on behalf of the U.S. Government.

This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
Questions? Contact M. Nicole Lemaster (mnlemas@sandia.gov)

************************************************************************
*/
/*! @HEADER */


/*! @file CTrilinos_Table.hpp
 * @brief Table for storing Trilinos objects. */


#ifndef CTRILINOS_TABLE_HPP
#define CTRILINOS_TABLE_HPP


#include <string>
#include <typeinfo>

#include "Teuchos_RCP.hpp"
#include "Teuchos_SimpleObjectTable.hpp"
#include "Teuchos_Exceptions.hpp"
#include "CTrilinos_enums.h"
#include "CTrilinos_exceptions.hpp"


namespace CTrilinos
{

/* stringify the enum name -- defined in CTrilinos_utils.cpp */
std::string enum2str( CTrilinos_Table_ID_t ty );


/*! Table class for storing Trilinos objects internally. */
template <class T>
class Table
{
  public:

    /*! constructor -- use is_const = true if table will store
     * objects of type const T instead of T */
    Table(CTrilinos_Table_ID_t type);

    /*! destructor */
    ~Table();

    /*! retrieve the object */
    const Teuchos::RCP<T> get(CTrilinos_Universal_ID_t id);

    /*! cast the object to type T and store a copy */
    template <class TT>
    const Teuchos::RCP<TT> get(CTrilinos_Universal_ID_t id);

    /*! retrieve the object */
    const Teuchos::RCP<const T> getConst(CTrilinos_Universal_ID_t id);

    /*! cast the object to type T and store a copy */
    template <class TT>
    const Teuchos::RCP<const TT> getConst(CTrilinos_Universal_ID_t id);

    /*! store an object of type T */
    CTrilinos_Universal_ID_t store(T* pobj, bool owned);

    /*! store an object whose base class is T */
    template <class Told>
    CTrilinos_Universal_ID_t store(Told* pobj, bool owned);

    /*! store an object of type const T */
    CTrilinos_Universal_ID_t store(const T* pobj, bool owned);

    /*! store an object whose base class is T */
    template <class Told>
    CTrilinos_Universal_ID_t store(const Told* pobj, bool owned);

    /*! cast the object to type T and store a copy */
    template <class Told>
    CTrilinos_Universal_ID_t alias(const Teuchos::RCP<Told> & rold);

    /*! cast the object to type T and store a copy */
    template <class Told>
    CTrilinos_Universal_ID_t alias(const Teuchos::RCP<const Told> & rold);

    /*! remove an object from the table and invalidate the id struct */
    int remove(CTrilinos_Universal_ID_t * id);

    /*! dump the table's contents but keep it's properties */
    void purge();

    /*! whether or not this table is templated on the desired tyoe */
    bool isType(CTrilinos_Table_ID_t tab) { return (tab == ttab); }

  private:

    /*! build full exception msg on the fly */
    std::string typeMismatchMsg(CTrilinos_Universal_ID_t id, std::string act);

    /*! build full exception msg on the fly */
    std::string badCastMsg(std::string type, std::string act);

    /* tables for storing objects */
    Teuchos::SimpleObjectTable<T> sot;
    Teuchos::SimpleObjectTable<const T> csot;

    /* properties of the tables */
    CTrilinos_Table_ID_t ttab;  /* enum value for stored objects */
    std::string castmsg;        /* string for exception msgs */
    std::string mismsg;         /* string for exception msgs */
};


/* constructor -- use is_const = true if table will store
 * objects of type const T instead of T */
template <class T>
Table<T>::Table(CTrilinos_Table_ID_t tab)
  : ttab(tab)
{
    /* assemble exception error messages for future use */
    std::stringstream hs;
    hs << "[CTrilinos::Table<" << typeid(T).name() << ">]: ";

    std::stringstream ss1;
    ss1 << "Expected type " << typeid(T).name() << " but found ";
    castmsg = hs.str() + ss1.str();

    std::stringstream ss2;
    ss1 << "Expected type " << enum2str(tab) << " but found ";
    mismsg = hs.str() + ss2.str();
}

/* destructor */
template <class T>
Table<T>::~Table()
{
  purge();
}

/* retrieve the object */
template <class T>
const Teuchos::RCP<T> Table<T>::get(CTrilinos_Universal_ID_t id)
{
    if (id.is_const)
        throw CTrilinosConstCastError(typeMismatchMsg(id, std::string("get()")));

    if (id.table == ttab)
        return sot.getRCP(id.index);

    throw CTrilinosWrongTableError(typeMismatchMsg(id, std::string("get()")));
    return Teuchos::null;
}

/* return a different type RCP */
template <class T>
template <class TT>
const Teuchos::RCP<TT> Table<T>::get(CTrilinos_Universal_ID_t id)
{
    if (id.is_const)
        throw CTrilinosConstCastError(typeMismatchMsg(id, std::string("get()")));

    if (id.table == ttab)
        return Teuchos::rcp_dynamic_cast<TT,T>(sot.getRCP(id.index), true);

    throw CTrilinosWrongTableError(typeMismatchMsg(id, std::string("get()")));
    return Teuchos::null;
}

/* retrieve the object */
template <class T>
const Teuchos::RCP<const T> Table<T>::getConst(CTrilinos_Universal_ID_t id)
{
    if (id.table == ttab) {
        if (id.is_const)
            return csot.getRCP(id.index);
        else
            return sot.getRCP(id.index);
    }

    throw CTrilinosWrongTableError(typeMismatchMsg(id, std::string("getConst()")));
    return Teuchos::null;
}

/* retrieve the object */
template <class T>
template <class TT>
const Teuchos::RCP<const TT> Table<T>::getConst(CTrilinos_Universal_ID_t id)
{
    if (id.table == ttab) {
        if (id.is_const)
            return Teuchos::rcp_dynamic_cast<const TT,const T>(csot.getRCP(id.index), true);
        else
            return Teuchos::rcp_dynamic_cast<TT,T>(sot.getRCP(id.index), true);
    }

    throw CTrilinosWrongTableError(typeMismatchMsg(id, std::string("getConst()")));
    return Teuchos::null;
}

/* store an object of type T */
template <class T>
CTrilinos_Universal_ID_t Table<T>::store(T* pobj, bool owned)
{
    if (pobj == NULL)
        throw Teuchos::NullReferenceError("[CTrilinos::Table]: Cannot store NULL pointer");

    CTrilinos_Universal_ID_t id;
    id.table = CT_Invalid_ID;
    id.index = -1;
    id.is_const = false;

    if ((id.index = sot.storeNew(pobj, owned)) != -1)
        id.table = ttab;

    return id;
}

/* store an object whose base class is T */
template <class T>
template <class Told>
CTrilinos_Universal_ID_t Table<T>::store(Told* pobj, bool owned)
{ /* prevent adding wrong types */
    if (pobj == NULL)
        throw Teuchos::NullReferenceError("[CTrilinos::Table]: Cannot store NULL pointer");

    CTrilinos_Universal_ID_t id;
    id.table = CT_Invalid_ID;
    id.index = -1;
    id.is_const = false;

    T* pnew = dynamic_cast<T*>(pobj);
    if (pnew != NULL) {
        if ((id.index = sot.storeNew(pobj, owned)) != -1)
            id.table = ttab;
    } else {
        throw CTrilinosTypeMismatchError(badCastMsg(typeid(*pobj).name(), std::string("store()")));
    }

    return id;
}

/* store an object of type T */
template <class T>
CTrilinos_Universal_ID_t Table<T>::store(const T* pobj, bool owned)
{
    if (pobj == NULL)
        throw Teuchos::NullReferenceError("[CTrilinos::Table]: Cannot store NULL pointer");

    CTrilinos_Universal_ID_t id;
    id.table = CT_Invalid_ID;
    id.index = -1;
    id.is_const = true;

    if ((id.index = csot.storeNew(pobj, owned)) != -1)
        id.table = ttab;

    return id;
}

/* store an object whose base class is T */
template <class T>
template <class Told>
CTrilinos_Universal_ID_t Table<T>::store(const Told* pobj, bool owned)
{ /* prevent adding wrong types */
    if (pobj == NULL)
        throw Teuchos::NullReferenceError("[CTrilinos::Table]: Cannot store NULL pointer");

    CTrilinos_Universal_ID_t id;
    id.table = CT_Invalid_ID;
    id.index = -1;
    id.is_const = true;

    const T* pnew = dynamic_cast<const T*>(pobj);
    if (pnew != NULL) {
        if ((id.index = csot.storeNew(pobj, owned)) != -1)
            id.table = ttab;
    } else {
        throw CTrilinosTypeMismatchError(badCastMsg(typeid(*pobj).name(), std::string("storeConst()")));
    }

    return id;
}

/* cast the object to type T and store a copy */
template <class T>
template <class Told>
CTrilinos_Universal_ID_t Table<T>::alias(const Teuchos::RCP<Told> & rold)
{
    CTrilinos_Universal_ID_t newid;
    newid.table = CT_Invalid_ID;
    newid.index = -1;
    newid.is_const = false;

    newid.index = sot.storeCastedRCP(rold);

    if (newid.index != -1)
        newid.table = ttab;

    return newid;
}

/* cast the object to type T and store a copy */
template <class T>
template <class Told>
CTrilinos_Universal_ID_t Table<T>::alias(const Teuchos::RCP<const Told> & rold)
{
    CTrilinos_Universal_ID_t newid;
    newid.table = CT_Invalid_ID;
    newid.index = -1;
    newid.is_const = true;

    newid.index = csot.storeCastedRCP(rold);

    if (newid.index != -1)
        newid.table = ttab;

    return newid;
}

/* remove an object from the table and invalidate the id struct */
template <class T>
int Table<T>::remove(CTrilinos_Universal_ID_t * id)
{
    int ret = -1;

    if (id->table == ttab) {
        if (id->is_const)
            ret = (csot.removeRCP(id->index) < 0 ? -1 : 0);
        else
            ret = (sot.removeRCP(id->index) < 0 ? -1 : 0);
        if (ret == 0) id->table = CT_Invalid_ID;
    } else {
        throw CTrilinosWrongTableError(typeMismatchMsg(*id, std::string("remove()")));
    }

    return ret;
}

/* dump the table's contents but keep it's properties */
template <class T>
void Table<T>::purge()
{
    sot.purge();
    csot.purge();
}

/* build full exception msg on the fly */
template <class T>
std::string Table<T>::typeMismatchMsg(CTrilinos_Universal_ID_t id, std::string act)
{
    std::stringstream ss;
    ss << mismsg << enum2str(id.table);
    if (id.is_const) {
        ss << " (const)";
    } else {
        ss << " (non-const)";
    }
    ss << " when attempting to " << act << " at index " << id.index;

    return ss.str();
}

/* build full exception msg on the fly */
template <class T>
std::string Table<T>::badCastMsg(std::string type, std::string act)
{
    std::stringstream ss;
    ss << castmsg << type << " when attempting to " << act;

    return ss.str();
}


} // namespace CTrilinos


#endif // CTRILINOS_TABLE_HPP