OSDN Git Service

modified: utilsrc/src/Admin/Makefile
[eos/others.git] / utiltools / X86MAC64 / cuda / samples / 7_CUDALibraries / common / UtilNPP / Signal.h
1 /**
2  * Copyright 1993-2013 NVIDIA Corporation.  All rights reserved.
3  *
4  * Please refer to the NVIDIA end user license agreement (EULA) associated
5  * with this source code for terms and conditions that govern your use of
6  * this software. Any use, reproduction, disclosure, or distribution of
7  * this software and related documentation outside the terms of the EULA
8  * is strictly prohibited.
9  *
10  */
11
12 #ifndef NV_UTIL_NPP_SIGNAL_H
13 #define NV_UTIL_NPP_SIGNAL_H
14
15 #include <cstring>
16
17 namespace npp
18 {
19     class Signal
20     {
21         public:
22             Signal() : nSize_(0)
23             { };
24
25             explicit
26             Signal(size_t nSize) : nSize_(nSize)
27             { };
28
29             Signal(const Signal &rSignal) : nSize_(rSignal.nSize_)
30             { };
31
32             virtual
33             ~Signal()
34             { }
35
36             Signal &
37             operator= (const Signal &rSignal)
38             {
39                 nSize_ = rSignal.nSize_;
40                 return *this;
41             }
42
43             size_t
44             size()
45             const
46             {
47                 return nSize_;
48             }
49
50             void
51             swap(Signal &rSignal)
52             {
53                 size_t nTemp = nSize_;
54                 nSize_ = rSignal.nSize_;
55                 rSignal.nSize_ = nTemp;
56             }
57
58
59         private:
60             size_t nSize_;
61     };
62
63     template<typename D, class A>
64     class SignalTemplate: public Signal
65     {
66         public:
67             typedef D tData;
68
69             SignalTemplate(): aValues_(0)
70             {
71                 ;
72             }
73
74             SignalTemplate(size_t nSize): Signal(nSize)
75                 , aValues_(0)
76             {
77                 aValues_ = A::Malloc1D(size());
78             }
79
80             SignalTemplate(const SignalTemplate<D, A> &rSignal): Signal(rSignal)
81                 , aValues_(0)
82             {
83                 aValues_ = A::Malloc1D(size());
84                 A::Copy1D(aValues_, rSignal.values(), size());
85             }
86
87             virtual
88             ~SignalTemplate()
89             {
90                 A::Free1D(aValues_);
91             }
92
93             SignalTemplate &
94             operator= (const SignalTemplate<D, A> &rSignal)
95             {
96                 // in case of self-assignment
97                 if (&rSignal == this)
98                 {
99                     return *this;
100                 }
101
102                 A::Free1D(aValues_);
103                 this->aPixels_ = 0;
104
105                 // assign parent class's data fields (width, height)
106                 Signal::operator =(rSignal);
107
108                 aValues_ = A::Malloc1D(size());
109                 A::Copy1D(aValues_, rSignal.value(), size());
110
111                 return *this;
112             }
113
114             /// Get a pointer to the pixel array.
115             ///     The result pointer can be offset to pixel at position (x, y) and
116             /// even negative offsets are allowed.
117             /// \param nX Horizontal pointer/array offset.
118             /// \param nY Vertical pointer/array offset.
119             /// \return Pointer to the pixel array (or first pixel in array with coordinates (nX, nY).
120             tData *
121             values(int i = 0)
122             {
123                 return aValues_ + i;
124             }
125
126             const
127             tData *
128             values(int i = 0)
129             const
130             {
131                 return aValues_ + i;
132             }
133
134             void
135             swap(SignalTemplate<D, A> &rSignal)
136             {
137                 Signal::swap(rSignal);
138
139                 tData *aTemp       = this->aValues_;
140                 this->aValues_      = rSignal.aValues_;
141                 rSignal.aValues_    = aTemp;
142             }
143
144         private:
145             D *aValues_;
146     };
147
148 } // npp namespace
149
150
151 #endif // NV_UTIL_NPP_SIGNAL_H