xref: /aoo41x/main/cosv/inc/cosv/comfunc.hxx (revision ac3d0c65)
1*ac3d0c65SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ac3d0c65SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ac3d0c65SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ac3d0c65SAndrew Rist  * distributed with this work for additional information
6*ac3d0c65SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ac3d0c65SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ac3d0c65SAndrew Rist  * "License"); you may not use this file except in compliance
9*ac3d0c65SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ac3d0c65SAndrew Rist  *
11*ac3d0c65SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ac3d0c65SAndrew Rist  *
13*ac3d0c65SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ac3d0c65SAndrew Rist  * software distributed under the License is distributed on an
15*ac3d0c65SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ac3d0c65SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ac3d0c65SAndrew Rist  * specific language governing permissions and limitations
18*ac3d0c65SAndrew Rist  * under the License.
19*ac3d0c65SAndrew Rist  *
20*ac3d0c65SAndrew Rist  *************************************************************/
21*ac3d0c65SAndrew Rist 
22*ac3d0c65SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef CSV_COMFUNC_HXX
25cdf0e10cSrcweir #define CSV_COMFUNC_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <stdlib.h>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir namespace csv
33cdf0e10cSrcweir {
34cdf0e10cSrcweir     class String;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir // min, max and range functions
38cdf0e10cSrcweir template <class E>
39cdf0e10cSrcweir inline E            max(E in1, E in2);
40cdf0e10cSrcweir template <class E>
41cdf0e10cSrcweir inline E            min(E in1, E in2);
42cdf0e10cSrcweir template <class E>
43cdf0e10cSrcweir inline bool         in_range(E low, E val, E high);    // return low <= val < high;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // string functions
47cdf0e10cSrcweir inline const char * valid_str(const char * str);
48cdf0e10cSrcweir inline bool         no_str(const char * str);       // return !str || !strlen(str)
49cdf0e10cSrcweir intt                count_chars(const char * str, char c);
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 
52cdf0e10cSrcweir // endian functions
53cdf0e10cSrcweir template <class NUMTYPE>
54cdf0e10cSrcweir void                switch_endian(
55cdf0e10cSrcweir                         NUMTYPE &       o_rNumber,
56cdf0e10cSrcweir                         const NUMTYPE & i_rNumber );
57cdf0e10cSrcweir 
58cdf0e10cSrcweir // Zeit-Typecasts
59cdf0e10cSrcweir bool  str2date(const char * str, int & out_day, int & out_month, int & out_year);
60cdf0e10cSrcweir void  date2str(String       & out_Str, int day, int month, int year);
61cdf0e10cSrcweir bool  str2time(const char * str, int & out_hour, int & out_min, int & out_sec);
62cdf0e10cSrcweir void  time2str(String       & out_Str, int hour, int min, int sec);
63cdf0e10cSrcweir 
64cdf0e10cSrcweir class noncopyable
65cdf0e10cSrcweir {
66cdf0e10cSrcweir   protected:
noncopyable()67cdf0e10cSrcweir                         noncopyable() {}
~noncopyable()68cdf0e10cSrcweir                         ~noncopyable() {}
69cdf0e10cSrcweir   private:
70cdf0e10cSrcweir     // Private to make copying impossible:
71cdf0e10cSrcweir                         noncopyable(const noncopyable&);
72cdf0e10cSrcweir     noncopyable &       operator=(const noncopyable&);
73cdf0e10cSrcweir };
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 
78cdf0e10cSrcweir // IMPLEMENTATION
79cdf0e10cSrcweir template <class E>
80cdf0e10cSrcweir inline E
max(E in1,E in2)81cdf0e10cSrcweir max(E in1, E in2)   { return in1 < in2 ? in2 : in1; }
82cdf0e10cSrcweir template <class E>
83cdf0e10cSrcweir inline E
min(E in1,E in2)84cdf0e10cSrcweir min(E in1, E in2)   { return in1 < in2 ? in1 : in2; }
85cdf0e10cSrcweir template <class E>
86cdf0e10cSrcweir inline bool
in_range(E low,E val,E high)87cdf0e10cSrcweir in_range(E low, E val, E high) { return low <= val AND val < high; }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir inline const char *
valid_str(const char * str)90cdf0e10cSrcweir valid_str(const char * str) { return str != 0 ? str : ""; }
91cdf0e10cSrcweir inline bool
no_str(const char * str)92cdf0e10cSrcweir no_str(const char * str) { return str != 0 ? *str == '\0' : true; }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 
95cdf0e10cSrcweir template <class NUMTYPE>
96cdf0e10cSrcweir void
switch_endian(NUMTYPE & o_rNumber,const NUMTYPE & i_rNumber)97cdf0e10cSrcweir switch_endian( NUMTYPE &       o_rNumber,
98cdf0e10cSrcweir                const NUMTYPE & i_rNumber )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir     char *          pFront = reinterpret_cast< char* >(&o_rNumber);
101cdf0e10cSrcweir     const char *    pBack  = reinterpret_cast< const char* >(&i_rNumber) + sizeof(NUMTYPE);
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     for ( size_t p = 0; p < sizeof(NUMTYPE); --p )
104cdf0e10cSrcweir     {
105cdf0e10cSrcweir         *pFront++ = *(--pBack);
106cdf0e10cSrcweir     }
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 
110cdf0e10cSrcweir }   // namespace csv
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 
115cdf0e10cSrcweir #define NON_COPYABLE(xy) \
116cdf0e10cSrcweir     private: xy(const xy &); xy & operator=(const xy &)
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 
121cdf0e10cSrcweir #endif
122