From 132ad2ed8d99f87b50177ae1dc36e50f41154a9e Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 29 Nov 2021 22:54:28 +0100 Subject: [PATCH] WIP: removing need to tl::type_traits --- scripts/mkqtdecl_common/produce.rb | 11 + src/db/db/dbBox.h | 13 - src/db/db/dbCell.h | 11 - src/db/db/dbColdProxy.h | 10 - src/db/db/dbCompoundOperation.h | 13 - src/db/db/dbDeepShapeStore.h | 10 - src/db/db/dbEdge.h | 13 - src/db/db/dbEdgePair.h | 13 - src/db/db/dbEdgePairs.h | 16 - src/db/db/dbEdges.h | 16 - src/db/db/dbHierProcessor.h | 13 - src/db/db/dbLayerProperties.h | 22 - src/db/db/dbLayoutToNetlist.h | 12 - src/db/db/dbLayoutVsSchematic.h | 12 - src/db/db/dbLibrary.h | 10 - src/db/db/dbManager.h | 10 - src/db/db/dbNetlistCompare.h | 18 - src/db/db/dbNetlistCrossReference.h | 11 - src/db/db/dbNetlistDeviceExtractor.h | 12 - src/db/db/dbNetlistDeviceExtractorClasses.h | 59 --- src/db/db/dbNetlistReader.h | 13 - src/db/db/dbNetlistSpiceReader.h | 13 - src/db/db/dbNetlistWriter.h | 13 - src/db/db/dbPCellDeclaration.h | 11 - src/db/db/dbPath.h | 15 - src/db/db/dbPoint.h | 10 - src/db/db/dbPolygon.h | 47 --- src/db/db/dbRegion.h | 16 - src/db/db/dbShapeCollection.h | 12 - src/db/db/dbTechnology.h | 11 - src/db/db/dbText.h | 9 - src/db/db/dbTexts.h | 16 - src/db/db/dbTilingProcessor.h | 10 - src/db/db/dbUserObject.h | 13 - src/db/db/dbVector.h | 9 - src/db/db/gsiDeclDbLayoutDiff.cc | 18 - src/db/db/gsiDeclDbLayoutQuery.cc | 23 -- src/db/db/gsiDeclDbNetlistCompare.cc | 5 - src/db/db/gsiDeclDbNetlistDeviceExtractor.cc | 17 - src/gsi/gsi/gsiClass.h | 380 +++--------------- src/gsi/gsi/gsiDeclBasic.cc | 11 - src/gsi/gsi/gsiDeclInternal.cc | 15 - src/gsi/gsi/gsiDeclTl.cc | 26 -- src/gsi/gsi/gsiTypes.h | 50 +-- src/gsi/gsi_test/gsiTest.h | 12 - src/lay/lay/gsiDeclLayHelpDialog.cc | 12 - src/lay/lay/layApplication.h | 14 - src/lay/lay/layMainWindow.h | 7 - src/laybasic/laybasic/gsiDeclLayDialogs.cc | 23 -- src/laybasic/laybasic/gsiDeclLayLayers.cc | 12 - src/laybasic/laybasic/gsiDeclLayMenu.cc | 12 - .../gsiDeclLayNetlistBrowserDialog.cc | 12 - src/laybasic/laybasic/gsiDeclLayPlugin.cc | 15 - src/laybasic/laybasic/gtf.cc | 9 - src/laybasic/laybasic/layAbstractMenu.h | 17 - src/laybasic/laybasic/layBrowserDialog.h | 11 - src/laybasic/laybasic/layDispatcher.h | 11 - src/laybasic/laybasic/layLayoutView.h | 8 - src/laybasic/laybasic/layMarker.h | 13 - .../laybasic/layNetlistBrowserModel.h | 13 - src/laybasic/laybasic/layPlugin.h | 8 - src/lym/lym/gsiDeclLymMacro.cc | 11 - src/rdb/rdb/rdb.h | 44 -- src/tl/tl/tlList.h | 41 +- src/tl/tl/tlProgress.h | 20 - src/tl/tl/tlRecipe.h | 6 - src/tl/tl/tlReuseVector.h | 47 ++- src/tl/tl/tlString.cc | 15 + src/tl/tl/tlString.h | 31 +- src/tl/tl/tlTypeTraits.h | 84 ++-- src/tl/tl/tlVariantUserClasses.h | 120 +++--- src/tl/tl/tlVector.h | 20 - src/tl/unit_tests/tlExpressionTests.cc | 19 - src/tl/unit_tests/tlListTests.cc | 9 - src/tl/unit_tests/tlReuseVectorTests.cc | 22 +- src/tl/unit_tests/tlVariantTests.cc | 26 -- 76 files changed, 271 insertions(+), 1521 deletions(-) diff --git a/scripts/mkqtdecl_common/produce.rb b/scripts/mkqtdecl_common/produce.rb index 77cc53dac..e2ad911f6 100755 --- a/scripts/mkqtdecl_common/produce.rb +++ b/scripts/mkqtdecl_common/produce.rb @@ -2396,6 +2396,7 @@ END # forward decl @ext_decls << "#{struct.kind.to_s} #{cls};\n\n" + if false # @@@ no longer needed # type traits included ... tt = "namespace tl { template <> struct type_traits<#{cls}> : public type_traits {\n" if !conf.has_copy_ctor?(cls) || is_abstract || (eq_op && eq_op.visibility == :private) @@ -2409,6 +2410,7 @@ END end tt += "}; }\n\n" @ext_decls << tt + end # only for top-level classes external declarations are produced currently @ext_decls << "namespace gsi { GSI_#{modn.upcase}_PUBLIC gsi::Class<#{cls}> &qtdecl_#{clsn} (); }\n\n" @@ -2993,6 +2995,7 @@ END ttfile.puts("#{struct.kind.to_s} #{cls};") end + if false # @@@ no longer needed ttfile.puts("namespace tl {") ttfile.puts "template <> struct type_traits<#{cls}> : public type_traits {" if !conf.has_copy_ctor?(cls) || is_abstract || (eq_op && eq_op.visibility == :private) @@ -3007,9 +3010,11 @@ END ttfile.puts "};" ttfile.puts "}" ttfile.puts "" + end if struct.needs_adaptor(conf) + if false # @@@ no longer needed ttfile.puts("class #{clsn}_Adaptor;") ttfile.puts("namespace tl {") ttfile.puts "template <> struct type_traits<#{clsn}_Adaptor> : public type_traits {" @@ -3022,6 +3027,7 @@ END ttfile.puts "};" ttfile.puts "}" ttfile.puts "" + end end @@ -3075,6 +3081,8 @@ END ttfile.puts("* This file has been created automatically") ttfile.puts("*/") ttfile.puts("") + + if false # @@@ no longer required ttfile.puts("#ifndef _HDR_gsiDecl#{modn}TypeTraits") ttfile.puts("#define _HDR_gsiDecl#{modn}TypeTraits") ttfile.puts("") @@ -3092,6 +3100,7 @@ END elsif decl_obj.is_a?(CPPNamespace) cls = decl_obj.myself + if false # no longer required ttfile.puts("class #{cls}_Namespace;") ttfile.puts("namespace tl {") ttfile.puts "template <> struct type_traits<#{cls}_Namespace> : public type_traits {" @@ -3100,10 +3109,12 @@ END ttfile.puts "};" ttfile.puts("}") ttfile.puts "" + end end end + end ttfile.puts("") ttfile.puts("#endif") diff --git a/src/db/db/dbBox.h b/src/db/db/dbBox.h index c93cfdffc..31502f164 100644 --- a/src/db/db/dbBox.h +++ b/src/db/db/dbBox.h @@ -1423,19 +1423,6 @@ typedef box DBox; namespace tl { - /** - * @brief The type traits for the box type - */ - template - struct type_traits > : public type_traits - { - typedef trivial_relocate_required relocate_requirements; - typedef true_tag supports_extractor; - typedef true_tag supports_to_string; - typedef true_tag has_less_operator; - typedef true_tag has_equal_operator; - }; - template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::Box &b); template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::DBox &b); diff --git a/src/db/db/dbCell.h b/src/db/db/dbCell.h index db7089b2a..eef960a31 100644 --- a/src/db/db/dbCell.h +++ b/src/db/db/dbCell.h @@ -1143,16 +1143,5 @@ mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const } // namespace db -namespace tl -{ - /** - * @brief Type traits - */ - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; -} - #endif diff --git a/src/db/db/dbColdProxy.h b/src/db/db/dbColdProxy.h index a8481f89b..a1273b8c4 100644 --- a/src/db/db/dbColdProxy.h +++ b/src/db/db/dbColdProxy.h @@ -110,16 +110,6 @@ private: } -namespace tl -{ - template <> - struct type_traits : public type_traits - { - typedef tl::false_tag has_default_constructor; - typedef tl::false_tag has_copy_constructor; - }; -} - #endif diff --git a/src/db/db/dbCompoundOperation.h b/src/db/db/dbCompoundOperation.h index 6e59d2d99..fd992e5b0 100644 --- a/src/db/db/dbCompoundOperation.h +++ b/src/db/db/dbCompoundOperation.h @@ -1620,17 +1620,4 @@ private: } -namespace tl -{ - -template <> -struct type_traits - : public tl::type_traits -{ - typedef false_tag has_copy_constructor; - typedef false_tag has_default_constructor; -}; - -} - #endif diff --git a/src/db/db/dbDeepShapeStore.h b/src/db/db/dbDeepShapeStore.h index 877cd2bc9..bac7b4964 100644 --- a/src/db/db/dbDeepShapeStore.h +++ b/src/db/db/dbDeepShapeStore.h @@ -865,15 +865,5 @@ void DeepLayer::commit_shapes (VarCollector &collector, std::map struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - }; - -} - #endif diff --git a/src/db/db/dbEdge.h b/src/db/db/dbEdge.h index 42f907237..da2e29cd7 100644 --- a/src/db/db/dbEdge.h +++ b/src/db/db/dbEdge.h @@ -1500,19 +1500,6 @@ public: namespace tl { - /** - * @brief The type traits for the edge type - */ - template - struct type_traits > : public type_traits - { - typedef trivial_relocate_required relocate_requirements; - typedef true_tag supports_extractor; - typedef true_tag supports_to_string; - typedef true_tag has_less_operator; - typedef true_tag has_equal_operator; - }; - template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::Edge &b); template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::DEdge &b); diff --git a/src/db/db/dbEdgePair.h b/src/db/db/dbEdgePair.h index 0b6209725..6cebdf015 100644 --- a/src/db/db/dbEdgePair.h +++ b/src/db/db/dbEdgePair.h @@ -622,19 +622,6 @@ typedef edge_pair DEdgePair; namespace tl { - /** - * @brief The type traits for the edge type - */ - template - struct type_traits > : public type_traits - { - typedef trivial_relocate_required relocate_requirements; - typedef true_tag supports_extractor; - typedef true_tag supports_to_string; - typedef true_tag has_less_operator; - typedef true_tag has_equal_operator; - }; - template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::EdgePair &b); template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::DEdgePair &b); diff --git a/src/db/db/dbEdgePairs.h b/src/db/db/dbEdgePairs.h index 73a82c40a..9a62bdf0c 100644 --- a/src/db/db/dbEdgePairs.h +++ b/src/db/db/dbEdgePairs.h @@ -613,21 +613,5 @@ private: } -namespace tl -{ - /** - * @brief The type traits for the box type - */ - template <> - struct type_traits : public type_traits - { - typedef true_tag supports_extractor; - typedef true_tag supports_to_string; - typedef true_tag has_less_operator; - typedef true_tag has_equal_operator; - }; - -} - #endif diff --git a/src/db/db/dbEdges.h b/src/db/db/dbEdges.h index a4cb05ae7..b58bca3f4 100644 --- a/src/db/db/dbEdges.h +++ b/src/db/db/dbEdges.h @@ -1210,20 +1210,4 @@ private: } // namespace db -namespace tl -{ - /** - * @brief The type traits for the region type - */ - template <> - struct type_traits : public type_traits - { - typedef true_tag supports_extractor; - typedef true_tag supports_to_string; - typedef true_tag has_less_operator; - typedef true_tag has_equal_operator; - }; - -} - #endif diff --git a/src/db/db/dbHierProcessor.h b/src/db/db/dbHierProcessor.h index c195a10c0..8a4a25f60 100644 --- a/src/db/db/dbHierProcessor.h +++ b/src/db/db/dbHierProcessor.h @@ -532,18 +532,5 @@ private: } -namespace tl -{ - -template -struct type_traits > : public tl::type_traits -{ - // mark "LocalProcessor" as not having a default ctor and no copy ctor - typedef tl::false_tag has_default_constructor; - typedef tl::false_tag has_copy_constructor; -}; - -} - #endif diff --git a/src/db/db/dbLayerProperties.h b/src/db/db/dbLayerProperties.h index c171d0332..8875228f0 100644 --- a/src/db/db/dbLayerProperties.h +++ b/src/db/db/dbLayerProperties.h @@ -229,27 +229,5 @@ inline LayerProperties &operator+= (LayerProperties &props, const LayerOffset &o } -// tl namespace support for db::LayerProperties -namespace tl -{ - template <> - struct type_traits : public type_traits - { - typedef true_tag supports_extractor; - typedef true_tag supports_to_string; - typedef true_tag has_less_operator; - typedef true_tag has_equal_operator; - }; - - template <> - struct type_traits : public type_traits - { - typedef true_tag supports_extractor; - typedef true_tag supports_to_string; - typedef true_tag has_less_operator; - typedef true_tag has_equal_operator; - }; -} - #endif diff --git a/src/db/db/dbLayoutToNetlist.h b/src/db/db/dbLayoutToNetlist.h index 487671783..be6522e9b 100644 --- a/src/db/db/dbLayoutToNetlist.h +++ b/src/db/db/dbLayoutToNetlist.h @@ -1002,16 +1002,4 @@ inline void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int } -namespace tl -{ - -template<> struct type_traits : public tl::type_traits -{ - // mark "NetlistDeviceExtractor" as not having a default ctor and no copy ctor - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -} - #endif diff --git a/src/db/db/dbLayoutVsSchematic.h b/src/db/db/dbLayoutVsSchematic.h index a26b542ea..9c259cfcc 100644 --- a/src/db/db/dbLayoutVsSchematic.h +++ b/src/db/db/dbLayoutVsSchematic.h @@ -172,16 +172,4 @@ private: } -namespace tl -{ - -template<> struct type_traits : public tl::type_traits -{ - // mark "NetlistDeviceExtractor" as not having a default ctor and no copy ctor - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -} - #endif diff --git a/src/db/db/dbLibrary.h b/src/db/db/dbLibrary.h index 408a12fcf..a421adeeb 100644 --- a/src/db/db/dbLibrary.h +++ b/src/db/db/dbLibrary.h @@ -231,16 +231,6 @@ private: } -namespace tl -{ - /** - * @brief Type traits - */ - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - }; -} - #endif diff --git a/src/db/db/dbManager.h b/src/db/db/dbManager.h index 4dd61412b..a389cc46e 100644 --- a/src/db/db/dbManager.h +++ b/src/db/db/dbManager.h @@ -351,15 +351,5 @@ private: } // namespace db -namespace tl -{ - template <> - struct type_traits : public type_traits - { - typedef tl::false_tag has_copy_constructor; - typedef tl::true_tag has_default_constructor; - }; -} - #endif diff --git a/src/db/db/dbNetlistCompare.h b/src/db/db/dbNetlistCompare.h index 90a41131b..e86e6a0da 100644 --- a/src/db/db/dbNetlistCompare.h +++ b/src/db/db/dbNetlistCompare.h @@ -380,22 +380,4 @@ protected: } -namespace tl -{ - -template<> struct type_traits : public tl::type_traits -{ - // mark "NetlistDeviceExtractor" as having a default ctor and no copy ctor - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -template<> struct type_traits : public tl::type_traits -{ - // mark "NetlistDeviceExtractor" as having a default ctor and no copy ctor - typedef tl::false_tag has_copy_constructor; -}; - -} - #endif diff --git a/src/db/db/dbNetlistCrossReference.h b/src/db/db/dbNetlistCrossReference.h index 6b7bcb239..cc3c197b4 100644 --- a/src/db/db/dbNetlistCrossReference.h +++ b/src/db/db/dbNetlistCrossReference.h @@ -312,15 +312,4 @@ private: } -namespace tl -{ - -template<> struct type_traits : public tl::type_traits -{ - // mark "NetlistDeviceExtractor" as having a default ctor and no copy ctor - typedef tl::false_tag has_copy_constructor; -}; - -} - #endif diff --git a/src/db/db/dbNetlistDeviceExtractor.h b/src/db/db/dbNetlistDeviceExtractor.h index 9300586ea..ffbe26bb0 100644 --- a/src/db/db/dbNetlistDeviceExtractor.h +++ b/src/db/db/dbNetlistDeviceExtractor.h @@ -571,16 +571,4 @@ private: } -namespace tl -{ - -template<> struct type_traits : public tl::type_traits -{ - // mark "NetlistDeviceExtractor" as not having a default ctor and no copy ctor - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -} - #endif diff --git a/src/db/db/dbNetlistDeviceExtractorClasses.h b/src/db/db/dbNetlistDeviceExtractorClasses.h index e7338e4dd..180d8f1b7 100644 --- a/src/db/db/dbNetlistDeviceExtractorClasses.h +++ b/src/db/db/dbNetlistDeviceExtractorClasses.h @@ -405,63 +405,4 @@ protected: } -namespace tl -{ - -template<> struct type_traits : public tl::type_traits -{ - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -template<> struct type_traits : public tl::type_traits -{ - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -template<> struct type_traits : public tl::type_traits -{ - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -template<> struct type_traits : public tl::type_traits -{ - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -template<> struct type_traits : public tl::type_traits -{ - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -template<> struct type_traits : public tl::type_traits -{ - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -template<> struct type_traits : public tl::type_traits -{ - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -template<> struct type_traits : public tl::type_traits -{ - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -template<> struct type_traits : public tl::type_traits -{ - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -} - #endif diff --git a/src/db/db/dbNetlistReader.h b/src/db/db/dbNetlistReader.h index a28e5b924..bed469255 100644 --- a/src/db/db/dbNetlistReader.h +++ b/src/db/db/dbNetlistReader.h @@ -52,17 +52,4 @@ public: } -namespace tl -{ - -template <> -struct type_traits - : public tl::type_traits -{ - typedef tl::false_tag has_default_constructor; - typedef tl::false_tag has_copy_constructor; -}; - -} - #endif diff --git a/src/db/db/dbNetlistSpiceReader.h b/src/db/db/dbNetlistSpiceReader.h index 394b45a69..c0ce6d825 100644 --- a/src/db/db/dbNetlistSpiceReader.h +++ b/src/db/db/dbNetlistSpiceReader.h @@ -237,17 +237,4 @@ private: } -namespace tl -{ - -template <> -struct type_traits - : public tl::type_traits -{ - typedef tl::false_tag has_default_constructor; - typedef tl::false_tag has_copy_constructor; -}; - -} - #endif diff --git a/src/db/db/dbNetlistWriter.h b/src/db/db/dbNetlistWriter.h index c6936a900..df1a0edf6 100644 --- a/src/db/db/dbNetlistWriter.h +++ b/src/db/db/dbNetlistWriter.h @@ -52,17 +52,4 @@ public: } -namespace tl -{ - -template <> -struct type_traits - : public tl::type_traits -{ - typedef tl::false_tag has_default_constructor; - typedef tl::false_tag has_copy_constructor; -}; - -} - #endif diff --git a/src/db/db/dbPCellDeclaration.h b/src/db/db/dbPCellDeclaration.h index acd4d12c9..6034afbe2 100644 --- a/src/db/db/dbPCellDeclaration.h +++ b/src/db/db/dbPCellDeclaration.h @@ -535,16 +535,5 @@ private: } -namespace tl -{ - /** - * @brief Type traits - */ - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; -} - #endif diff --git a/src/db/db/dbPath.h b/src/db/db/dbPath.h index 0cd3a4a13..edf6ff981 100644 --- a/src/db/db/dbPath.h +++ b/src/db/db/dbPath.h @@ -224,7 +224,6 @@ public: typedef typename coord_traits::area_type area_type; typedef object_tag< path > tag; typedef tl::vector pointlist_type; - typedef typename tl::type_traits::relocate_requirements relocate_requirements; typedef db::path_point_iterator, db::unit_trans > iterator; /** @@ -1132,20 +1131,6 @@ Path round_path_corners (const Path &input, int rad, int npoints); namespace tl { - /** - * @brief The type traits for the path type - */ - template - struct type_traits > : public type_traits - { - typedef typename db::path::relocate_requirements relocate_requirements; - typedef true_tag has_efficient_swap; - typedef true_tag supports_extractor; - typedef true_tag supports_to_string; - typedef true_tag has_less_operator; - typedef true_tag has_equal_operator; - }; - /** * @brief Special extractors for the paths */ diff --git a/src/db/db/dbPoint.h b/src/db/db/dbPoint.h index 8eef24c08..741c061d3 100644 --- a/src/db/db/dbPoint.h +++ b/src/db/db/dbPoint.h @@ -750,16 +750,6 @@ inline bool equal (const tl::vector > &a, const tl::vector > & namespace tl { - template - struct type_traits > : public type_traits - { - typedef trivial_relocate_required relocate_requirements; - typedef true_tag supports_extractor; - typedef true_tag supports_to_string; - typedef true_tag has_less_operator; - typedef true_tag has_equal_operator; - }; - template <> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::Point &p); template <> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::DPoint &p); diff --git a/src/db/db/dbPolygon.h b/src/db/db/dbPolygon.h index 70d9cd8f2..275ca67b1 100644 --- a/src/db/db/dbPolygon.h +++ b/src/db/db/dbPolygon.h @@ -1045,24 +1045,6 @@ private: } -namespace tl -{ - /** - * @brief The type traits for the contour type - */ - template - struct type_traits > : public type_traits - { - // the contour just uses one pointer, hence the relocation requirements are simple - typedef typename tl::trivial_relocate_required relocate_requirements; - typedef true_tag has_efficient_swap; - typedef false_tag supports_extractor; - typedef false_tag supports_to_string; - typedef true_tag has_less_operator; - typedef true_tag has_equal_operator; - }; -} - namespace db { @@ -1437,7 +1419,6 @@ public: typedef typename coord_traits::area_type area_type; typedef polygon_contour contour_type; typedef tl::vector contour_list_type; - typedef typename tl::type_traits::relocate_requirements relocate_requirements; typedef db::polygon_edge_iterator< polygon, db::unit_trans > polygon_edge_iterator; typedef db::polygon_contour_iterator< contour_type, db::unit_trans > polygon_contour_iterator; typedef db::object_tag< polygon > tag; @@ -2439,7 +2420,6 @@ public: typedef typename coord_traits::area_type area_type; typedef polygon_contour contour_type; typedef tl::vector contour_list_type; - typedef typename tl::type_traits::relocate_requirements relocate_requirements; typedef db::polygon_edge_iterator< simple_polygon, db::unit_trans > polygon_edge_iterator; typedef db::polygon_contour_iterator< contour_type, db::unit_trans > polygon_contour_iterator; typedef db::object_tag< simple_polygon > tag; @@ -3568,33 +3548,6 @@ void swap (db::simple_polygon &a, db::simple_polygon &b) namespace tl { - /** - * @brief The type traits for the polygon type - */ - template - struct type_traits > : public type_traits - { - typedef typename db::polygon::relocate_requirements relocate_requirements; - typedef true_tag has_efficient_swap; - typedef true_tag supports_extractor; - typedef true_tag supports_to_string; - typedef true_tag has_less_operator; - typedef true_tag has_equal_operator; - }; - - /** - * @brief The type traits for the simple_polygon type - */ - template - struct type_traits > : public type_traits - { - typedef typename db::simple_polygon::relocate_requirements relocate_requirements; - typedef true_tag supports_extractor; - typedef true_tag supports_to_string; - typedef true_tag has_less_operator; - typedef true_tag has_equal_operator; - }; - /** * @brief Special extractors for the polygons */ diff --git a/src/db/db/dbRegion.h b/src/db/db/dbRegion.h index 9c77722d5..1698f264c 100644 --- a/src/db/db/dbRegion.h +++ b/src/db/db/dbRegion.h @@ -1821,21 +1821,5 @@ private: } // namespace db -namespace tl -{ - /** - * @brief The type traits for the region type - */ - template <> - struct type_traits : public type_traits - { - typedef true_tag supports_extractor; - typedef true_tag supports_to_string; - typedef true_tag has_less_operator; - typedef true_tag has_equal_operator; - }; - -} - #endif diff --git a/src/db/db/dbShapeCollection.h b/src/db/db/dbShapeCollection.h index b5d228922..bec5a6663 100644 --- a/src/db/db/dbShapeCollection.h +++ b/src/db/db/dbShapeCollection.h @@ -100,16 +100,4 @@ public: } -namespace tl -{ - -template<> struct type_traits : public tl::type_traits -{ - // mark "NetlistDeviceExtractor" as having a default ctor and no copy ctor - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -} - #endif diff --git a/src/db/db/dbTechnology.h b/src/db/db/dbTechnology.h index 7be8d663f..050decc7c 100644 --- a/src/db/db/dbTechnology.h +++ b/src/db/db/dbTechnology.h @@ -874,16 +874,5 @@ public: } -namespace tl -{ - /** - * @brief Type traits - */ - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_default_constructor; - typedef tl::false_tag has_copy_constructor; - }; -} - #endif diff --git a/src/db/db/dbText.h b/src/db/db/dbText.h index 5d11d9511..47fd1e64f 100644 --- a/src/db/db/dbText.h +++ b/src/db/db/dbText.h @@ -1125,15 +1125,6 @@ inline void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int namespace tl { - template - struct type_traits > : public type_traits - { - typedef true_tag supports_extractor; - typedef true_tag supports_to_string; - typedef true_tag has_less_operator; - typedef true_tag has_equal_operator; - }; - template<> void DB_PUBLIC extractor_impl (tl::Extractor &ex, db::Text &p); template<> void DB_PUBLIC extractor_impl (tl::Extractor &ex, db::DText &p); diff --git a/src/db/db/dbTexts.h b/src/db/db/dbTexts.h index c5cf5eec3..26e678641 100644 --- a/src/db/db/dbTexts.h +++ b/src/db/db/dbTexts.h @@ -618,21 +618,5 @@ private: } -namespace tl -{ - /** - * @brief The type traits for the box type - */ - template <> - struct type_traits : public type_traits - { - typedef true_tag supports_extractor; - typedef true_tag supports_to_string; - typedef true_tag has_less_operator; - typedef true_tag has_equal_operator; - }; - -} - #endif diff --git a/src/db/db/dbTilingProcessor.h b/src/db/db/dbTilingProcessor.h index 406ff6526..29f39aa90 100644 --- a/src/db/db/dbTilingProcessor.h +++ b/src/db/db/dbTilingProcessor.h @@ -703,15 +703,5 @@ private: } -namespace tl -{ - template <> - struct type_traits : public type_traits - { - typedef tl::true_tag has_default_constructor; - typedef tl::false_tag has_copy_constructor; - }; -} - #endif diff --git a/src/db/db/dbUserObject.h b/src/db/db/dbUserObject.h index f9a3c0b92..c3eb90b13 100644 --- a/src/db/db/dbUserObject.h +++ b/src/db/db/dbUserObject.h @@ -520,19 +520,6 @@ typedef tl::RegisteredClass > DUserObjectDe } // namespace db -namespace tl -{ - /** - * @brief The type traits for the user object type - */ - template - struct type_traits > : public type_traits - { - typedef trivial_relocate_required relocate_requirements; - typedef true_tag has_efficient_swap; - }; -} - // inject a swap specialization into the std namespace: namespace std { diff --git a/src/db/db/dbVector.h b/src/db/db/dbVector.h index 642e523b9..34e079c1f 100644 --- a/src/db/db/dbVector.h +++ b/src/db/db/dbVector.h @@ -713,15 +713,6 @@ struct from_double_vector namespace tl { - template - struct type_traits > : public type_traits - { - typedef true_tag supports_extractor; - typedef true_tag supports_to_string; - typedef true_tag has_less_operator; - typedef true_tag has_equal_operator; - }; - template <> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::Vector &p); template <> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::DVector &p); diff --git a/src/db/db/gsiDeclDbLayoutDiff.cc b/src/db/db/gsiDeclDbLayoutDiff.cc index b0dd486fd..fb9ad68c0 100644 --- a/src/db/db/gsiDeclDbLayoutDiff.cc +++ b/src/db/db/gsiDeclDbLayoutDiff.cc @@ -369,24 +369,6 @@ private: int m_layer_index_b; }; -} - -namespace tl -{ - -// Disable copy and default ctor for layout query -template <> -struct type_traits - : public type_traits -{ - typedef false_tag has_copy_constructor; -}; - -} - -namespace gsi -{ - static unsigned int f_silent () { return db::layout_diff::f_silent; } diff --git a/src/db/db/gsiDeclDbLayoutQuery.cc b/src/db/db/gsiDeclDbLayoutQuery.cc index 7b03b5757..031aa5a78 100644 --- a/src/db/db/gsiDeclDbLayoutQuery.cc +++ b/src/db/db/gsiDeclDbLayoutQuery.cc @@ -24,29 +24,6 @@ #include "gsiDecl.h" #include "dbLayoutQuery.h" -namespace tl -{ - -// Disable copy and default ctor for layout query -template <> -struct type_traits - : public type_traits -{ - typedef false_tag has_copy_constructor; - typedef false_tag has_default_constructor; -}; - -// Disable copy and default ctor for layout query -template <> -struct type_traits - : public type_traits -{ - typedef false_tag has_copy_constructor; - typedef false_tag has_default_constructor; -}; - -} - namespace gsi { diff --git a/src/db/db/gsiDeclDbNetlistCompare.cc b/src/db/db/gsiDeclDbNetlistCompare.cc index 5a0696ee6..8c167d92b 100644 --- a/src/db/db/gsiDeclDbNetlistCompare.cc +++ b/src/db/db/gsiDeclDbNetlistCompare.cc @@ -316,11 +316,6 @@ private: } -namespace tl -{ - template<> struct type_traits : public tl::type_traits { }; -} - namespace gsi { diff --git a/src/db/db/gsiDeclDbNetlistDeviceExtractor.cc b/src/db/db/gsiDeclDbNetlistDeviceExtractor.cc index 6112967b9..d2c219acb 100644 --- a/src/db/db/gsiDeclDbNetlistDeviceExtractor.cc +++ b/src/db/db/gsiDeclDbNetlistDeviceExtractor.cc @@ -93,23 +93,6 @@ public: gsi::Callback cb_extract_devices; }; -} - -namespace tl -{ - -template<> struct type_traits : public tl::type_traits -{ - // mark "NetlistDeviceExtractor" as having a default ctor and no copy ctor - typedef tl::false_tag has_copy_constructor; - typedef tl::true_tag has_default_constructor; -}; - -} - -namespace gsi -{ - namespace { diff --git a/src/gsi/gsi/gsiClass.h b/src/gsi/gsi/gsiClass.h index 84eaf7edd..4d22179a2 100644 --- a/src/gsi/gsi/gsiClass.h +++ b/src/gsi/gsi/gsiClass.h @@ -44,74 +44,53 @@ namespace gsi /** * @brief A helper function to implement equal as efficiently as possible */ -template -bool _var_user_equal_impl (const T *a, const T *b, const VariantUserClassImpl *delegate, I); +template struct _var_user_equal_impl; template -bool _var_user_equal_impl (const T *a, const T *b, const VariantUserClassImpl * /*delegate*/, tl::true_tag) +struct _var_user_equal_impl { - return *a == *b; -} + static bool call (const T *a, const T *b, const VariantUserClassImpl * /*delegate*/) { return *a == *b; } +}; template -bool _var_user_equal_impl (const T *a, const T *b, const VariantUserClassImpl *delegate, tl::false_tag) +struct _var_user_equal_impl { - return delegate->equal_impl ((void *) a, (void *) b); -} + static bool call (const T *a, const T *b, const VariantUserClassImpl *delegate) { return delegate->equal_impl ((void *) a, (void *) b); } +}; /** - * @brief A helper function to implement less as efficiently as possible + * @brief A helper function to implement equal as efficiently as possible */ -template -bool _var_user_less_impl (const T *a, const T *b, const VariantUserClassImpl *delegate, I); +template struct _var_user_less_impl; template -bool _var_user_less_impl (const T *a, const T *b, const VariantUserClassImpl * /*delegate*/, tl::true_tag) +struct _var_user_less_impl { - return *a < *b; -} + static bool call (const T *a, const T *b, const VariantUserClassImpl * /*delegate*/) { return *a < *b; } +}; template -bool _var_user_less_impl (const T *a, const T *b, const VariantUserClassImpl *delegate, tl::false_tag) +struct _var_user_less_impl { - return delegate->less_impl ((void *) a, (void *) b); -} + static bool call (const T *a, const T *b, const VariantUserClassImpl *delegate) { return delegate->less_impl ((void *) a, (void *) b); } +}; /** - * @brief A helper function to implement to_string as efficiently as possible + * @brief A helper function to implement equal as efficiently as possible */ -template -std::string _var_user_to_string_impl (const T *a, const VariantUserClassImpl *delegate, I); +template struct _var_user_to_string_impl; template -std::string _var_user_to_string_impl (const T *a, const VariantUserClassImpl * /*delegate*/, tl::true_tag) +struct _var_user_to_string_impl { - return a->to_string (); -} + static std::string call (const T *a, const VariantUserClassImpl * /*delegate*/) { return a->to_string (); } +}; template -std::string _var_user_to_string_impl (const T *a, const VariantUserClassImpl *delegate, tl::false_tag) +struct _var_user_to_string_impl { - return delegate->to_string_impl ((void *) a); -} - -/** - * @brief A helper function to implement read as efficiently as possible - */ -template -void _var_user_read_impl (T *a, tl::Extractor &ex, I); - -template -void _var_user_read_impl (T *a, tl::Extractor &ex, tl::true_tag) -{ - ex.read (*a); -} - -template -void _var_user_read_impl (T * /*a*/, tl::Extractor & /*ex*/, tl::false_tag) -{ - tl_assert (false); -} + static std::string call (const T *a, const VariantUserClassImpl *delegate) { return delegate->to_string_impl ((void *) a); } +}; /** * @brief A VariantUserClassBase specialization that links GSI classes and Variant classes @@ -165,20 +144,17 @@ public: virtual bool equal (const void *a, const void *b) const { - typename tl::type_traits::has_equal_operator f; - return gsi::_var_user_equal_impl ((const T *) a, (const T *) b, this, f); + return gsi::_var_user_equal_impl::value>::call ((const T *) a, (const T *) b, this); } virtual bool less (const void *a, const void *b) const { - typename tl::type_traits::has_less_operator f; - return gsi::_var_user_less_impl ((const T *) a, (const T *) b, this, f); + return gsi::_var_user_less_impl::value>::call ((const T *) a, (const T *) b, this); } virtual std::string to_string (const void *a) const { - typename tl::type_traits::supports_to_string f; - return gsi::_var_user_to_string_impl ((const T *) a, this, f); + return gsi::_var_user_to_string_impl::value>::call ((const T *) a, this); } void *clone (const void *obj) const @@ -212,8 +188,8 @@ public: void read (void *a, tl::Extractor &ex) const { - typename tl::type_traits::supports_extractor f; - gsi::_var_user_read_impl ((T *) a, ex, f); + const T *t = a; + ex.read (*t); } const gsi::ClassBase *gsi_cls () const @@ -244,256 +220,21 @@ private: // ----------------------------------------------------------------------------- // GSI implementation -template -void *_get_vector_of (SerialArgs & /*from*/, const ArgType & /*a*/, void * /*data*/, void (* /*cb*/) (void * /*data*/, void * /*obj*/), tl::false_tag /*has_copy_ctor*/) -{ - tl_assert (false); // cannot copy object of this type - return 0; -} +template struct _destroy; +template struct _destroy { static void call (X *) { tl_assert (false); } }; +template struct _destroy { static void call (X *x) { delete x; } }; -template -void _get_vector_of (SerialArgs &from, const ArgType &a, void *data, void (*cb) (void *data, void *obj), tl::true_tag /*has_copy_ctor*/) -{ - std::vector vv; - const std::vector *v = &vv; - if (a.is_cref ()) { - v = &from.template read &> (); - } else if (a.is_cptr ()) { - v = from.template read *> (); - } else if (a.is_ref ()) { - v = &from.template read &> (); - } else if (a.is_ptr ()) { - v = from.template read *> (); - } else { - vv = from.template read< std::vector > (); - } - for (typename std::vector::const_iterator o = v->begin (); o != v->end (); ++o) { - (*cb) (data, new X (*o)); - } -} +template struct _create; +template struct _create { static void *call () { throw tl::Exception (tl::to_string (tr ("Object cannot be created here"))); } }; +template struct _create { static void *call () { return new X (); } }; -template -void _get_cptr_vector_of (SerialArgs &from, const ArgType &a, void *data, void (*cb) (void *data, void *obj)) -{ - std::vector vv; - const std::vector *v = &vv; - if (a.is_cref ()) { - v = &from.template read &> (); - } else if (a.is_cptr ()) { - v = from.template read *> (); - } else if (a.is_ref ()) { - v = &from.template read &> (); - } else if (a.is_ptr ()) { - v = from.template read *> (); - } else { - vv = from.template read< std::vector > (); - } - for (typename std::vector::const_iterator o = v->begin (); o != v->end (); ++o) { - (*cb) (data, (void *) *o); - } -} +template struct _clone; +template struct _clone { static void *call (const void *) { throw tl::Exception (tl::to_string (tr ("Object cannot be copied here"))); } }; +template struct _clone { static void *call (const void *other) { new X (*(const X *)other); } }; -template -void _get_ptr_vector_of (SerialArgs &from, const ArgType &a, void *data, void (*cb) (void *data, void *obj)) -{ - std::vector vv; - const std::vector *v = &vv; - if (a.is_cref ()) { - v = &from.template read &> (); - } else if (a.is_cptr ()) { - v = from.template read *> (); - } else if (a.is_ref ()) { - v = &from.template read &> (); - } else if (a.is_ptr ()) { - v = from.template read *> (); - } else { - vv = from.template read< std::vector > (); - } - for (typename std::vector::const_iterator o = v->begin (); o != v->end (); ++o) { - (*cb) (data, *o); - } -} - -template -void _destroy (X *, tl::false_tag /*has public dtor*/) -{ - tl_assert (false); // cannot delete object of this type -} - -template -void _destroy (X *x, tl::true_tag /*has public dtor*/) -{ - delete x; -} - -template -void _push_vector_of (SerialArgs & /*to*/, const ArgType & /*a*/, tl::Heap & /*heap*/, const std::vector & /*objects*/, tl::false_tag /*has_copy_ctor*/) -{ - tl_assert (false); // cannot copy object of this type -} - -template -void _push_vector_of (SerialArgs &to, const ArgType &a, tl::Heap &heap, const std::vector &objects, tl::true_tag /*has_copy_ctor*/) -{ - tl_assert (a.inner () != 0); - - std::vector vv; - std::vector *v; - if (a.is_ref () || a.is_cref () || a.is_ptr () || a.is_cptr ()) { - v = new std::vector (); - heap.push (v); - } else { - v = &vv; - } - - v->reserve (objects.size ()); - for (std::vector::const_iterator o = objects.begin (); o != objects.end (); ++o) { - v->push_back (*(X *)*o); - } - - if (a.is_cref ()) { - to.write &> (*v); - } else if (a.is_cptr ()) { - to.write *> (v); - } else if (a.is_ref ()) { - to.write &> (*v); - } else if (a.is_ptr ()) { - to.write *> (v); - } else { - to.write > (vv); - } -} - -template -void _push_cptr_vector_of (SerialArgs &to, const ArgType &a, tl::Heap &heap, const std::vector &objects) -{ - tl_assert (a.inner () != 0); - - std::vector vv; - std::vector *v; - if (a.is_ref () || a.is_cref () || a.is_ptr () || a.is_cptr ()) { - v = new std::vector (); - heap.push (v); - } else { - v = &vv; - } - - v->reserve (objects.size ()); - for (std::vector::const_iterator o = objects.begin (); o != objects.end (); ++o) { - v->push_back ((const X *)*o); - } - - if (a.is_cref ()) { - to.write &> (*v); - } else if (a.is_cptr ()) { - to.write *> (v); - } else if (a.is_ref ()) { - to.write &> (*v); - } else if (a.is_ptr ()) { - to.write *> (v); - } else { - to.write > (vv); - } -} - -template -void _push_ptr_vector_of (SerialArgs &to, const ArgType &a, tl::Heap &heap, const std::vector &objects) -{ - tl_assert (a.inner () != 0); - - std::vector vv; - std::vector *v; - if (a.is_ref () || a.is_cref () || a.is_ptr () || a.is_cptr ()) { - v = new std::vector (); - heap.push (v); - } else { - v = &vv; - } - - v->reserve (objects.size ()); - for (std::vector::const_iterator o = objects.begin (); o != objects.end (); ++o) { - v->push_back ((X *)*o); - } - - if (a.is_cref ()) { - to.write &> (*v); - } else if (a.is_cptr ()) { - to.write *> (v); - } else if (a.is_ref ()) { - to.write &> (*v); - } else if (a.is_ptr ()) { - to.write *> (v); - } else { - to.write > (vv); - } -} - -template -void *_create (tl::false_tag) -{ - throw tl::Exception (tl::to_string (tr ("Object cannot be created here"))); - return 0; -} - -template -void *_create (tl::true_tag) -{ - return new X (); -} - -template -void *_clone (tl::false_tag, const void * /*other*/) -{ - throw tl::Exception (tl::to_string (tr ("Object cannot be copied here"))); - return 0; -} - -template -void *_clone (tl::true_tag, const void *other) -{ - return new X (*(const X *)other); -} - -template -void _assign (tl::false_tag /*has_copy_ctor*/, void *, const void *) -{ - throw tl::Exception (tl::to_string (tr ("Object cannot be copied here"))); -} - -template -void _assign (tl::true_tag /*has_copy_ctor*/, void *dest, const void *src) -{ - *(X *)dest = *(const X *)src; -} - -/** - * @brief A class predicate telling us whether X is polymorphic - * - * The trick was taken from boost - if a class is made polymorphic and it - * has not been before, the size of the object changes since a virtual - * function table will be added. - */ -template -struct is_polymorphic -{ -private: - struct P1 : public X - { - P1 (); - ~P1 (); - int something; - }; - - struct P2 : public X - { - P2 (); - virtual ~P2 (); - int something; - }; - -public: - typedef typename tl::boolean_value::value value; -}; +template struct _assign; +template struct _assign { static void call (void *, const void *) { throw tl::Exception (tl::to_string (tr ("Object cannot be copied here"))); } }; +template struct _assign { static void call (void *dest, const void *src) { *(X *)dest = *(const X *)src; } }; /** * @brief A helper class which tests whether a given object can be upcast @@ -513,14 +254,14 @@ public: * The can_upcast method will return true, if the object (which has at least to * be of type B) can be upcast to X. */ -template +template class SubClassTester; /** * @brief Specialization for polymorphic types - we can use dynamic_cast to tests whether B object can be cast to X */ template -class SubClassTester +class SubClassTester : public SubClassTesterBase { public: @@ -534,7 +275,7 @@ public: * @brief Specialization for non-polymorphic types */ template -class SubClassTester +class SubClassTester : public SubClassTesterBase { public: @@ -556,10 +297,6 @@ class GSI_PUBLIC_TEMPLATE ClassExt : public ClassBase { public: - typedef typename tl::type_traits::has_copy_constructor has_copy_ctor; - typedef typename tl::type_traits::has_default_constructor has_default_ctor; - typedef typename tl::type_traits::has_public_destructor has_public_dtor; - ClassExt (const Methods &mm, const std::string &doc = std::string ()) : ClassBase (doc, mm), mp_declaration (0) { @@ -713,10 +450,6 @@ class GSI_PUBLIC_TEMPLATE Class : public ClassBase { public: - typedef typename tl::type_traits::has_copy_constructor has_copy_ctor; - typedef typename tl::type_traits::has_default_constructor has_default_ctor; - typedef typename tl::type_traits::has_public_destructor has_public_dtor; - Class (const std::string &module, const std::string &name, const Methods &mm, const std::string &doc = std::string (), bool do_register = true) : ClassBase (doc, mm, do_register) { @@ -726,7 +459,7 @@ public: template Class (const Class &base, const std::string &module, const std::string &name, const Methods &mm, const std::string &doc = std::string (), bool do_register = true) - : ClassBase (doc, mm, do_register), m_subclass_tester (new SubClassTester::value> ()) + : ClassBase (doc, mm, do_register), m_subclass_tester (new SubClassTester::value> ()) { set_module (module); set_name (name); @@ -742,7 +475,7 @@ public: template Class (const Class &base, const std::string &module, const std::string &name, const std::string &doc = std::string (), bool do_register = true) - : ClassBase (doc, Methods (), do_register), m_subclass_tester (new SubClassTester::value> ()) + : ClassBase (doc, Methods (), do_register), m_subclass_tester (new SubClassTester::value> ()) { set_module (module); set_name (name); @@ -785,15 +518,12 @@ public: virtual void destroy (void *p) const { X *x = (X *)p; - has_public_dtor hpd; - _destroy (x, hpd); + _destroy::value>::call (x); } virtual void *create () const { - has_default_ctor cst; - void *r = _create (cst); - return r; + return _create::value>::call (); } virtual void *create_from_adapted (const void *x) const @@ -818,33 +548,27 @@ public: virtual void *clone (const void *other) const { - has_copy_ctor cst; - void *r = _clone (cst, other); - return r; + return _clone::value>::call (other); } virtual void assign (void *dest, const void *src) const { - has_copy_ctor cst; - _assign (cst, dest, src); + _assign::value>::call (dest, src); } virtual bool can_destroy () const { - has_public_dtor hpd; - return tl::value_of (hpd); + return std::is_destructible::value; } virtual bool can_copy () const { - has_copy_ctor cpt; - return tl::value_of (cpt); + return std::is_copy_constructible::value; } virtual bool can_default_create () const { - has_default_ctor cpt; - return tl::value_of (cpt); + return std::is_default_constructible::value; } virtual const ClassBase *subclass_decl (const void *p) const diff --git a/src/gsi/gsi/gsiDeclBasic.cc b/src/gsi/gsi/gsiDeclBasic.cc index dc43160c0..c35202595 100644 --- a/src/gsi/gsi/gsiDeclBasic.cc +++ b/src/gsi/gsi/gsiDeclBasic.cc @@ -26,17 +26,6 @@ #include "gsiDecl.h" #include "tlTypeTraits.h" -namespace tl -{ - template <> struct type_traits - : tl::type_traits - { - typedef false_tag has_copy_constructor; - typedef false_tag has_default_constructor; - typedef false_tag has_public_destructor; - }; -} - namespace gsi { diff --git a/src/gsi/gsi/gsiDeclInternal.cc b/src/gsi/gsi/gsiDeclInternal.cc index 06f5faba5..ccd5861ee 100644 --- a/src/gsi/gsi/gsiDeclInternal.cc +++ b/src/gsi/gsi/gsiDeclInternal.cc @@ -23,21 +23,6 @@ #include "gsiDecl.h" -namespace tl -{ - -template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -} - namespace gsi { diff --git a/src/gsi/gsi/gsiDeclTl.cc b/src/gsi/gsi/gsiDeclTl.cc index 401458d24..d11eed55f 100644 --- a/src/gsi/gsi/gsiDeclTl.cc +++ b/src/gsi/gsi/gsiDeclTl.cc @@ -77,18 +77,6 @@ public: } }; -} - -namespace tl { - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; -} - -namespace gsi -{ - Class decl_Logger ("tl", "Logger", gsi::method ("info", &Logger::info, gsi::arg ("msg"), "@brief Writes the given string to the info channel\n" @@ -488,20 +476,6 @@ static ExpressionWrapper *new_expr2 (const std::string &e, const std::map struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::true_tag has_default_constructor; - }; - -} - -namespace gsi -{ - Class decl_ExpressionContext ("tl", "ExpressionContext", gsi::method ("var", &tl::Eval::set_var, gsi::arg ("name"), gsi::arg ("value"), "@brief Defines a variable with the given name and value\n" diff --git a/src/gsi/gsi/gsiTypes.h b/src/gsi/gsi/gsiTypes.h index 4f4561874..1cfde544b 100644 --- a/src/gsi/gsi/gsiTypes.h +++ b/src/gsi/gsi/gsiTypes.h @@ -1144,7 +1144,7 @@ public: /** * @brief An implementation helper that provides a switch between classes having and having no copy ctor */ -template +template class ArgSpecImpl : public ArgSpecBase { @@ -1189,7 +1189,7 @@ public: * @brief A specialization for classes with default and copy ctor */ template -class ArgSpecImpl +class ArgSpecImpl : public ArgSpecBase { public: @@ -1289,30 +1289,30 @@ private: */ template class ArgSpec - : public ArgSpecImpl::has_copy_constructor> + : public ArgSpecImpl::value && std::is_destructible::value> { public: - typedef typename tl::type_traits::has_copy_constructor cc_type; + typedef ArgSpecImpl::value && std::is_destructible::value> Base; ArgSpec () - : ArgSpecImpl () + : Base () { } ArgSpec (const ArgSpec &other) - : ArgSpecImpl (other) + : Base (other) { } template ArgSpec (const ArgSpec &other) - : ArgSpecImpl (other) + : Base (other) { } ArgSpec (const std::string &name) - : ArgSpecImpl (name) + : Base (name) { } ArgSpec (const std::string &name, const T &init, const std::string &init_doc = std::string ()) - : ArgSpecImpl (name, init, init_doc) + : Base (name, init, init_doc) { } virtual ArgSpecBase *clone () const @@ -1326,30 +1326,30 @@ public: */ template class ArgSpec - : public ArgSpecImpl::has_copy_constructor> + : public ArgSpecImpl::value && std::is_destructible::value> { public: - typedef typename tl::type_traits::has_copy_constructor cc_type; + typedef ArgSpecImpl::value && std::is_destructible::value> Base; - ArgSpec () - : ArgSpecImpl () + ArgSpec () + : Base () { } ArgSpec (const ArgSpec &other) - : ArgSpecImpl (other) + : Base (other) { } template ArgSpec (const ArgSpec &other) - : ArgSpecImpl (other) + : Base (other) { } ArgSpec (const std::string &name) - : ArgSpecImpl (name) + : Base (name) { } ArgSpec (const std::string &name, const T &init, const std::string &init_doc = std::string ()) - : ArgSpecImpl (name, init, init_doc) + : Base (name, init, init_doc) { } virtual ArgSpecBase *clone () const @@ -1363,37 +1363,37 @@ public: */ template class ArgSpec - : public ArgSpecImpl::has_copy_constructor> + : public ArgSpecImpl::value && std::is_destructible::value> { public: + typedef ArgSpecImpl::value && std::is_destructible::value> Base; typedef T &init_type; - typedef typename tl::type_traits::has_copy_constructor cc_type; ArgSpec () - : ArgSpecImpl () + : Base () { } ArgSpec (const ArgSpec &other) - : ArgSpecImpl (other) + : Base (other) { } template ArgSpec (const ArgSpec &other) - : ArgSpecImpl (other) + : Base (other) { } ArgSpec (const std::string &name) - : ArgSpecImpl (name) + : Base (name) { } ArgSpec (const std::string &name, const T &init, const std::string &init_doc = std::string ()) - : ArgSpecImpl (name, init, init_doc) + : Base (name, init, init_doc) { } T &init () const { // this simplifies the implementation, but it's not really clean since the caller may modify the default. - return const_cast (ArgSpecImpl::init ()); + return const_cast (ArgSpecImpl::value>::init ()); } virtual ArgSpecBase *clone () const diff --git a/src/gsi/gsi_test/gsiTest.h b/src/gsi/gsi_test/gsiTest.h index 6869f2632..57d6efb95 100644 --- a/src/gsi/gsi_test/gsiTest.h +++ b/src/gsi/gsi_test/gsiTest.h @@ -1273,17 +1273,5 @@ private: } -namespace tl -{ - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - }; -#if defined(HAVE_QT) - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - }; -#endif -} - #endif diff --git a/src/lay/lay/gsiDeclLayHelpDialog.cc b/src/lay/lay/gsiDeclLayHelpDialog.cc index 1cb6fb7f1..3d4d81dce 100644 --- a/src/lay/lay/gsiDeclLayHelpDialog.cc +++ b/src/lay/lay/gsiDeclLayHelpDialog.cc @@ -34,18 +34,6 @@ # define QT_EXTERNAL_BASE(x) #endif -namespace tl -{ - -// type traits for HelpDialog -template <> -struct type_traits : public type_traits { - typedef tl::false_tag has_default_constructor; - typedef tl::false_tag has_copy_constructor; -}; - -} - namespace gsi { diff --git a/src/lay/lay/layApplication.h b/src/lay/lay/layApplication.h index b7ee616e2..d370c10ab 100644 --- a/src/lay/lay/layApplication.h +++ b/src/lay/lay/layApplication.h @@ -494,20 +494,6 @@ private: } // namespace lay -namespace tl { - - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; - - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; - -} - #endif diff --git a/src/lay/lay/layMainWindow.h b/src/lay/lay/layMainWindow.h index cb2f2246d..c7f76b5f3 100644 --- a/src/lay/lay/layMainWindow.h +++ b/src/lay/lay/layMainWindow.h @@ -833,11 +833,4 @@ private: } -namespace tl { - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; -} - #endif diff --git a/src/laybasic/laybasic/gsiDeclLayDialogs.cc b/src/laybasic/laybasic/gsiDeclLayDialogs.cc index d802ee01b..4df8a4ebf 100644 --- a/src/laybasic/laybasic/gsiDeclLayDialogs.cc +++ b/src/laybasic/laybasic/gsiDeclLayDialogs.cc @@ -92,29 +92,6 @@ public: gsi::Callback get_cb; }; -} - -namespace tl -{ - -// type traits for BrowserDialog_Stub -template <> -struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; -}; - -// type traits for BrowserPanel -template <> -struct type_traits : public type_traits { - typedef tl::false_tag has_default_constructor; - typedef tl::false_tag has_copy_constructor; -}; - -} - -namespace gsi -{ - // --------------------------------------------------------------------------------- // Value classes with "not set" capabilities diff --git a/src/laybasic/laybasic/gsiDeclLayLayers.cc b/src/laybasic/laybasic/gsiDeclLayLayers.cc index 75fd91eac..1b8062f30 100644 --- a/src/laybasic/laybasic/gsiDeclLayLayers.cc +++ b/src/laybasic/laybasic/gsiDeclLayLayers.cc @@ -24,18 +24,6 @@ #include "gsiDecl.h" #include "layLayoutView.h" -namespace tl -{ - // NOTE: we don't want references to be passed around and be default-constructed. - // References are only meant as return values for the layer properties iterator and - // be short-living. Hence we disable copying (which will also disable the default - // "assign" implementation) and default construction. - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; -} - namespace gsi { diff --git a/src/laybasic/laybasic/gsiDeclLayMenu.cc b/src/laybasic/laybasic/gsiDeclLayMenu.cc index 130f2f632..fab175924 100644 --- a/src/laybasic/laybasic/gsiDeclLayMenu.cc +++ b/src/laybasic/laybasic/gsiDeclLayMenu.cc @@ -44,18 +44,6 @@ public: tl::Event on_triggered_event; }; -} - -namespace tl -{ - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - }; -} - -namespace gsi -{ - static std::string pack_key_binding (const std::map &kb) { std::vector > v; diff --git a/src/laybasic/laybasic/gsiDeclLayNetlistBrowserDialog.cc b/src/laybasic/laybasic/gsiDeclLayNetlistBrowserDialog.cc index a7f05d9d6..ef261e1fb 100644 --- a/src/laybasic/laybasic/gsiDeclLayNetlistBrowserDialog.cc +++ b/src/laybasic/laybasic/gsiDeclLayNetlistBrowserDialog.cc @@ -27,18 +27,6 @@ #include "layNetlistBrowserDialog.h" #include "layLayoutView.h" -namespace tl -{ - -// disable copy and default constructor for NetlistBrowserDialog -template <> struct type_traits : public type_traits -{ - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -} - namespace gsi { diff --git a/src/laybasic/laybasic/gsiDeclLayPlugin.cc b/src/laybasic/laybasic/gsiDeclLayPlugin.cc index 5a7345f5b..28fde26ec 100644 --- a/src/laybasic/laybasic/gsiDeclLayPlugin.cc +++ b/src/laybasic/laybasic/gsiDeclLayPlugin.cc @@ -32,21 +32,6 @@ namespace gsi { class PluginFactoryBase; class PluginBase; -} - -namespace tl -{ - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - }; - - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - }; -} - -namespace gsi -{ // TODO: these static variables are a bad hack! // However it's not easy to pass parameters to a C++ classes constructor in Ruby without diff --git a/src/laybasic/laybasic/gtf.cc b/src/laybasic/laybasic/gtf.cc index 255384609..60c647b07 100644 --- a/src/laybasic/laybasic/gtf.cc +++ b/src/laybasic/laybasic/gtf.cc @@ -63,15 +63,6 @@ // -------------------------------------------------------------- // A helper class that allows putting a QImage into a tl::Variant -namespace tl -{ - template <> - struct type_traits : public type_traits - { - typedef true_tag has_equal_operator; - }; -} - namespace gtf { diff --git a/src/laybasic/laybasic/layAbstractMenu.h b/src/laybasic/laybasic/layAbstractMenu.h index 752b0cf92..7e1612d97 100644 --- a/src/laybasic/laybasic/layAbstractMenu.h +++ b/src/laybasic/laybasic/layAbstractMenu.h @@ -822,23 +822,6 @@ private: } -namespace tl -{ - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; - - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; - - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - }; -} - #endif diff --git a/src/laybasic/laybasic/layBrowserDialog.h b/src/laybasic/laybasic/layBrowserDialog.h index 886cefbc3..f8ea03044 100644 --- a/src/laybasic/laybasic/layBrowserDialog.h +++ b/src/laybasic/laybasic/layBrowserDialog.h @@ -130,16 +130,5 @@ private: } -namespace tl -{ - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - }; - - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - }; -} - #endif diff --git a/src/laybasic/laybasic/layDispatcher.h b/src/laybasic/laybasic/layDispatcher.h index ae7d0b31e..307787514 100644 --- a/src/laybasic/laybasic/layDispatcher.h +++ b/src/laybasic/laybasic/layDispatcher.h @@ -246,15 +246,4 @@ private: } -namespace tl -{ - // disable copy ctor for Dispatcher - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; -} - #endif - - diff --git a/src/laybasic/laybasic/layLayoutView.h b/src/laybasic/laybasic/layLayoutView.h index 58dbf94c6..2438f0b14 100644 --- a/src/laybasic/laybasic/layLayoutView.h +++ b/src/laybasic/laybasic/layLayoutView.h @@ -2934,12 +2934,4 @@ private: } -namespace tl { - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; -} - #endif - diff --git a/src/laybasic/laybasic/layMarker.h b/src/laybasic/laybasic/layMarker.h index c0a6eeed4..052746f28 100644 --- a/src/laybasic/laybasic/layMarker.h +++ b/src/laybasic/laybasic/layMarker.h @@ -813,17 +813,4 @@ private: } -namespace tl { - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; -} - #endif - - diff --git a/src/laybasic/laybasic/layNetlistBrowserModel.h b/src/laybasic/laybasic/layNetlistBrowserModel.h index 0290e1dbe..c87d2cfb6 100644 --- a/src/laybasic/laybasic/layNetlistBrowserModel.h +++ b/src/laybasic/laybasic/layNetlistBrowserModel.h @@ -99,19 +99,6 @@ class CircuitNetItemData; class CircuitDeviceItemData; class CircuitSubCircuitItemData; -} - -namespace tl { - // disable copying for NetlistModelItemData - template<> struct type_traits - { - typedef false_tag has_copy_constructor; - }; -} - -namespace lay -{ - /** * @brief A base class for the item data object */ diff --git a/src/laybasic/laybasic/layPlugin.h b/src/laybasic/laybasic/layPlugin.h index 87a955227..a592fb9d9 100644 --- a/src/laybasic/laybasic/layPlugin.h +++ b/src/laybasic/laybasic/layPlugin.h @@ -883,14 +883,6 @@ inline bool test_and_set (T &target, const T &source) } -namespace tl -{ - // disable copy ctor for Plugin - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - }; -} - #endif diff --git a/src/lym/lym/gsiDeclLymMacro.cc b/src/lym/lym/gsiDeclLymMacro.cc index 91ba0da3e..596a97756 100644 --- a/src/lym/lym/gsiDeclLymMacro.cc +++ b/src/lym/lym/gsiDeclLymMacro.cc @@ -35,17 +35,6 @@ #include -namespace tl -{ - -// type traits for BrowserDialog_Stub -template <> -struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; -}; - -} - namespace gsi { diff --git a/src/rdb/rdb/rdb.h b/src/rdb/rdb/rdb.h index 138cd4d96..6df8bf59e 100644 --- a/src/rdb/rdb/rdb.h +++ b/src/rdb/rdb/rdb.h @@ -2388,48 +2388,4 @@ private: } -namespace tl -{ - /** - * @brief Type traits for Cell - */ - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; - - /** - * @brief Type traits for Category - */ - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; - - /** - * @brief Type traits for Categories - */ - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; - - /** - * @brief Type traits for Item - */ - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; - - /** - * @brief Type traits for Database - */ - template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; - }; -} - #endif - diff --git a/src/tl/tl/tlList.h b/src/tl/tl/tlList.h index 21458d74f..791917b95 100644 --- a/src/tl/tl/tlList.h +++ b/src/tl/tl/tlList.h @@ -29,11 +29,12 @@ #include #include +#include namespace tl { -template class list_impl; +template class list_impl; /** * @brief A base class for objects that can be kept in the linked list @@ -109,7 +110,7 @@ private: }; template -class list_impl +class list_impl { public: list_impl () : m_head (), m_back () @@ -142,7 +143,7 @@ public: } } - void swap (list_impl &other) + void swap (list_impl &other) { std::swap (m_head.mp_next, other.m_head.mp_next); if (m_head.mp_next) { @@ -308,21 +309,21 @@ private: }; template -class list_impl - : public list_impl +class list_impl + : public list_impl { public: - using list_impl::insert; - using list_impl::push_back; - using list_impl::pop_back; - using list_impl::insert_before; - using list_impl::push_front; - using list_impl::pop_front; + using list_impl::insert; + using list_impl::push_back; + using list_impl::pop_back; + using list_impl::insert_before; + using list_impl::push_front; + using list_impl::pop_front; list_impl () { } list_impl (const list_impl &other) - : list_impl () + : list_impl () { operator= (other); } @@ -330,7 +331,7 @@ public: list_impl &operator= (const list_impl &other) { if (this != &other) { - list_impl::clear (); + list_impl::clear (); for (const C *p = other.first (); p; p = p->next ()) { push_back (*p); } @@ -444,7 +445,7 @@ private: */ template class list - : public list_impl::has_copy_constructor> + : public list_impl::value> { public: typedef list_iterator iterator; @@ -454,17 +455,17 @@ public: typedef C value_type; - using list_impl::has_copy_constructor>::first; - using list_impl::has_copy_constructor>::last; - using list_impl::has_copy_constructor>::head; - using list_impl::has_copy_constructor>::back; + using list_impl::value>::first; + using list_impl::value>::last; + using list_impl::value>::head; + using list_impl::value>::back; list () { } - list (const list &other) : list_impl::has_copy_constructor> (other) { } + list (const list &other) : list_impl::value> (other) { } list &operator= (const list &other) { - list_impl::has_copy_constructor>::operator= (other); + list_impl::value>::operator= (other); return *this; } diff --git a/src/tl/tl/tlProgress.h b/src/tl/tl/tlProgress.h index aff0b25b5..757da2897 100644 --- a/src/tl/tl/tlProgress.h +++ b/src/tl/tl/tlProgress.h @@ -43,26 +43,6 @@ class RelativeProgress; class AbstractProgress; class AbsoluteProgress; -template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - -template <> struct type_traits : public type_traits { - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - /** * @brief A helper class to clean up pending progress objects * diff --git a/src/tl/tl/tlRecipe.h b/src/tl/tl/tlRecipe.h index 20770718b..e5aef6c90 100644 --- a/src/tl/tl/tlRecipe.h +++ b/src/tl/tl/tlRecipe.h @@ -183,12 +183,6 @@ private: std::string m_description; }; -template<> struct type_traits : public type_traits -{ - typedef tl::false_tag has_copy_constructor; - typedef tl::false_tag has_default_constructor; -}; - } // namespace tl #endif diff --git a/src/tl/tl/tlReuseVector.h b/src/tl/tl/tlReuseVector.h index 2f332ebb0..4b063c084 100644 --- a/src/tl/tl/tlReuseVector.h +++ b/src/tl/tl/tlReuseVector.h @@ -36,14 +36,14 @@ namespace tl { -template class reuse_vector; -template class reuse_vector_const_iterator; +template class reuse_vector; +template class reuse_vector_const_iterator; /** * @brief The iterator for a reuse_vector */ -template +template class reuse_vector_iterator { public: @@ -64,14 +64,14 @@ public: /** * @brief The constructor */ - reuse_vector_iterator (reuse_vector *v, size_type n) + reuse_vector_iterator (reuse_vector *v, size_type n) : mp_v (v), m_n (n) { } /** * @brief Equality with const iterator */ - bool operator== (const reuse_vector_const_iterator &d) const + bool operator== (const reuse_vector_const_iterator &d) const { return mp_v == d.mp_v && m_n == d.m_n; } @@ -79,7 +79,7 @@ public: /** * @brief Inequality with const iterator */ - bool operator!= (const reuse_vector_const_iterator &d) const + bool operator!= (const reuse_vector_const_iterator &d) const { return ! operator== (d); } @@ -171,7 +171,7 @@ public: /** * @brief The pointer to the vector that this iterator points into */ - reuse_vector *vector () const + reuse_vector *vector () const { return mp_v; } @@ -193,7 +193,7 @@ public: private: template friend class reuse_vector_const_iterator; - reuse_vector *mp_v; + reuse_vector *mp_v; size_type m_n; }; @@ -202,7 +202,7 @@ private: * @brief The const_iterator for a reuse_vector */ -template +template class reuse_vector_const_iterator { public: @@ -223,23 +223,23 @@ public: /** * @brief The constructor */ - reuse_vector_const_iterator (const reuse_vector *v, size_type n) + reuse_vector_const_iterator (const reuse_vector *v, size_type n) : mp_v (v), m_n (n) { } /** * @brief The conversion of a non-const iterator to a const iterator */ - reuse_vector_const_iterator (const reuse_vector_iterator &d) + reuse_vector_const_iterator (const reuse_vector_iterator &d) : mp_v (d.mp_v), m_n (d.m_n) { } /** * @brief cast to non-const iterator */ - reuse_vector_iterator to_non_const () const + reuse_vector_iterator to_non_const () const { - return reuse_vector_iterator (const_cast *> (mp_v), m_n); + return reuse_vector_iterator (const_cast *> (mp_v), m_n); } /** @@ -340,7 +340,7 @@ public: /** * @brief The pointer to the vector that this iterator points into */ - const reuse_vector *vector () const + const reuse_vector *vector () const { return mp_v; } @@ -362,7 +362,7 @@ public: private: template friend class reuse_vector_iterator; - const reuse_vector *mp_v; + const reuse_vector *mp_v; size_type m_n; }; @@ -491,14 +491,14 @@ private: * One requirement is that sizeof(C) >= sizeof(void *). */ -template +template ::value> class reuse_vector { public: typedef Value value_type; typedef size_t size_type; - typedef reuse_vector_iterator iterator; - typedef reuse_vector_const_iterator const_iterator; + typedef reuse_vector_iterator iterator; + typedef reuse_vector_const_iterator const_iterator; /** * @brief Default constructor @@ -889,8 +889,11 @@ public: */ void reserve (size_type n) { - typename tl::type_traits::relocate_requirements relocate_requirements_tag; - internal_reserve (n, relocate_requirements_tag); + if (trivial_relocate) { + internal_reserve_trivial (n); + } else { + internal_reserve_complex (n); + } } /** @@ -979,7 +982,7 @@ private: } } - void internal_reserve (size_type n, tl::complex_relocate_required) + void internal_reserve_complex (size_type n) { if (n > capacity ()) { @@ -1010,7 +1013,7 @@ private: } } - void internal_reserve (size_type n, tl::trivial_relocate_required) + void internal_reserve_trivial (size_type n) { if (n > capacity ()) { diff --git a/src/tl/tl/tlString.cc b/src/tl/tl/tlString.cc index 2842e1161..833794a55 100644 --- a/src/tl/tl/tlString.cc +++ b/src/tl/tl/tlString.cc @@ -41,6 +41,21 @@ namespace tl static std::locale c_locale ("C"); +// ------------------------------------------------------------------------- +// Exception classes + +ExtractorNotImplementedException::ExtractorNotImplementedException () + : Exception (tl::to_string (tr ("No string extractor available"))) +{ + // .. nothing yet .. +} + +StringConversionException::StringConversionException () + : Exception (tl::to_string (tr ("No string conversion available"))) +{ + // .. nothing yet .. +} + // ------------------------------------------------------------------------- // lower and upper case for wchar_t and uint32_t diff --git a/src/tl/tl/tlString.h b/src/tl/tl/tlString.h index 576b3a93d..6752f7251 100644 --- a/src/tl/tl/tlString.h +++ b/src/tl/tl/tlString.h @@ -33,6 +33,7 @@ #include "tlException.h" #include "tlVariant.h" +#include "tlTypeTraits.h" #if defined(HAVE_QT) class QImage; @@ -40,9 +41,29 @@ class QImage; namespace tl { +/** + * @brief An exception indicating that string extraction is not available for a certain type + */ +class ExtractorNotImplementedException + : tl::Exception +{ +public: + ExtractorNotImplementedException (); +}; + +/** + * @brief An exception indicating that string conversion is not available for a certain type + */ +class StringConversionException + : tl::Exception +{ +public: + StringConversionException (); +}; + class Extractor; -template void extractor_impl (tl::Extractor &, T &); -template bool test_extractor_impl (tl::Extractor &, T &); +template void extractor_impl (tl::Extractor &, T &) { throw ExtractorNotImplementedException (); } +template bool test_extractor_impl (tl::Extractor &, T &) { throw ExtractorNotImplementedException (); } /** * @brief Another string class @@ -266,7 +287,11 @@ TL_PUBLIC std::string to_string (const char *cp, int length); TL_PUBLIC std::string to_string_from_local (const char *cp); TL_PUBLIC std::string to_local (const std::string &s); -template inline std::string to_string (const T &o) { return o.to_string (); } +template struct __redirect_to_string; +template struct __redirect_to_string { static std::string to_string (const T &t) { return t.to_string (); } }; +template struct __redirect_to_string { static std::string to_string (const T &) { throw StringConversionException (); } }; +template inline std::string to_string (const T &o) { return __redirect_to_string::value>::to_string (o); } + template <> inline std::string to_string (const double &d) { return to_string (d, 12); } template <> inline std::string to_string (const float &d) { return to_string (d, 6); } template <> TL_PUBLIC std::string to_string (const int &d); diff --git a/src/tl/tl/tlTypeTraits.h b/src/tl/tl/tlTypeTraits.h index 98dcb0c82..be2908dd3 100644 --- a/src/tl/tl/tlTypeTraits.h +++ b/src/tl/tl/tlTypeTraits.h @@ -67,50 +67,56 @@ inline bool value_of (true_tag) { return true; } */ inline bool value_of (false_tag) { return false; } -/** - * @brief A tag class which defines a object to require complex relocation. - */ -struct complex_relocate_required { }; +// SFINAE boolean types +typedef char __yes_type [1]; +typedef char __no_type [2]; /** - * @brief A tag class which defines a object to allow trivial relocation. + * @brief Detects whether a class has a "to_string" method with a matching signature */ -struct trivial_relocate_required { }; +template static __yes_type &__test_to_string_func (decltype (&T::to_string)); +template static __no_type &__test_to_string_func (...); -/** - * @brief The type traits struct that defines some requirements for the given type T - * - * Specifically the following typedefs must be provided: - * - * "relocate_requirements" specifies how the object needs to be relocated. - * This typdef can be complex_relocate_required or trivial_relocate_required. - * Complex relocation is implemented by a copy construction and destruction of the - * source object. Trivial relocation is implemented by a memcpy. - * The default is complex relocation. - * - * "has_copy_constructor" specifies if a class has a copy constructor. - * This typedef can be true_tag or false_tag. The default is "true_tag". - * - * "has_default_constructor" specifies if a class has a default constructor. - * This typedef can be true_tag or false_tag. The default is "true_tag". - * - * "has_efficient_swap" specifies that it is beneficial to use std::swap - * on those objects because it is implemented very efficiently. The default is "false_tag". - * - * TODO: further requirements shall go here. - */ -template -struct type_traits +template +struct has_to_string { - typedef complex_relocate_required relocate_requirements; - typedef true_tag has_copy_constructor; - typedef true_tag has_default_constructor; - typedef true_tag has_public_destructor; - typedef false_tag has_efficient_swap; - typedef false_tag supports_extractor; - typedef false_tag supports_to_string; - typedef false_tag has_less_operator; - typedef false_tag has_equal_operator; + static constexpr bool value = sizeof (__test_to_string_func (nullptr)) == sizeof (__yes_type); +}; + +/** + * @brief Detects whether a class has an equal operator + */ +template static __yes_type &__test_equal_func (decltype (&T::operator==)); +template static __no_type &__test_equal_func (...); + +template +struct has_equal_operator +{ + static constexpr bool value = sizeof (__test_equal_func (nullptr)) == sizeof (__yes_type); +}; + +/** + * @brief Detects whether a class has a less operator + */ +template static __yes_type &__test_less_func (decltype (&T::operator==)); +template static __no_type &__test_less_func (...); + +template +struct has_less_operator +{ + static constexpr bool value = sizeof (__test_less_func (nullptr)) == sizeof (__yes_type); +}; + +/** + * @brief Detects whether a class has a "swap" method with a matching signature + */ +template static __yes_type &__test_swap_func (decltype (&T::swap)); +template static __no_type &__test_swap_func (...); + +template +struct has_swap +{ + static constexpr bool value = sizeof (__test_swap_func (nullptr)) == sizeof (__yes_type); }; } diff --git a/src/tl/tl/tlVariantUserClasses.h b/src/tl/tl/tlVariantUserClasses.h index 900ea07ba..687b84548 100644 --- a/src/tl/tl/tlVariantUserClasses.h +++ b/src/tl/tl/tlVariantUserClasses.h @@ -34,113 +34,90 @@ namespace tl class EvalClass; -/** - * @brief A helper function to implement equal as efficiently as possible - */ -template -bool _var_user_equal_impl (const T *a, const T *b, I); - -template -bool _var_user_equal_impl (const T *a, const T *b, tl::true_tag) -{ - return *a == *b; -} - -template -bool _var_user_equal_impl (const T * /*a*/, const T * /*b*/, tl::false_tag) -{ - tl_assert (false); -} - /** * @brief A helper function to implement clone as efficiently as possible */ -template -T *_var_user_clone_impl (const T *a, I); +template struct _var_user_clone_impl; template -T *_var_user_clone_impl (const T *a, tl::true_tag) +struct _var_user_clone_impl { - return new T (*a); -} + static T *call (const T *a) { new T (*a); } +}; template -T *_var_user_clone_impl (const T * /*a*/, tl::false_tag) +struct _var_user_clone_impl { - tl_assert (false); -} + static T *call (const T *) { tl_assert (false); } +}; /** - * @brief A helper function to implement assignment as efficiently as possible + * @brief A helper function to implement assign as efficiently as possible */ -template -void _var_user_assign_impl (T *a, const T *b, I); +template struct _var_user_assign_impl; template -void _var_user_assign_impl (T *a, const T *b, tl::true_tag) +struct _var_user_assign_impl { - *a = *b; -} + static void call (T *a, const T *b) { *a = *b; } +}; template -void _var_user_assign_impl (T * /*a*/, const T * /*b*/, tl::false_tag) +struct _var_user_assign_impl { - tl_assert (false); -} + static void call (T *, const T *) { tl_assert (false); } +}; /** - * @brief A helper function to implement less as efficiently as possible + * @brief A helper function to implement equal as efficiently as possible */ -template -bool _var_user_less_impl (const T *a, const T *b, I); +template struct _var_user_equal_impl; template -bool _var_user_less_impl (const T *a, const T *b, tl::true_tag) +struct _var_user_equal_impl { - return *a < *b; -} + static bool call (const T *a, const T *b) { return *a == *b; } +}; template -bool _var_user_less_impl (const T *, const T *, tl::false_tag) +struct _var_user_equal_impl { - tl_assert (false); -} + static bool call (const T *, const T *) { tl_assert (false); } +}; /** - * @brief A helper function to implement to_string as efficiently as possible + * @brief A helper function to implement equal as efficiently as possible */ -template -std::string _var_user_to_string_impl (const T *a, I); +template struct _var_user_less_impl; template -std::string _var_user_to_string_impl (const T *a, tl::true_tag) +struct _var_user_less_impl { - return a->to_string (); -} + static bool call (const T *a, const T *b) { return *a < *b; } +}; template -std::string _var_user_to_string_impl (const T *, tl::false_tag) +struct _var_user_less_impl { - tl_assert (false); -} + static bool call (const T *, const T *) { tl_assert (false); } +}; /** - * @brief A helper function to implement read as efficiently as possible + * @brief A helper function to implement equal as efficiently as possible */ -template -void _var_user_read_impl (T *a, tl::Extractor &ex, I); +template struct _var_user_to_string_impl; template -void _var_user_read_impl (T *a, tl::Extractor &ex, tl::true_tag) +struct _var_user_to_string_impl { - ex.read (*a); -} + static std::string call (const T *a) { return a->to_string (); } +}; template -void _var_user_read_impl (T *, tl::Extractor &, tl::false_tag) +struct _var_user_to_string_impl { - tl_assert (false); -} + static std::string call (const T *) { tl_assert (false); } +}; /** * @brief A utility implementation of tl::VariantUserClass using type traits for the implementation @@ -162,39 +139,32 @@ public: virtual bool equal (const void *a, const void *b) const { - typename tl::type_traits::has_equal_operator f; - return _var_user_equal_impl ((T *) a, (T *) b, f); + return _var_user_equal_impl::value> ((const T *) a, (const T *) b); } virtual bool less (const void *a, const void *b) const { - typename tl::type_traits::has_less_operator f; - return _var_user_less_impl ((T *) a, (T *) b, f); + return _var_user_less_impl::value> ((const T *) a, (const T *) b); } virtual void *clone (const void *a) const { - typename tl::type_traits::has_copy_constructor f; - return _var_user_clone_impl ((const T *) a, f); + return _var_user_clone_impl::value> ((const T *) a); } virtual void assign (void *a, const void *b) const { - // TODO: we assume (for now) that objects with a copy constructor do have an assignment operator too - typename tl::type_traits::has_copy_constructor f; - _var_user_assign_impl ((T *) a, (const T *) b, f); + _var_user_assign_impl::value> ((T *) a, (const T *)b); } virtual std::string to_string (const void *a) const { - typename tl::type_traits::supports_to_string f; - return _var_user_to_string_impl ((const T *) a, f); + return _var_user_to_string_impl::value> ((const T *) a); } virtual void read (void *a, tl::Extractor &ex) const { - typename tl::type_traits::supports_extractor f; - _var_user_read_impl ((T *) a, ex, f); + ex.read (*(T *)a); } virtual const char *name () const diff --git a/src/tl/tl/tlVector.h b/src/tl/tl/tlVector.h index 0bbd77803..c8e71be23 100644 --- a/src/tl/tl/tlVector.h +++ b/src/tl/tl/tlVector.h @@ -93,26 +93,6 @@ public: vector (const T &v, int s) : base (v, s) { } }; -/** - * @brief The type traits for the vector type - */ -template -struct type_traits > : public type_traits -{ -#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0 - // With iterator debugging on, the vector carries additional - // information which cannot be copied trivially - typedef complex_relocate_required relocate_requirements; -#else - typedef trivial_relocate_required relocate_requirements; -#endif - typedef true_tag has_efficient_swap; - typedef false_tag supports_extractor; - typedef false_tag supports_to_string; - typedef true_tag has_less_operator; - typedef true_tag has_equal_operator; -}; - } // namespace tl #endif diff --git a/src/tl/unit_tests/tlExpressionTests.cc b/src/tl/unit_tests/tlExpressionTests.cc index 619b5a351..4c05fa444 100644 --- a/src/tl/unit_tests/tlExpressionTests.cc +++ b/src/tl/unit_tests/tlExpressionTests.cc @@ -569,25 +569,6 @@ EdgeClassClass::execute (const tl::ExpressionParserContext &context, tl::Variant } } -namespace tl -{ - -template <> -struct type_traits : public type_traits -{ - typedef trivial_relocate_required relocate_requirements; - typedef true_tag supports_to_string; -}; - -template <> -struct type_traits : public type_traits -{ - typedef trivial_relocate_required relocate_requirements; - typedef true_tag supports_to_string; -}; - -} - // basics: custom objects TEST(1b) { diff --git a/src/tl/unit_tests/tlListTests.cc b/src/tl/unit_tests/tlListTests.cc index 1f41339af..3e9ca3ba1 100644 --- a/src/tl/unit_tests/tlListTests.cc +++ b/src/tl/unit_tests/tlListTests.cc @@ -53,15 +53,6 @@ public: } -namespace tl -{ - template <> - struct type_traits : public tl::type_traits - { - typedef tl::false_tag has_copy_constructor; - }; -} - template static std::string l2s (const tl::list &l) { diff --git a/src/tl/unit_tests/tlReuseVectorTests.cc b/src/tl/unit_tests/tlReuseVectorTests.cc index a8c2b0d1f..88bc45062 100644 --- a/src/tl/unit_tests/tlReuseVectorTests.cc +++ b/src/tl/unit_tests/tlReuseVectorTests.cc @@ -210,13 +210,6 @@ int A::dc = 0; } -namespace tl -{ - template <> struct type_traits : public type_traits { - typedef trivial_relocate_required relocate_requirements; - }; -} - namespace { class B { @@ -238,18 +231,11 @@ int B::dc = 0; } -namespace tl -{ - template <> struct type_traits : public type_traits { - typedef complex_relocate_required relocate_requirements; - }; -} - // Test: relocate strategy TEST(4) { - tl::reuse_vector va; - tl::reuse_vector vb; + tl::reuse_vector va; + tl::reuse_vector vb; A::reset (); B::reset (); @@ -259,11 +245,11 @@ TEST(4) } int i = 0; - for (tl::reuse_vector::const_iterator n = va.begin (); n != va.end (); ++n, ++i) { + for (tl::reuse_vector::const_iterator n = va.begin (); n != va.end (); ++n, ++i) { EXPECT_EQ (n->x, 100 - i * 10); } i = 0; - for (tl::reuse_vector::const_iterator n = vb.begin (); n != vb.end (); ++n, ++i) { + for (tl::reuse_vector::const_iterator n = vb.begin (); n != vb.end (); ++n, ++i) { EXPECT_EQ (n->x, 100 - i * 10); } diff --git a/src/tl/unit_tests/tlVariantTests.cc b/src/tl/unit_tests/tlVariantTests.cc index 93af6d383..9f2ca66ba 100644 --- a/src/tl/unit_tests/tlVariantTests.cc +++ b/src/tl/unit_tests/tlVariantTests.cc @@ -48,18 +48,6 @@ struct AA int AA::ac = 0; -namespace tl -{ - template<> - class type_traits - : public type_traits - { - public: - typedef tl::true_tag supports_to_string; - typedef tl::true_tag has_copy_constructor; - }; -} - struct B { int bb; @@ -69,20 +57,6 @@ struct B const std::string &to_string () const { return b; } }; -namespace tl -{ - template<> - class type_traits - : public type_traits - { - public: - typedef tl::true_tag supports_to_string; - typedef tl::true_tag has_equal_operator; - typedef tl::true_tag has_less_operator; - typedef tl::true_tag has_copy_constructor; - }; -} - static tl::VariantUserClassImpl a_class_instance; static tl::VariantUserClassImpl aa_class_instance; static tl::VariantUserClassImpl b_class_instance;