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