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
33namespace casacore { // # NAMESPACE CASACORE - BEGIN
34
35// <summary>
36// A class with general conversion definitions
37// </summary>
38
39// <use visibility=export>
40
41// <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tConversion" demos="">
42// </reviewed>
43
44// <synopsis>
45// This class contains the general definitions for the Conversion classes.
46// <ul>
47// <li>
48// It defines the signature for the functions converting from input
49// to output format (e.g. from local to canonical format). There is
50// a version where the number of values is given and a version where
51// the number of bytes is given. The latter is there to be able to use
52// memcpy as a conversion function (which will often be the case).
53// Note that the signatures only differ in return value.
54// <li>
55// It defines functions to convert Bools to bits and vice-versa.
56// These are used elsewhere to store Bools as space efficient as possible.
57// Note that these functions are machine independent (they work on little
58// and big endian machines).
59// <li>
60// It defines a private version of memcpy for compilers having a
61// different signature for memcpy (e.g. ObjectCenter and DEC-Alpha).
62// </ul>
63// Static functions in the classes
64// <linkto class=CanonicalConversion>CanonicalConversion</linkto>,
65// <linkto class=VAXConversion>VAXConversion</linkto>, and
66// <linkto class=IBMConversion>IBMConversion</linkto> convert data
67// from/to canonical, VAX, and IBM/360 format, resp..
68// <br>Classes derived from
69// <linkto class=DataConversion>DataConversion</linkto>
70// provide the same functionality in a polymorphic way.
71// </synopsis>
72
73// <motivation>
74// This provides a common place for definitions used elsewhere.
75// It also provides a uniform interface to memcpy.
76// </motivation>
77
78// # <todo asof="$DATE$">
79// # </todo>
80
82 public:
83 // Define the signature of a function converting <src>nvalues</src>
84 // values from internal to external format or vice-versa.
85 // These functions are used in the <linkto class=TypeIO>IO framework
86 // </linkto>, but are also used in the table system.
87 // Examples of such conversions are:
88 // <br>- local <-> canonical (when storing in canonical format)
89 // <br>- local <-> local (when storing in local format)
90 // <br>- binary <-> ASCII
91 // <br>It returns the number of bytes in <em>external</em> format.
92 // (For example the ToLocal/FromLocal functions in class
93 // <linkto class=CanonicalConversion>CanonicalConversion</linkto>
94 // return the number of bytes in canonical format).
95 typedef size_t ValueFunction(void* to, const void* from, size_t nvalues);
96
97 // Define the signature of a function converting from one
98 // format to another providing the number of bytes.
99 // It returns the <src>to</src> pointer (similar to memcpy).
100 // (For example the byteTo/FromLocalXXX functions in class
101 // <linkto class=CanonicalConversion>CanonicalConversion</linkto>.
102 typedef void* ByteFunction(void* to, const void* from, size_t nbytes);
103
104 // Convert a stream of Bools to output format (as bits).
105 // The variable <src>startBit</src> (0-relative) indicates
106 // where to start in the <src>to</src> buffer.
107 // <group>
108 static size_t boolToBit(void* to, const void* from, size_t nvalues);
109 static void boolToBit(void* to, const void* from, size_t startBit, size_t nvalues);
110 // </group>
111
112 // Convert a stream of Bools to output format (as bits).
113 // The variable <src>startBit</src> (0-relative) indicates
114 // where to start in the <src>from</src> buffer.
115 // <group>
116 static size_t bitToBool(void* to, const void* from, size_t nvalues);
117 static void bitToBool(void* to, const void* from, size_t startBit, size_t nvalues);
118 // </group>
119
120 // Copy a value using memcpy.
121 // It differs from memcpy in the return value.
122 // <note> This version has the <src>ValueFunction</src> signature,
123 // but it expects as input the number of bytes.
124 // </note>
125 static size_t valueCopy(void* to, const void* from, size_t nbytes);
126
127 // Get a pointer to the memcpy function.
128 static ByteFunction* getmemcpy();
129
130 private:
131 // Copy bits to Bool in an unoptimized way needed when 'to' is not
132 // aligned properly.
133 static size_t bitToBool_(void* to, const void* from, size_t nvalues);
134};
135
137
138} // namespace casacore
139
140#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:95
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:102
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:136
static void bitToBool(void *to, const void *from, size_t startBit, size_t nvalues)
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28