casacore
Loading...
Searching...
No Matches
Conversion.h
Go to the documentation of this file.
1//# Conversion.h: A class with general conversion definitions
2//# Copyright (C) 1996,1999,2001,2002,2003
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_CONVERSION_H
27#define CASA_CONVERSION_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/string.h> // needed for memcpy
32
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36// <summary>
37// A class with general conversion definitions
38// </summary>
39
40// <use visibility=export>
41
42// <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tConversion" demos="">
43// </reviewed>
44
45// <synopsis>
46// This class contains the general definitions for the Conversion classes.
47// <ul>
48// <li>
49// It defines the signature for the functions converting from input
50// to output format (e.g. from local to canonical format). There is
51// a version where the number of values is given and a version where
52// the number of bytes is given. The latter is there to be able to use
53// memcpy as a conversion function (which will often be the case).
54// Note that the signatures only differ in return value.
55// <li>
56// It defines functions to convert Bools to bits and vice-versa.
57// These are used elsewhere to store Bools as space efficient as possible.
58// Note that these functions are machine independent (they work on little
59// and big endian machines).
60// <li>
61// It defines a private version of memcpy for compilers having a
62// different signature for memcpy (e.g. ObjectCenter and DEC-Alpha).
63// </ul>
64// Static functions in the classes
65// <linkto class=CanonicalConversion>CanonicalConversion</linkto>,
66// <linkto class=VAXConversion>VAXConversion</linkto>, and
67// <linkto class=IBMConversion>IBMConversion</linkto> convert data
68// from/to canonical, VAX, and IBM/360 format, resp..
69// <br>Classes derived from
70// <linkto class=DataConversion>DataConversion</linkto>
71// provide the same functionality in a polymorphic way.
72// </synopsis>
73
74// <motivation>
75// This provides a common place for definitions used elsewhere.
76// It also provides a uniform interface to memcpy.
77// </motivation>
78
79//# <todo asof="$DATE$">
80//# </todo>
81
82
84{
85public:
86 // Define the signature of a function converting <src>nvalues</src>
87 // values from internal to external format or vice-versa.
88 // These functions are used in the <linkto class=TypeIO>IO framework
89 // </linkto>, but are also used in the table system.
90 // Examples of such conversions are:
91 // <br>- local <-> canonical (when storing in canonical format)
92 // <br>- local <-> local (when storing in local format)
93 // <br>- binary <-> ASCII
94 // <br>It returns the number of bytes in <em>external</em> format.
95 // (For example the ToLocal/FromLocal functions in class
96 // <linkto class=CanonicalConversion>CanonicalConversion</linkto>
97 // return the number of bytes in canonical format).
98 typedef size_t ValueFunction (void* to, const void* from,
99 size_t nvalues);
100
101 // Define the signature of a function converting from one
102 // format to another providing the number of bytes.
103 // It returns the <src>to</src> pointer (similar to memcpy).
104 // (For example the byteTo/FromLocalXXX functions in class
105 // <linkto class=CanonicalConversion>CanonicalConversion</linkto>.
106 typedef void* ByteFunction (void* to, const void* from,
107 size_t nbytes);
108
109 // Convert a stream of Bools to output format (as bits).
110 // The variable <src>startBit</src> (0-relative) indicates
111 // where to start in the <src>to</src> buffer.
112 // <group>
113 static size_t boolToBit (void* to, const void* from,
114 size_t nvalues);
115 static void boolToBit (void* to, const void* from,
116 size_t startBit,
117 size_t nvalues);
118 // </group>
119
120 // Convert a stream of Bools to output format (as bits).
121 // The variable <src>startBit</src> (0-relative) indicates
122 // where to start in the <src>from</src> buffer.
123 // <group>
124 static size_t bitToBool (void* to, const void* from,
125 size_t nvalues);
126 static void bitToBool (void* to, const void* from,
127 size_t startBit,
128 size_t nvalues);
129 // </group>
130
131 // Copy a value using memcpy.
132 // It differs from memcpy in the return value.
133 // <note> This version has the <src>ValueFunction</src> signature,
134 // but it expects as input the number of bytes.
135 // </note>
136 static size_t valueCopy (void* to, const void* from,
137 size_t nbytes);
138
139 // Get a pointer to the memcpy function.
140 static ByteFunction* getmemcpy();
141
142private:
143 // Copy bits to Bool in an unoptimized way needed when 'to' is not
144 // aligned properly.
145 static size_t bitToBool_ (void* to, const void* from,
146 size_t nvalues);
147};
148
149
151{
152 return memcpy;
153}
154
155
156
157} //# NAMESPACE CASACORE - END
158
159#endif
size_t ValueFunction(void *to, const void *from, size_t nvalues)
Define the signature of a function converting nvalues values from internal to external format or vice...
Definition Conversion.h:98
static void boolToBit(void *to, const void *from, size_t startBit, size_t nvalues)
void * ByteFunction(void *to, const void *from, size_t nbytes)
Define the signature of a function converting from one format to another providing the number of byte...
Definition Conversion.h:106
static size_t bitToBool(void *to, const void *from, size_t nvalues)
Convert a stream of Bools to output format (as bits).
static size_t valueCopy(void *to, const void *from, size_t nbytes)
Copy a value using memcpy.
static size_t bitToBool_(void *to, const void *from, size_t nvalues)
Copy bits to Bool in an unoptimized way needed when 'to' is not aligned properly.
static size_t boolToBit(void *to, const void *from, size_t nvalues)
Convert a stream of Bools to output format (as bits).
static ByteFunction * getmemcpy()
Get a pointer to the memcpy function.
Definition Conversion.h:150
static void bitToBool(void *to, const void *from, size_t startBit, size_t nvalues)
this file contains all the compiler specific defines
Definition mainpage.dox:28