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