|
| 1 | +/*========================================================================= |
| 2 | + * |
| 3 | + * Copyright NumFOCUS |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * https://www.apache.org/licenses/LICENSE-2.0.txt |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * |
| 17 | + *=========================================================================*/ |
| 18 | +#ifndef itkScancoDataManipulation_h |
| 19 | +#define itkScancoDataManipulation_h |
| 20 | +#include <cstddef> |
| 21 | + |
| 22 | +/** Check the file header to see what type of file it is. |
| 23 | + * |
| 24 | + * \param header A pointer to the first 16 bytes of the file header. |
| 25 | + * \return 0 if unrecognized, 1 if ISQ/RAD, |
| 26 | + * 2 if AIM 020, 3 if AIM 030. |
| 27 | + */ |
| 28 | +int |
| 29 | +CheckVersion(const char header[16]); |
| 30 | + |
| 31 | +/** Convert char data to 32-bit int (little-endian). |
| 32 | + * |
| 33 | + * \param data Pointer to a buffer of at least 4 bytes. |
| 34 | + * \return The decoded integer value. |
| 35 | + */ |
| 36 | +int |
| 37 | +DecodeInt(const void * data); |
| 38 | + |
| 39 | +/** Convert 32-bit int (little-endian) to char data. |
| 40 | + * |
| 41 | + * \param data The integer to convert. |
| 42 | + * \param target Pointer to a buffer of at least 4 bytes to store the result. |
| 43 | + */ |
| 44 | +void |
| 45 | +EncodeInt(int data, void * target); |
| 46 | + |
| 47 | +/** Convert char data to float (single precision). |
| 48 | + * |
| 49 | + * \param data Pointer to a buffer of at least 4 bytes. |
| 50 | + * \return The decoded float value. |
| 51 | + */ |
| 52 | +float |
| 53 | +DecodeFloat(const void * data); |
| 54 | + |
| 55 | +/** Convert char data to float (double precision). |
| 56 | + * |
| 57 | + * \param data Pointer to a buffer of at least 8 bytes. |
| 58 | + * \return The decoded double value. |
| 59 | + */ |
| 60 | +double |
| 61 | +DecodeDouble(const void * data); |
| 62 | + |
| 63 | +/** Convert a VMS timestamp to a calendar date. |
| 64 | + * |
| 65 | + * \param data Pointer to a buffer of at least 8 bytes containing the VMS timestamp. |
| 66 | + * \param year The extracted Gregorian year. |
| 67 | + * \param month The extracted Gregorian month (1-12). |
| 68 | + * \param day The extracted Gregorian day (1-31). |
| 69 | + * \param hour The extracted hour (0-23). |
| 70 | + * \param minute The extracted minute (0-59). |
| 71 | + * \param second The extracted second (0-59). |
| 72 | + * \param millis The extracted milliseconds (0-999). |
| 73 | + */ |
| 74 | +void |
| 75 | +DecodeDate(const void * data, int & year, int & month, int & day, int & hour, int & minute, int & second, int & millis); |
| 76 | + |
| 77 | +/** Convert the current calendar date to a VMS timestamp and store in target |
| 78 | + * |
| 79 | + * \param target Pointer to a buffer of at least 8 bytes to store the VMS timestamp. |
| 80 | + */ |
| 81 | +void |
| 82 | +EncodeCurrentDate(void * target); |
| 83 | + |
| 84 | +/** Convert a calendar date to VMS timestamp |
| 85 | + * |
| 86 | + * \param target Pointer to a buffer of at least 8 bytes to store the timestamp. |
| 87 | + * \param dateString A string in the format "YYYY-MM-DD HH:MM:SS.mmm" |
| 88 | + */ |
| 89 | +void |
| 90 | +EncodeDateFromString(void * target, const char dateString[32]); |
| 91 | + |
| 92 | +/** Strip a string by removing trailing whitespace. |
| 93 | + * |
| 94 | + * \attention dest must have a size of at least l+1. |
| 95 | + * \param dest The destination string to be stripped. |
| 96 | + * \param source The source string to copy from. |
| 97 | + * \param length The total length of the destination string. |
| 98 | + */ |
| 99 | +void |
| 100 | +StripString(char * dest, const char * source, size_t length); |
| 101 | + |
| 102 | +/** Pad a string with spaces to a specified length. |
| 103 | + * |
| 104 | + * \attention dest must have a size of at least l+1. |
| 105 | + * \param dest The destination string to be padded. |
| 106 | + * \param source The source string to copy from. |
| 107 | + * \param length The total length of the destination string after padding. |
| 108 | + */ |
| 109 | +void |
| 110 | +PadString(char * dest, const char * source, size_t length); |
| 111 | + |
| 112 | +#endif // itkScancoDataManipulation_h |
0 commit comments