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