STK++ 0.9.13
STK_IContainerRef.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004 Serge Iovleff
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place,
18 Suite 330,
19 Boston, MA 02111-1307
20 USA
21
22 Contact : S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
23*/
24
25/*
26 * Project: stkpp::Arrays
27 * Purpose: Define the Reference Container interface class.
28 * Author: Serge Iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 *
30 **/
31
41#ifndef STK_ICONTAINERREF_H
42#define STK_ICONTAINERREF_H
43
44namespace STK
45{
55template <int ref_> struct TRef;
56
58template <>
59struct TRef<0>
60{ static bool isRef() { return false;} };
61
63template <>
64struct TRef<1>
65{ static bool isRef() { return true;} };
66
68template <>
69struct TRef<-1>
70{
71 protected:
75 explicit TRef( bool ref) : ref_(ref) {}
77 ~TRef() {}
78
79 public:
81 inline bool isRef() const { return ref_;}
83 inline bool ref() const { return ref_;}
87 inline void exchange(TRef const& T) { std::swap(ref_, T.ref_);}
92 void setRef(bool ref) const { ref_ = ref;}
93
94 private:
98 mutable bool ref_;
99};
100
102typedef TRef<-1> IContainerRef;
103
104} // namespace STK
105
106#endif
107// STK_CONTAINERREF_H
TRef<-1 > IContainerRef
The namespace STK is the main domain space of the Statistical ToolKit project.
void setRef(bool ref) const
Modify the container : can become a reference or the owner of the data.
~TRef()
destructor.
bool ref_
Is it a "true" container or a wrapper ? ref_ should be false if this own its own data,...
void exchange(TRef const &T)
swap this with the container T.
bool isRef() const
TRef(bool ref)
Default constructor We have to specify the member ref_.
static bool isRef()
static bool isRef()
Base class for all referencing containers.