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