GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / i18npool / source / calendar / calendarImpl.cxx
blob5f9396b130c6e2b2a6d298f44475c052933871ff
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "calendarImpl.hxx"
22 #include "localedata.hxx"
23 #include <comphelper/processfactory.hxx>
25 using namespace ::com::sun::star::uno;
26 using namespace ::com::sun::star::lang;
28 namespace com { namespace sun { namespace star { namespace i18n {
30 #define ERROR RuntimeException()
32 CalendarImpl::CalendarImpl(const Reference< XComponentContext > &rxContext) : m_xContext(rxContext)
36 CalendarImpl::~CalendarImpl()
38 // Clear lookuptable
39 for (size_t l = 0; l < lookupTable.size(); l++)
40 delete lookupTable[l];
41 lookupTable.clear();
45 void SAL_CALL
46 CalendarImpl::loadDefaultCalendar( const Locale& rLocale ) throw(RuntimeException)
48 Sequence< Calendar2 > xC = LocaleDataImpl().getAllCalendars2(rLocale);
49 for (sal_Int32 i = 0; i < xC.getLength(); i++) {
50 if (xC[i].Default) {
51 loadCalendar(xC[i].Name, rLocale);
52 return;
55 throw ERROR;
58 void SAL_CALL
59 CalendarImpl::loadCalendar(const OUString& uniqueID, const Locale& rLocale ) throw (RuntimeException)
61 Reference < XCalendar3 > xOldCalendar( xCalendar ); // backup
62 sal_Int32 i;
64 for (i = 0; i < sal::static_int_cast<sal_Int32>(lookupTable.size()); i++) {
65 lookupTableItem *listItem = lookupTable[i];
66 if (uniqueID == listItem->uniqueID) {
67 xCalendar = listItem->xCalendar;
68 break;
72 if (i >= sal::static_int_cast<sal_Int32>(lookupTable.size())) {
73 Reference < XInterface > xI = m_xContext->getServiceManager()->createInstanceWithContext(
74 OUString("com.sun.star.i18n.Calendar_") + uniqueID, m_xContext);
76 if ( ! xI.is() ) {
77 // check if the calendar is defined in localedata, load gregorian calendar service.
78 Sequence< Calendar2 > xC = LocaleDataImpl().getAllCalendars2(rLocale);
79 for (i = 0; i < xC.getLength(); i++) {
80 if (uniqueID == xC[i].Name) {
81 xI = m_xContext->getServiceManager()->createInstanceWithContext("com.sun.star.i18n.Calendar_gregorian", m_xContext);
82 break;
87 if ( xI.is() )
88 xCalendar.set(xI, UNO_QUERY);
89 else
90 throw ERROR;
92 lookupTable.push_back( new lookupTableItem(uniqueID, xCalendar) );
95 if ( !xCalendar.is() )
97 xCalendar = xOldCalendar;
98 throw ERROR;
103 xCalendar->loadCalendar(uniqueID, rLocale);
105 catch ( Exception& )
106 { // restore previous calendar and re-throw
107 xCalendar = xOldCalendar;
108 throw;
112 Calendar2 SAL_CALL
113 CalendarImpl::getLoadedCalendar2() throw(RuntimeException)
115 if (xCalendar.is())
116 return xCalendar->getLoadedCalendar2();
117 else
118 throw ERROR ;
121 Calendar SAL_CALL
122 CalendarImpl::getLoadedCalendar() throw(RuntimeException)
124 if (xCalendar.is())
125 return xCalendar->getLoadedCalendar();
126 else
127 throw ERROR ;
130 Sequence< OUString > SAL_CALL
131 CalendarImpl::getAllCalendars( const Locale& rLocale ) throw(RuntimeException)
133 Sequence< Calendar2 > xC = LocaleDataImpl().getAllCalendars2(rLocale);
134 sal_Int32 nLen = xC.getLength();
135 Sequence< OUString > xSeq( nLen );
136 for (sal_Int32 i = 0; i < nLen; i++)
137 xSeq[i] = xC[i].Name;
138 return xSeq;
141 void SAL_CALL
142 CalendarImpl::setDateTime( double timeInDays ) throw(RuntimeException)
144 if (xCalendar.is())
145 xCalendar->setDateTime( timeInDays );
146 else
147 throw ERROR ;
150 double SAL_CALL
151 CalendarImpl::getDateTime() throw(RuntimeException)
153 if (xCalendar.is())
154 return xCalendar->getDateTime();
155 else
156 throw ERROR ;
159 OUString SAL_CALL
160 CalendarImpl::getUniqueID() throw(RuntimeException)
162 if (xCalendar.is())
163 return xCalendar->getUniqueID();
164 else
165 throw ERROR ;
168 void SAL_CALL
169 CalendarImpl::setValue( sal_Int16 fieldIndex, sal_Int16 value ) throw(RuntimeException)
171 if (xCalendar.is())
172 xCalendar->setValue( fieldIndex, value );
173 else
174 throw ERROR ;
177 sal_Int16 SAL_CALL
178 CalendarImpl::getValue( sal_Int16 fieldIndex ) throw(RuntimeException)
180 if (xCalendar.is())
181 return xCalendar->getValue( fieldIndex );
182 else
183 throw ERROR ;
186 void SAL_CALL
187 CalendarImpl::addValue( sal_Int16 fieldIndex, sal_Int32 amount ) throw(RuntimeException)
189 if (xCalendar.is())
190 xCalendar->addValue( fieldIndex, amount);
191 else
192 throw ERROR ;
195 sal_Int16 SAL_CALL
196 CalendarImpl::getFirstDayOfWeek() throw(RuntimeException)
198 if (xCalendar.is())
199 return xCalendar->getFirstDayOfWeek();
200 else
201 throw ERROR ;
204 void SAL_CALL
205 CalendarImpl::setFirstDayOfWeek( sal_Int16 day )
206 throw(RuntimeException)
208 if (xCalendar.is())
209 xCalendar->setFirstDayOfWeek(day);
210 else
211 throw ERROR ;
214 void SAL_CALL
215 CalendarImpl::setMinimumNumberOfDaysForFirstWeek( sal_Int16 days ) throw(RuntimeException)
217 if (xCalendar.is())
218 xCalendar->setMinimumNumberOfDaysForFirstWeek(days);
219 else
220 throw ERROR ;
223 sal_Int16 SAL_CALL
224 CalendarImpl::getMinimumNumberOfDaysForFirstWeek() throw(RuntimeException)
226 if (xCalendar.is())
227 return xCalendar->getMinimumNumberOfDaysForFirstWeek();
228 else
229 throw ERROR ;
233 OUString SAL_CALL
234 CalendarImpl::getDisplayName( sal_Int16 displayIndex, sal_Int16 idx, sal_Int16 nameType ) throw(RuntimeException)
236 if (xCalendar.is())
237 return xCalendar->getDisplayName( displayIndex, idx, nameType );
238 else
239 throw ERROR ;
242 sal_Int16 SAL_CALL
243 CalendarImpl::getNumberOfMonthsInYear() throw(RuntimeException)
245 if (xCalendar.is())
246 return xCalendar->getNumberOfMonthsInYear();
247 else
248 throw ERROR ;
252 sal_Int16 SAL_CALL
253 CalendarImpl::getNumberOfDaysInWeek() throw(RuntimeException)
255 if (xCalendar.is())
256 return xCalendar->getNumberOfDaysInWeek();
257 else
258 throw ERROR ;
262 Sequence< CalendarItem > SAL_CALL
263 CalendarImpl::getDays() throw(RuntimeException)
265 if (xCalendar.is())
266 return xCalendar->getDays();
267 else
268 throw ERROR ;
272 Sequence< CalendarItem > SAL_CALL
273 CalendarImpl::getMonths() throw(RuntimeException)
275 if (xCalendar.is())
276 return xCalendar->getMonths();
277 else
278 throw ERROR ;
282 Sequence< CalendarItem2 > SAL_CALL
283 CalendarImpl::getDays2() throw(RuntimeException)
285 if (xCalendar.is())
286 return xCalendar->getDays2();
287 else
288 throw ERROR ;
292 Sequence< CalendarItem2 > SAL_CALL
293 CalendarImpl::getMonths2() throw(RuntimeException)
295 if (xCalendar.is())
296 return xCalendar->getMonths2();
297 else
298 throw ERROR ;
302 Sequence< CalendarItem2 > SAL_CALL
303 CalendarImpl::getGenitiveMonths2() throw(RuntimeException)
305 if (xCalendar.is())
306 return xCalendar->getGenitiveMonths2();
307 else
308 throw ERROR ;
312 Sequence< CalendarItem2 > SAL_CALL
313 CalendarImpl::getPartitiveMonths2() throw(RuntimeException)
315 if (xCalendar.is())
316 return xCalendar->getPartitiveMonths2();
317 else
318 throw ERROR ;
322 sal_Bool SAL_CALL
323 CalendarImpl::isValid() throw(RuntimeException)
325 if (xCalendar.is())
326 return xCalendar->isValid();
327 else
328 throw ERROR ;
331 OUString SAL_CALL
332 CalendarImpl::getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode )
333 throw (RuntimeException)
335 if (xCalendar.is())
336 return xCalendar->getDisplayString(nCalendarDisplayCode, nNativeNumberMode);
337 else
338 throw ERROR ;
341 OUString SAL_CALL
342 CalendarImpl::getImplementationName(void) throw( RuntimeException )
344 return OUString("com.sun.star.i18n.CalendarImpl");
347 const sal_Char cCalendar[] = "com.sun.star.i18n.LocaleCalendar";
349 sal_Bool SAL_CALL
350 CalendarImpl::supportsService(const OUString& rServiceName) throw( RuntimeException )
352 return rServiceName.equalsAscii(cCalendar);
355 Sequence< OUString > SAL_CALL
356 CalendarImpl::getSupportedServiceNames(void) throw( RuntimeException )
358 Sequence< OUString > aRet(1);
359 aRet[0] = OUString::createFromAscii(cCalendar);
360 return aRet;
363 }}}}
365 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */