Skip to content

Commit af38a8b

Browse files
committed
cleanup: move Type_collection_fbt<> template out of Type_handler_fbt<>
1 parent c09b158 commit af38a8b

File tree

1 file changed

+78
-71
lines changed

1 file changed

+78
-71
lines changed

sql/sql_type_fixedbin.h

Lines changed: 78 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
/***********************************************************************/
3232

3333

34-
template<class FbtImpl>
34+
template<class FbtImpl> class Type_collection_fbt;
35+
36+
template<class FbtImpl, class TypeCollectionImpl = Type_collection_fbt<FbtImpl> >
3537
class Type_handler_fbt: public Type_handler
3638
{
3739
/* =[ internal helper classes ]=============================== */
@@ -210,74 +212,6 @@ class Type_handler_fbt: public Type_handler
210212

211213
/* =[ API classes ]=========================================== */
212214

213-
class Type_collection_fbt: public Type_collection
214-
{
215-
const Type_handler *aggregate_common(const Type_handler *a,
216-
const Type_handler *b) const
217-
{
218-
if (a == b)
219-
return a;
220-
return NULL;
221-
}
222-
const Type_handler *aggregate_if_string(const Type_handler *a,
223-
const Type_handler *b) const
224-
{
225-
static const Type_aggregator::Pair agg[]=
226-
{
227-
{singleton(), &type_handler_null, singleton()},
228-
{singleton(), &type_handler_varchar, singleton()},
229-
{singleton(), &type_handler_string, singleton()},
230-
{singleton(), &type_handler_tiny_blob, singleton()},
231-
{singleton(), &type_handler_blob, singleton()},
232-
{singleton(), &type_handler_medium_blob, singleton()},
233-
{singleton(), &type_handler_long_blob, singleton()},
234-
{singleton(), &type_handler_hex_hybrid, singleton()},
235-
{NULL,NULL,NULL}
236-
};
237-
return Type_aggregator::find_handler_in_array(agg, a, b, true);
238-
}
239-
public:
240-
const Type_handler *aggregate_for_result(const Type_handler *a,
241-
const Type_handler *b)
242-
const override
243-
{
244-
const Type_handler *h;
245-
if ((h= aggregate_common(a, b)) ||
246-
(h= aggregate_if_string(a, b)))
247-
return h;
248-
return NULL;
249-
}
250-
251-
const Type_handler *aggregate_for_min_max(const Type_handler *a,
252-
const Type_handler *b)
253-
const override
254-
{
255-
return aggregate_for_result(a, b);
256-
}
257-
258-
const Type_handler *aggregate_for_comparison(const Type_handler *a,
259-
const Type_handler *b)
260-
const override
261-
{
262-
if (const Type_handler *h= aggregate_common(a, b))
263-
return h;
264-
static const Type_aggregator::Pair agg[]=
265-
{
266-
{singleton(), &type_handler_null, singleton()},
267-
{singleton(), &type_handler_long_blob, singleton()},
268-
{NULL,NULL,NULL}
269-
};
270-
return Type_aggregator::find_handler_in_array(agg, a, b, true);
271-
}
272-
273-
const Type_handler *aggregate_for_num_op(const Type_handler *a,
274-
const Type_handler *b)
275-
const override
276-
{
277-
return NULL;
278-
}
279-
};
280-
281215
class Type_std_attributes_fbt: public Type_std_attributes
282216
{
283217
public:
@@ -1120,8 +1054,7 @@ class Type_handler_fbt: public Type_handler
11201054

11211055
const Type_collection *type_collection() const override
11221056
{
1123-
static Type_collection_fbt type_collection_fbt;
1124-
return &type_collection_fbt;
1057+
return TypeCollectionImpl::singleton();
11251058
}
11261059

11271060
const Name &default_value() const override
@@ -1902,4 +1835,78 @@ class Type_handler_fbt: public Type_handler
19021835
}
19031836
};
19041837

1838+
template<class FbtImpl>
1839+
class Type_collection_fbt: public Type_collection
1840+
{
1841+
const Type_handler *aggregate_common(const Type_handler *a,
1842+
const Type_handler *b) const
1843+
{
1844+
if (a == b)
1845+
return a;
1846+
return NULL;
1847+
}
1848+
const Type_handler *aggregate_if_string(const Type_handler *a,
1849+
const Type_handler *b) const
1850+
{
1851+
static const Type_aggregator::Pair agg[]=
1852+
{
1853+
{Type_handler_fbt<FbtImpl>::singleton(), &type_handler_null, Type_handler_fbt<FbtImpl>::singleton()},
1854+
{Type_handler_fbt<FbtImpl>::singleton(), &type_handler_varchar, Type_handler_fbt<FbtImpl>::singleton()},
1855+
{Type_handler_fbt<FbtImpl>::singleton(), &type_handler_string, Type_handler_fbt<FbtImpl>::singleton()},
1856+
{Type_handler_fbt<FbtImpl>::singleton(), &type_handler_tiny_blob, Type_handler_fbt<FbtImpl>::singleton()},
1857+
{Type_handler_fbt<FbtImpl>::singleton(), &type_handler_blob, Type_handler_fbt<FbtImpl>::singleton()},
1858+
{Type_handler_fbt<FbtImpl>::singleton(), &type_handler_medium_blob, Type_handler_fbt<FbtImpl>::singleton()},
1859+
{Type_handler_fbt<FbtImpl>::singleton(), &type_handler_long_blob, Type_handler_fbt<FbtImpl>::singleton()},
1860+
{Type_handler_fbt<FbtImpl>::singleton(), &type_handler_hex_hybrid, Type_handler_fbt<FbtImpl>::singleton()},
1861+
{NULL,NULL,NULL}
1862+
};
1863+
return Type_aggregator::find_handler_in_array(agg, a, b, true);
1864+
}
1865+
public:
1866+
const Type_handler *aggregate_for_result(const Type_handler *a,
1867+
const Type_handler *b)
1868+
const override
1869+
{
1870+
const Type_handler *h;
1871+
if ((h= aggregate_common(a, b)) || (h= aggregate_if_string(a, b)))
1872+
return h;
1873+
return NULL;
1874+
}
1875+
1876+
const Type_handler *aggregate_for_min_max(const Type_handler *a,
1877+
const Type_handler *b)
1878+
const override
1879+
{
1880+
return aggregate_for_result(a, b);
1881+
}
1882+
1883+
const Type_handler *aggregate_for_comparison(const Type_handler *a,
1884+
const Type_handler *b)
1885+
const override
1886+
{
1887+
if (const Type_handler *h= aggregate_common(a, b))
1888+
return h;
1889+
static const Type_aggregator::Pair agg[]=
1890+
{
1891+
{Type_handler_fbt<FbtImpl>::singleton(), &type_handler_null, Type_handler_fbt<FbtImpl>::singleton()},
1892+
{Type_handler_fbt<FbtImpl>::singleton(), &type_handler_long_blob, Type_handler_fbt<FbtImpl>::singleton()},
1893+
{NULL,NULL,NULL}
1894+
};
1895+
return Type_aggregator::find_handler_in_array(agg, a, b, true);
1896+
}
1897+
1898+
const Type_handler *aggregate_for_num_op(const Type_handler *a,
1899+
const Type_handler *b)
1900+
const override
1901+
{
1902+
return NULL;
1903+
}
1904+
1905+
static Type_collection_fbt *singleton()
1906+
{
1907+
static Type_collection_fbt tc;
1908+
return &tc;
1909+
}
1910+
};
1911+
19051912
#endif /* SQL_TYPE_FIXEDBIN_H */

0 commit comments

Comments
 (0)