xref: /aoo42x/main/autodoc/inc/cosv/comfunc.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef CSV_COMFUNC_HXX
29 #define CSV_COMFUNC_HXX
30 
31 #include <stdlib.h>
32 
33 
34 
35 
36 namespace csv
37 {
38     class String;
39 
40 
41 // min, max and range functions
42 template <class E>
43 inline E            max(E in1, E in2);
44 template <class E>
45 inline E            min(E in1, E in2);
46 template <class E>
47 inline bool         in_range(E low, E val, E high);    // return low <= val < high;
48 
49 
50 // string functions
51 inline const char * valid_str(const char * str);
52 inline bool         no_str(const char * str);       // return !str || !strlen(str)
53 intt                count_chars(const char * str, char c);
54 
55 
56 // endian functions
57 template <class NUMTYPE>
58 void                switch_endian(
59                         NUMTYPE &       o_rNumber,
60                         const NUMTYPE & i_rNumber );
61 
62 // Zeit-Typecasts
63 bool  str2date(const char * str, int & out_day, int & out_month, int & out_year);
64 void  date2str(String       & out_Str, int day, int month, int year);
65 bool  str2time(const char * str, int & out_hour, int & out_min, int & out_sec);
66 void  time2str(String       & out_Str, int hour, int min, int sec);
67 
68 class noncopyable
69 {
70   protected:
71                         noncopyable() {}
72                         ~noncopyable() {}
73   private:
74     // Private to make copying impossible:
75                         noncopyable(const noncopyable&);
76     noncopyable &       operator=(const noncopyable&);
77 };
78 
79 
80 
81 
82 // IMPLEMENTATION
83 template <class E>
84 inline E
85 max(E in1, E in2)   { return in1 < in2 ? in2 : in1; }
86 template <class E>
87 inline E
88 min(E in1, E in2)   { return in1 < in2 ? in1 : in2; }
89 template <class E>
90 inline bool
91 in_range(E low, E val, E high) { return low <= val AND val < high; }
92 
93 inline const char *
94 valid_str(const char * str) { return str != 0 ? str : ""; }
95 inline bool
96 no_str(const char * str) { return str != 0 ? *str == '\0' : true; }
97 
98 
99 template <class NUMTYPE>
100 void
101 switch_endian( NUMTYPE &       o_rNumber,
102                const NUMTYPE & i_rNumber )
103 {
104     char *          pFront = reinterpret_cast< char* >(&o_rNumber);
105     const char *    pBack  = reinterpret_cast< const char* >(&i_rNumber) + sizeof(NUMTYPE);
106 
107     for ( size_t p = 0; p < sizeof(NUMTYPE); --p )
108     {
109         *pFront++ = *(--pBack);
110     }
111 }
112 
113 
114 }   // namespace csv
115 
116 
117 
118 
119 #define NON_COPYABLE(xy) \
120     private: xy(const xy &); xy & operator=(const xy &)
121 
122 
123 
124 
125 #endif
126