File: | comphelper/source/container/container.cxx |
Location: | line 81, column 99 |
Description: | Called C++ object pointer is null |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |||
2 | /* | |||
3 | * This file is part of the LibreOffice project. | |||
4 | * | |||
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/. | |||
8 | * | |||
9 | * This file incorporates work covered by the following license notice: | |||
10 | * | |||
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 . | |||
18 | */ | |||
19 | ||||
20 | #include <com/sun/star/uno/XInterface.hpp> | |||
21 | #include <com/sun/star/container/XIndexAccess.hpp> | |||
22 | #include <com/sun/star/container/XChild.hpp> | |||
23 | #include <comphelper/container.hxx> | |||
24 | #include <osl/diagnose.h> | |||
25 | ||||
26 | //......................................................................... | |||
27 | namespace comphelper | |||
28 | { | |||
29 | //......................................................................... | |||
30 | ||||
31 | //============================================================================== | |||
32 | IndexAccessIterator::IndexAccessIterator(::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> xStartingPoint) | |||
33 | :m_xStartingPoint(xStartingPoint) | |||
34 | ,m_xCurrentObject(NULL__null) | |||
35 | { | |||
36 | OSL_ENSURE(m_xStartingPoint.is(), "IndexAccessIterator::IndexAccessIterator : no starting point !")do { if (true && (!(m_xStartingPoint.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/comphelper/source/container/container.cxx" ":" "36" ": "), "%s", "IndexAccessIterator::IndexAccessIterator : no starting point !" ); } } while (false); | |||
37 | } | |||
38 | ||||
39 | IndexAccessIterator::~IndexAccessIterator() {} | |||
40 | ||||
41 | //------------------------------------------------------------------------------ | |||
42 | ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> IndexAccessIterator::Next() | |||
43 | { | |||
44 | sal_Bool bCheckingStartingPoint = !m_xCurrentObject.is(); | |||
45 | // Is the current node the starting point? | |||
46 | sal_Bool bAlreadyCheckedCurrent = m_xCurrentObject.is(); | |||
47 | // Have I already tested the current node through ShouldHandleElement? | |||
48 | if (!m_xCurrentObject.is()) | |||
| ||||
49 | m_xCurrentObject = m_xStartingPoint; | |||
50 | ||||
51 | ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> xSearchLoop( m_xCurrentObject); | |||
52 | sal_Bool bHasMoreToSearch = sal_True((sal_Bool)1); | |||
53 | sal_Bool bFoundSomething = sal_False((sal_Bool)0); | |||
54 | while (!bFoundSomething && bHasMoreToSearch) | |||
55 | { | |||
56 | // Priming loop | |||
57 | if (!bAlreadyCheckedCurrent && ShouldHandleElement(xSearchLoop)) | |||
58 | { | |||
59 | m_xCurrentObject = xSearchLoop; | |||
60 | bFoundSomething = sal_True((sal_Bool)1); | |||
61 | } | |||
62 | else | |||
63 | { | |||
64 | // First, check to see if there's a match below | |||
65 | ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess> xContainerAccess(xSearchLoop, ::com::sun::star::uno::UNO_QUERY); | |||
66 | if (xContainerAccess.is() && xContainerAccess->getCount() && ShouldStepInto(xContainerAccess)) | |||
67 | { | |||
68 | ::com::sun::star::uno::Any aElement(xContainerAccess->getByIndex(0)); | |||
69 | xSearchLoop = *(::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>*)aElement.getValue(); | |||
70 | bCheckingStartingPoint = sal_False((sal_Bool)0); | |||
71 | ||||
72 | m_arrChildIndizies.push_back((sal_Int32)0); | |||
73 | } | |||
74 | else | |||
75 | { // otherwise, look above and to the right, if possible | |||
76 | while (m_arrChildIndizies.size() > 0) | |||
77 | { // If the list isn't empty and there's nothing above | |||
78 | ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild> xChild(xSearchLoop, ::com::sun::star::uno::UNO_QUERY); | |||
79 | OSL_ENSURE(xChild.is(), "IndexAccessIterator::Next : a content has no approriate interface !")do { if (true && (!(xChild.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/comphelper/source/container/container.cxx" ":" "79" ": "), "%s", "IndexAccessIterator::Next : a content has no approriate interface !" ); } } while (false); | |||
80 | ||||
81 | ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> xParent( xChild->getParent()); | |||
| ||||
82 | xContainerAccess = ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>(xParent, ::com::sun::star::uno::UNO_QUERY); | |||
83 | OSL_ENSURE(xContainerAccess.is(), "IndexAccessIterator::Next : a content has an invalid parent !")do { if (true && (!(xContainerAccess.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/comphelper/source/container/container.cxx" ":" "83" ": "), "%s", "IndexAccessIterator::Next : a content has an invalid parent !" ); } } while (false); | |||
84 | ||||
85 | // Remove the index that SearchLoop had within this parent from my stack | |||
86 | sal_Int32 nOldSearchChildIndex = m_arrChildIndizies[m_arrChildIndizies.size() - 1]; | |||
87 | m_arrChildIndizies.pop_back(); | |||
88 | ||||
89 | if (nOldSearchChildIndex < xContainerAccess->getCount() - 1) | |||
90 | { // Move to the right in this row | |||
91 | ++nOldSearchChildIndex; | |||
92 | // and check the next child | |||
93 | ::com::sun::star::uno::Any aElement(xContainerAccess->getByIndex(nOldSearchChildIndex)); | |||
94 | xSearchLoop = *(::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>*) aElement.getValue(); | |||
95 | bCheckingStartingPoint = sal_False((sal_Bool)0); | |||
96 | // and update its position in the list. | |||
97 | m_arrChildIndizies.push_back((sal_Int32)nOldSearchChildIndex); | |||
98 | ||||
99 | break; | |||
100 | } | |||
101 | // Finally, if there's nothing more to do in this row (to the right), we'll move on to the next row. | |||
102 | xSearchLoop = xParent; | |||
103 | bCheckingStartingPoint = sal_False((sal_Bool)0); | |||
104 | } | |||
105 | ||||
106 | if (m_arrChildIndizies.empty() && !bCheckingStartingPoint) | |||
107 | { //This is the case if there is nothing to the right in the original search loop | |||
108 | bHasMoreToSearch = sal_False((sal_Bool)0); | |||
109 | } | |||
110 | } | |||
111 | ||||
112 | if (bHasMoreToSearch) | |||
113 | { // If there is still a node in the tree which can be tested | |||
114 | if (ShouldHandleElement(xSearchLoop)) | |||
115 | { | |||
116 | m_xCurrentObject = xSearchLoop; | |||
117 | bFoundSomething = sal_True((sal_Bool)1); | |||
118 | } | |||
119 | else | |||
120 | if (bCheckingStartingPoint) | |||
121 | bHasMoreToSearch = sal_False((sal_Bool)0); | |||
122 | bAlreadyCheckedCurrent = sal_True((sal_Bool)1); | |||
123 | } | |||
124 | } | |||
125 | } | |||
126 | ||||
127 | if (!bFoundSomething) | |||
128 | { | |||
129 | OSL_ENSURE(m_arrChildIndizies.empty(), "IndexAccessIterator::Next : items left on stack ! how this ?")do { if (true && (!(m_arrChildIndizies.empty()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/comphelper/source/container/container.cxx" ":" "129" ": "), "%s", "IndexAccessIterator::Next : items left on stack ! how this ?" ); } } while (false); | |||
130 | Invalidate(); | |||
131 | } | |||
132 | ||||
133 | return m_xCurrentObject; | |||
134 | } | |||
135 | ||||
136 | //......................................................................... | |||
137 | } // namespace comphelper | |||
138 | //......................................................................... | |||
139 | ||||
140 | ||||
141 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |