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 #ifndef INCLUDED_UNODEVTOOLS_SOURCE_SKELETONMAKER_SKELETONCOMMON_HXX
28 #define INCLUDED_UNODEVTOOLS_SOURCE_SKELETONMAKER_SKELETONCOMMON_HXX
29 
30 #include "rtl/string.hxx"
31 #include "registry/reader.hxx"
32 #include "codemaker/typemanager.hxx"
33 #include "codemaker/unotype.hxx"
34 
35 #include <fstream>
36 #include <hash_set>
37 #include <map>
38 
39 namespace skeletonmaker {
40 
41 typedef ::std::map< ::rtl::OString, ::std::vector< ::rtl::OString >,
42                     ::std::less< ::rtl::OString > > ProtocolCmdMap;
43 
44 typedef ::std::vector< ::std::pair< rtl::OString,
45                      ::std::pair< rtl::OString, sal_Int16 > > > AttributeInfo;
46 
47 
48 struct ProgramOptions {
49     ProgramOptions(): java5(true), all(false), dump(false), license(false),
50                       shortnames(false), supportpropertysetmixin(false),
51                       backwardcompatible(false), language(1), componenttype(1) {}
52 
53     bool java5;
54     bool all;
55     bool dump;
56     bool license;
57     bool shortnames;
58     bool supportpropertysetmixin;
59     bool backwardcompatible;
60     // language specifier - is extendable
61     // 1 = Java
62     // 2 = C++
63     short language;
64     // component type
65     // 1 = default UNO component - is extendable
66     // 2 = calc add-in
67     // 3 = add-on
68     short componenttype;
69     rtl::OString outputpath;
70     rtl::OString implname;
71     ProtocolCmdMap protocolCmdMap;
72 };
73 
74 
75 /**
76    print the standard OpenOffice.org license header
77 
78    @param o specifies the output stream
79    @param filename specifies the source file name
80 */
81 void printLicenseHeader(std::ostream& o, rtl::OString const & filename);
82 
83 /**
84    create dependent on the output path, the implementation name and the
85    extension a new output file. If output path is equal "stdout" the tool
86    generates the output to standard out.
87 
88    @param options the program options including the output path and the
89                   implementation name
90    @param extension specifies the file extensions (e.g. .cxx or .java)
91    @param ppOutputStream out parameter returning the output stream
92    @param targetSourceFileName out parameter returning the generated file name
93                                constructed on base of the output path, the
94                                implementation name and the extension
95    @param tmpSourceFileName out parameter returning the temporary file name based
96                             on the output path and a generated temporary file name.
97    @return true if output is generated to standard out or else false
98 */
99 bool getOutputStream(ProgramOptions const & options,
100                      rtl::OString const & extension,
101                      std::ostream** ppOutputStream,
102                      rtl::OString & targetSourceFileName,
103                      rtl::OString & tmpSourceFileName);
104 
105 codemaker::UnoType::Sort decomposeResolveAndCheck(
106     TypeManager const & manager, rtl::OString const & type,
107     bool resolveTypedefs, bool allowVoid, bool allowExtraEntities,
108     RTTypeClass * typeClass, rtl::OString * name, sal_Int32 * rank,
109     std::vector< rtl::OString > * arguments);
110 
111 void checkType(TypeManager const & manager,
112                rtl::OString const & type,
113                std::hash_set< rtl::OString, rtl::OStringHash >& interfaceTypes,
114                std::hash_set< rtl::OString, rtl::OStringHash >& serviceTypes,
115                AttributeInfo& properties);
116 
117 void checkDefaultInterfaces(
118     std::hash_set< rtl::OString, rtl::OStringHash >& interfaces,
119     const std::hash_set< rtl::OString, rtl::OStringHash >& services,
120     const rtl::OString & propertyhelper);
121 
122 rtl::OString checkPropertyHelper(
123     ProgramOptions const & options, TypeManager const & manager,
124     const std::hash_set< rtl::OString, rtl::OStringHash >& services,
125     const std::hash_set< rtl::OString, rtl::OStringHash >& interfaces,
126     AttributeInfo& attributes,
127     std::hash_set< rtl::OString, rtl::OStringHash >& propinterfaces);
128 
129 /**
130    checks whether the return and parameters types are valid and allowed
131    calc add-in type. The function throws a CannotDumpException with an
132    detailed error description which type is wrong
133 
134    @param manager a type manager
135    @param reader a registry type reader of an interface defining
136                  calc add-in functions
137 */
138 void checkAddInTypes(TypeManager const & manager,
139                      typereg::Reader const & reader);
140 
141 
142 /**
143    checks if XComponent have to be supported, if yes it removes it from the
144    supported interfaces list becuase it becmoes implmented by the appropriate
145    helper
146 
147    @param manager a type manager
148    @param interfaces a list of interfaces which should be implemented
149 
150    @return true if XComponent have to be supported
151 */
152 bool checkXComponentSupport(TypeManager const & manager,
153          std::hash_set< rtl::OString, rtl::OStringHash >& interfaces);
154 
155 
156 sal_uInt16 checkAdditionalPropertyFlags(typereg::Reader const & reader,
157                                         sal_uInt16 field, sal_uInt16 method);
158 
159 
160 void generateFunctionParameterMap(std::ostream& o,
161          ProgramOptions const & options,
162          TypeManager const & manager,
163          const std::hash_set< ::rtl::OString, ::rtl::OStringHash >& interfaces);
164 
165 }
166 
167 #endif // INCLUDED_UNODEVTOOLS_SOURCE_SKELETONMAKER_SKELETONCOMMON_HXX
168 
169