xref: /aoo4110/main/sc/source/core/inc/doubleref.hxx (revision b1cdbd2c)
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 
24 #ifndef SC_DOUBLEREF_HXX
25 #define SC_DOUBLEREF_HXX
26 
27 #include "address.hxx"
28 #include "scmatrix.hxx"
29 
30 class ScDocument;
31 class ScBaseCell;
32 struct ScDBQueryParamBase;
33 struct ScQueryParamBase;
34 
35 // ============================================================================
36 
37 /**
38  * Base class for abstracting range data backends for database functions.
39  */
40 class ScDBRangeBase
41 {
42 public:
43     enum RefType { INTERNAL, EXTERNAL }; // TODO: We may not need this after all... (kohei)
44 
45     virtual ~ScDBRangeBase() = 0;
46 
47     bool fillQueryEntries(ScQueryParamBase* pParam, const ScDBRangeBase* pDBRef) const;
48 
49     virtual SCCOL getColSize() const = 0;
50     virtual SCROW getRowSize() const = 0;
51     virtual SCSIZE getVisibleDataCellCount() const = 0;
52 
53     /**
54      * Get a string value of a specified cell position.  Note that the
55      * position of the upper left cell of the range is always (0, 0) even if
56      * the reference type is of internal range.
57      *
58      * @param nCol column position (0 to column size-1)
59      * @param nRow row position (0 to row size-1)
60      */
61     virtual ::rtl::OUString getString(SCCOL nCol, SCROW nRow) const = 0;
62 
63     virtual SCCOL getFirstFieldColumn() const = 0;
64 
65     /**
66      * Get a <i>0-based</i> column index that corresponds with the passed field
67      * index.  Note that the field index passed as the 1st parameter is
68      * <i>1-based.</i>
69      *
70      * @param nIndex 1-based field index.
71      *
72      * @return 0-based column index
73      */
74     virtual SCCOL findFieldColumn(SCCOL nIndex) const = 0;
75     virtual SCCOL findFieldColumn(const ::rtl::OUString& rStr, sal_uInt16* pErr = NULL) const = 0;
76     virtual ScDBQueryParamBase* createQueryParam(const ScDBRangeBase* pQueryRef) const = 0;
77     virtual bool isRangeEqual(const ScRange& rRange) const = 0;
78 
79 protected:
80     ScDBRangeBase(ScDocument* pDoc, RefType eType);
81     ScDocument* getDoc() const;
82 
83     /**
84      * Populate query options that are always the same for all database
85      * queries.
86      */
87     static void fillQueryOptions(ScQueryParamBase* pParam);
88 
89 private:
90     ScDBRangeBase(); // disabled
91 
92     ScDocument* mpDoc;
93     RefType meType;
94 };
95 
96 // ============================================================================
97 
98 class ScDBInternalRange : public ScDBRangeBase
99 {
100 public:
101     explicit ScDBInternalRange(ScDocument* pDoc, const ScRange& rRange);
102     virtual ~ScDBInternalRange();
103 
104     const ScRange& getRange() const;
105 
106     virtual SCCOL getColSize() const;
107     virtual SCROW getRowSize() const;
108     virtual SCSIZE getVisibleDataCellCount() const;
109 
110     /**
111      * Get a string value of a specified cell position.  Note that the
112      * position of the upper left cell of the range is always (0, 0) even if
113      * the reference type is of internal range.
114      *
115      * @param nCol column position (0 to column size-1)
116      * @param nRow row position (0 to row size-1)
117      */
118     virtual ::rtl::OUString getString(SCCOL nCol, SCROW nRow) const;
119 
120     virtual SCCOL getFirstFieldColumn() const;
121     /**
122      * Get a <i>0-based</i> column index that corresponds with the passed field
123      * index.  Note that the field index passed as the 1st parameter is
124      * <i>1-based.</i>
125      *
126      * @param nIndex 1-based field index.
127      *
128      * @return 0-based column index
129      */
130     virtual SCCOL findFieldColumn(SCCOL nIndex) const;
131     virtual SCCOL findFieldColumn(const ::rtl::OUString& rStr, sal_uInt16* pErr = NULL) const;
132     virtual ScDBQueryParamBase* createQueryParam(const ScDBRangeBase* pQueryRef) const;
133     virtual bool isRangeEqual(const ScRange& rRange) const;
134 
135 private:
136     ScRange maRange;
137 };
138 
139 // ============================================================================
140 
141 class ScDBExternalRange : public ScDBRangeBase
142 {
143 public:
144     explicit ScDBExternalRange(ScDocument* pDoc, const ScMatrixRef& pMat);
145     virtual ~ScDBExternalRange();
146 
147     virtual SCCOL getColSize() const;
148     virtual SCROW getRowSize() const;
149     virtual SCSIZE getVisibleDataCellCount() const;
150 
151     /**
152      * Get a string value of a specified cell position.  Note that the
153      * position of the upper left cell of the range is always (0, 0) even if
154      * the reference type is of internal range.
155      *
156      * @param nCol column position (0 to column size-1)
157      * @param nRow row position (0 to row size-1)
158      */
159     virtual ::rtl::OUString getString(SCCOL nCol, SCROW nRow) const;
160 
161     virtual SCCOL getFirstFieldColumn() const;
162 
163     /**
164      * Get a <i>0-based</i> column index that corresponds with the passed field
165      * index.  Note that the field index passed as the 1st parameter is
166      * <i>1-based.</i>
167      *
168      * @param nIndex 1-based field index.
169      *
170      * @return 0-based column index
171      */
172     virtual SCCOL findFieldColumn(SCCOL nIndex) const;
173     virtual SCCOL findFieldColumn(const ::rtl::OUString& rStr, sal_uInt16* pErr = NULL) const;
174     virtual ScDBQueryParamBase* createQueryParam(const ScDBRangeBase* pQueryRef) const;
175     virtual bool isRangeEqual(const ScRange& rRange) const;
176 
177 private:
178     const ScMatrixRef mpMatrix;
179     SCCOL mnCols;
180     SCROW mnRows;
181 };
182 
183 #endif
184