ConstRecordAdapter.h 3.34 KB
Newer Older
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
// $Id: ConstRecordAdapter.h,v 1.22 2009-12-16 17:41:24 avalassi Exp $
#ifndef RELATIONALCOOL_CONSTRECORDADAPTER_H
#define RELATIONALCOOL_CONSTRECORDADAPTER_H 1

// Include files
#include "CoolKernel/IRecord.h"
#include "CoolKernel/RecordSpecification.h"
#include "CoralBase/AttributeList.h"

namespace cool
{

  //--------------------------------------------------------------------------

  /** @class ConstRecordAdapter ConstRecordAdapter.h
   *
   *  Read-only wrapper of a constant coral::AttributeList reference,
   *  implementing the cool::IRecord interface. The adapter can only be
   *  used as long as the AttributeList is alive. The adapter creates
   *  its own RecordSpecification from one specified at construction time.
   *
   *  All non-const methods throw: this is effectively a read-only class.
   *
   *  The StorageType constraints on the data values of all fields
   *  are enforced in all copy constructors and assignment operators.
   *
   *  @author Andrea Valassi and Marco Clemencic
   *  @date   2006-12-01
   *///

  class ConstRecordAdapter : public IRecord {

  public:

    virtual ~ConstRecordAdapter();

    /// Constructor from a record spec and a _const_ AttributeList reference.
    /// The AttributeList must have at least all the fields required by the
    /// IRecordSpecification (with the correct name and storage type), but it
    /// may have more: it is reinterpreted according to the new specification.
    /// String attributes equal to NULL are considered equal to "".
    ConstRecordAdapter( const IRecordSpecification& spec,
                        const coral::AttributeList& al );

    /// Return the specification of this record.
    const IRecordSpecification& specification() const;

    /// Return a field in this record by its name (const).
    const IField& operator[] ( const std::string& name ) const;

    /// Return a field in this record by its index in [0, N-1] (const).
    const IField& operator[] ( UInt32 index ) const;

    /// Explicit conversion to a constant coral AttributeList reference.
    /// The AttributeList returned by this method contains only the attributes
    /// listed in the input IRecordSpecification, which may be fewer than
    /// those contained in the wrapped constant AttributeList reference.
    const coral::AttributeList& attributeList() const;

  private:

    /// Return a field in this record by its index in [0, N-1] (const).
    const IField& field( UInt32 index ) const;

    /// This method THROWS an exception because this is a read-only class.
    IField& field( UInt32 index ); // THROWS...

  private:

    /// Default constructor is private
    ConstRecordAdapter();

    /// Copy constructor is private
    ConstRecordAdapter( const ConstRecordAdapter& rhs );

    /// Assignment operator is private
    ConstRecordAdapter& operator=( const ConstRecordAdapter& rhs );

  private:

    /// The record specification.
    RecordSpecification m_spec;

    /// The record data (as an AttributeList const reference).
    /// CONST REFERENCE: the adapter can only be used as long as this is alive!
    const coral::AttributeList& m_attrList;

    /// The IField wrappers for the individual data Attribute's.
    std::vector< IField* > m_fields;

    /// The AttributeList accessible via the attributeList public method.
    coral::AttributeList m_publicAttrList;

  };

}
#endif // RELATIONALCOOL_CONSTRECORDADAPTER_H