diff --git a/src/db/db/dbBox.cc b/src/db/db/dbBox.cc index 48abf25aa..1e3f868d9 100644 --- a/src/db/db/dbBox.cc +++ b/src/db/db/dbBox.cc @@ -31,14 +31,14 @@ namespace tl template<> void extractor_impl (tl::Extractor &ex, db::Box &b) { if (! test_extractor_impl (ex, b)) { - ex.error (tl::to_string (QObject::tr ("Expected an box specification"))); + ex.error (tl::to_string (tr ("Expected an box specification"))); } } template<> void extractor_impl (tl::Extractor &ex, db::DBox &b) { if (! test_extractor_impl (ex, b)) { - ex.error (tl::to_string (QObject::tr ("Expected an box specification"))); + ex.error (tl::to_string (tr ("Expected an box specification"))); } } diff --git a/src/db/db/dbBoxScanner.h b/src/db/db/dbBoxScanner.h index 19cd3eb8f..52423afe0 100644 --- a/src/db/db/dbBoxScanner.h +++ b/src/db/db/dbBoxScanner.h @@ -291,7 +291,7 @@ public: std::auto_ptr progress (0); if (m_report_progress) { if (m_progress_desc.empty ()) { - progress.reset (new tl::RelativeProgress (tl::to_string (QObject::tr ("Processing")), m_pp.size (), 1000)); + progress.reset (new tl::RelativeProgress (tl::to_string (tr ("Processing")), m_pp.size (), 1000)); } else { progress.reset (new tl::RelativeProgress (m_progress_desc, m_pp.size (), 1000)); } diff --git a/src/db/db/dbCellMapping.cc b/src/db/db/dbCellMapping.cc index dcf1d9d0c..4c403c8c1 100644 --- a/src/db/db/dbCellMapping.cc +++ b/src/db/db/dbCellMapping.cc @@ -348,7 +348,7 @@ CellMapping::create_missing_mapping (db::Layout &layout_a, db::cell_index_type / void CellMapping::create_from_geometry (const db::Layout &layout_a, db::cell_index_type cell_index_a, const db::Layout &layout_b, db::cell_index_type cell_index_b) { - tl::SelfTimer timer (tl::verbosity () >= 11, tl::to_string (QObject::tr ("Cell mapping"))); + tl::SelfTimer timer (tl::verbosity () >= 11, tl::to_string (tr ("Cell mapping"))); if (tl::verbosity () >= 20) { tl::info << "Cell mapping - first step: mapping instance count and instance identity"; diff --git a/src/db/db/dbCommonReader.cc b/src/db/db/dbCommonReader.cc index 96ac0d7d9..7a636a147 100644 --- a/src/db/db/dbCommonReader.cc +++ b/src/db/db/dbCommonReader.cc @@ -74,6 +74,7 @@ public: return false; } +#if defined(HAVE_XML) virtual tl::XMLElementBase *xml_reader_options_element () const { return new db::ReaderOptionsXMLElement ("common", @@ -83,6 +84,7 @@ public: tl::make_member (&db::CommonReaderOptions::enable_text_objects, "enable-text-objects") ); } +#endif }; static tl::RegisteredClass reader_decl (new CommonFormatDeclaration (), 20, "Common"); diff --git a/src/db/db/dbEdge.cc b/src/db/db/dbEdge.cc index 07dd42ba0..3237e6582 100644 --- a/src/db/db/dbEdge.cc +++ b/src/db/db/dbEdge.cc @@ -29,14 +29,14 @@ namespace tl template<> void extractor_impl (tl::Extractor &ex, db::Edge &e) { if (! test_extractor_impl (ex, e)) { - ex.error (tl::to_string (QObject::tr ("Expected an edge specification"))); + ex.error (tl::to_string (tr ("Expected an edge specification"))); } } template<> void extractor_impl (tl::Extractor &ex, db::DEdge &e) { if (! test_extractor_impl (ex, e)) { - ex.error (tl::to_string (QObject::tr ("Expected an edge specification"))); + ex.error (tl::to_string (tr ("Expected an edge specification"))); } } diff --git a/src/db/db/dbEdgePair.cc b/src/db/db/dbEdgePair.cc index 583c05e3f..d4055329b 100644 --- a/src/db/db/dbEdgePair.cc +++ b/src/db/db/dbEdgePair.cc @@ -29,14 +29,14 @@ namespace tl template<> void extractor_impl (tl::Extractor &ex, db::EdgePair &e) { if (! test_extractor_impl (ex, e)) { - ex.error (tl::to_string (QObject::tr ("Expected an edge specification"))); + ex.error (tl::to_string (tr ("Expected an edge specification"))); } } template<> void extractor_impl (tl::Extractor &ex, db::DEdgePair &e) { if (! test_extractor_impl (ex, e)) { - ex.error (tl::to_string (QObject::tr ("Expected an edge specification"))); + ex.error (tl::to_string (tr ("Expected an edge specification"))); } } diff --git a/src/db/db/dbEdgePairs.cc b/src/db/db/dbEdgePairs.cc index 68cd8def4..1ee65f466 100644 --- a/src/db/db/dbEdgePairs.cc +++ b/src/db/db/dbEdgePairs.cc @@ -218,7 +218,7 @@ namespace tl template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::EdgePairs &b) { if (! test_extractor_impl (ex, b)) { - ex.error (tl::to_string (QObject::tr ("Expected an edge pair collection specification"))); + ex.error (tl::to_string (tr ("Expected an edge pair collection specification"))); } } } diff --git a/src/db/db/dbEdgeProcessor.cc b/src/db/db/dbEdgeProcessor.cc index 60889271b..79640fb53 100644 --- a/src/db/db/dbEdgeProcessor.cc +++ b/src/db/db/dbEdgeProcessor.cc @@ -1580,11 +1580,11 @@ EdgeProcessor::process (db::EdgeSink &es, EdgeEvaluatorBase &op) std::auto_ptr progress (0); if (m_report_progress) { if (m_progress_desc.empty ()) { - progress.reset (new tl::AbsoluteProgress (tl::to_string (QObject::tr ("Processing")), 1000)); + progress.reset (new tl::AbsoluteProgress (tl::to_string (tr ("Processing")), 1000)); } else { progress.reset (new tl::AbsoluteProgress (m_progress_desc, 1000)); } - progress->set_format (tl::to_string (QObject::tr ("%.0f%%"))); + progress->set_format (tl::to_string (tr ("%.0f%%"))); progress->set_unit (todo_max / 100); } diff --git a/src/db/db/dbEdges.cc b/src/db/db/dbEdges.cc index 00f7b7542..5c41840c6 100644 --- a/src/db/db/dbEdges.cc +++ b/src/db/db/dbEdges.cc @@ -1362,7 +1362,7 @@ namespace tl template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::Edges &b) { if (! test_extractor_impl (ex, b)) { - ex.error (tl::to_string (QObject::tr ("Expected an edge collection specification"))); + ex.error (tl::to_string (tr ("Expected an edge collection specification"))); } } } diff --git a/src/db/db/dbFuzzyCellMapping.cc b/src/db/db/dbFuzzyCellMapping.cc index fda1ff78e..166396a1d 100644 --- a/src/db/db/dbFuzzyCellMapping.cc +++ b/src/db/db/dbFuzzyCellMapping.cc @@ -298,7 +298,7 @@ static void collect_cell_signatures (const db::Layout &layout, const std::vector void FuzzyCellMapping::create (const db::Layout &layout_a, db::cell_index_type cell_index_a, const db::Layout &layout_b, db::cell_index_type cell_index_b) { - tl::SelfTimer timer (tl::verbosity () >= 11, tl::to_string (QObject::tr ("Cell mapping"))); + tl::SelfTimer timer (tl::verbosity () >= 11, tl::to_string (tr ("Cell mapping"))); if (tl::verbosity () >= 20) { tl::info << "Cell mapping"; @@ -321,16 +321,16 @@ FuzzyCellMapping::create (const db::Layout &layout_a, db::cell_index_type cell_i } std::map ma; - collect_cell_signatures (layout_a, la, cell_index_a, ma, tl::to_string (QObject::tr ("Collecting cell signatures (A)"))); + collect_cell_signatures (layout_a, la, cell_index_a, ma, tl::to_string (tr ("Collecting cell signatures (A)"))); if (tl::verbosity () >= 40) { tl::info << "Signatures (b):"; } std::map mb; - collect_cell_signatures (layout_b, lb, cell_index_b, mb, tl::to_string (QObject::tr ("Collecting cell signatures (B)"))); + collect_cell_signatures (layout_b, lb, cell_index_b, mb, tl::to_string (tr ("Collecting cell signatures (B)"))); - tl::RelativeProgress progress (tl::to_string (QObject::tr ("Finding matching cells")), ma.size () * ma.size ()); + tl::RelativeProgress progress (tl::to_string (tr ("Finding matching cells")), ma.size () * ma.size ()); for (std::map ::const_iterator m = ma.begin (); m != ma.end (); ++m) { diff --git a/src/db/db/dbGlyphs.cc b/src/db/db/dbGlyphs.cc index e0a17431c..fb62ee807 100644 --- a/src/db/db/dbGlyphs.cc +++ b/src/db/db/dbGlyphs.cc @@ -146,7 +146,7 @@ TextGenerator::load_from_resource (const std::string &name) { QResource res (tl::to_qstring (name)); if (res.size () == 0) { - throw tl::Exception (tl::to_string (QObject::tr ("Unable to load font resource from ")) + name); + throw tl::Exception (tl::to_string (tr ("Unable to load font resource from ")) + name); } QByteArray data = qUncompress (QByteArray ((const char *) res.data (), int (res.size ()))); diff --git a/src/db/db/dbHershey.cc b/src/db/db/dbHershey.cc index d37ab2463..6e303edc7 100644 --- a/src/db/db/dbHershey.cc +++ b/src/db/db/dbHershey.cc @@ -85,13 +85,13 @@ std::vector hershey_font_names () { std::vector ff; - ff.push_back (tl::to_string (QObject::tr ("Default"))); - ff.push_back (tl::to_string (QObject::tr ("Gothic"))); - ff.push_back (tl::to_string (QObject::tr ("Sans Serif"))); - ff.push_back (tl::to_string (QObject::tr ("Stick"))); - ff.push_back (tl::to_string (QObject::tr ("Times Italic"))); - ff.push_back (tl::to_string (QObject::tr ("Times Thin"))); - ff.push_back (tl::to_string (QObject::tr ("Times"))); + ff.push_back (tl::to_string (tr ("Default"))); + ff.push_back (tl::to_string (tr ("Gothic"))); + ff.push_back (tl::to_string (tr ("Sans Serif"))); + ff.push_back (tl::to_string (tr ("Stick"))); + ff.push_back (tl::to_string (tr ("Times Italic"))); + ff.push_back (tl::to_string (tr ("Times Thin"))); + ff.push_back (tl::to_string (tr ("Times"))); return ff; } diff --git a/src/db/db/dbInit.cc b/src/db/db/dbInit.cc index 99f261470..fb91b4bc3 100644 --- a/src/db/db/dbInit.cc +++ b/src/db/db/dbInit.cc @@ -61,7 +61,7 @@ static PluginDescriptor load_plugin (const std::string &pp) // there is no "dlopen" on mingw, so we need to emulate it. HINSTANCE handle = LoadLibraryW ((const wchar_t *) tl::to_qstring (pp).constData ()); if (! handle) { - throw tl::Exception (tl::to_string (QObject::tr ("Unable to load plugin: %s with error message: %s ")), pp, GetLastError ()); + throw tl::Exception (tl::to_string (tr ("Unable to load plugin: %s with error message: %s ")), pp, GetLastError ()); return desc; } init_func = reinterpret_cast (GetProcAddress (handle, init_func_name)); @@ -71,7 +71,7 @@ static PluginDescriptor load_plugin (const std::string &pp) void *handle; handle = dlopen (tl::string_to_system (pp).c_str (), RTLD_LAZY); if (! handle) { - throw tl::Exception (tl::to_string (QObject::tr ("Unable to load plugin: %s")), pp); + throw tl::Exception (tl::to_string (tr ("Unable to load plugin: %s")), pp); } init_func = reinterpret_cast (dlsym (handle, init_func_name)); @@ -90,7 +90,7 @@ static PluginDescriptor load_plugin (const std::string &pp) } } - tl::log << tl::sprintf (tl::to_string (QObject::tr ("Loaded plugin: %s")), pp); + tl::log << tl::sprintf (tl::to_string (tr ("Loaded plugin: %s")), pp); return desc; } diff --git a/src/db/db/dbInstances.cc b/src/db/db/dbInstances.cc index eca515d9c..ba5f8925a 100644 --- a/src/db/db/dbInstances.cc +++ b/src/db/db/dbInstances.cc @@ -1057,7 +1057,7 @@ Instances::instance_type Instances::replace (const instance_type &ref, const cell_inst_wp_array_type &inst) { if (ref.instances () != this) { - throw tl::Exception (tl::to_string (QObject::tr ("Trying to replace an object in a list that it does not belong to"))); + throw tl::Exception (tl::to_string (tr ("Trying to replace an object in a list that it does not belong to"))); } const cell_inst_wp_array_type *cp = ref.basic_ptr (cell_inst_wp_array_type::tag ()); @@ -1080,7 +1080,7 @@ Instances::instance_type Instances::replace (const instance_type &ref, const cell_inst_array_type &inst) { if (ref.instances () != this) { - throw tl::Exception (tl::to_string (QObject::tr ("Trying to replace an object in a list that it does not belong to"))); + throw tl::Exception (tl::to_string (tr ("Trying to replace an object in a list that it does not belong to"))); } const cell_inst_array_type *cp = ref.basic_ptr (cell_inst_array_type::tag ()); @@ -1121,7 +1121,7 @@ void Instances::erase_inst_by_iter (Tag tag, ET editable_tag, I iter) { if (iter.vector () != &inst_tree (tag, editable_tag).objects ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Trying to erase an object from a list that it does not belong to"))); + throw tl::Exception (tl::to_string (tr ("Trying to erase an object from a list that it does not belong to"))); } if (mp_cell) { @@ -1468,7 +1468,7 @@ Instances::instance_type Instances::replace_prop_id (const instance_type &ref, db::properties_id_type prop_id) { if (ref.instances () != this) { - throw tl::Exception (tl::to_string (QObject::tr ("Trying to replace an object in a list that it does not belong to"))); + throw tl::Exception (tl::to_string (tr ("Trying to replace an object in a list that it does not belong to"))); } if (! ref.is_null ()) { diff --git a/src/db/db/dbLayerProperties.cc b/src/db/db/dbLayerProperties.cc index 6904a87cc..85b758fa2 100644 --- a/src/db/db/dbLayerProperties.cc +++ b/src/db/db/dbLayerProperties.cc @@ -328,14 +328,14 @@ template<> bool test_extractor_impl (tl::Extractor &ex, db::LayerOffset &e) template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::LayerProperties &e) { if (! test_extractor_impl (ex, e)) { - ex.error (tl::to_string (QObject::tr ("Expected a layer specification"))); + ex.error (tl::to_string (tr ("Expected a layer specification"))); } } template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::LayerOffset &e) { if (! test_extractor_impl (ex, e)) { - ex.error (tl::to_string (QObject::tr ("Expected a layer offset specification"))); + ex.error (tl::to_string (tr ("Expected a layer offset specification"))); } } diff --git a/src/db/db/dbLayout.cc b/src/db/db/dbLayout.cc index 69cef4a56..90e2a9200 100644 --- a/src/db/db/dbLayout.cc +++ b/src/db/db/dbLayout.cc @@ -1271,13 +1271,13 @@ Layout::update () const void Layout::do_update () { - tl::SelfTimer timer (tl::verbosity () >= 21, tl::to_string (QObject::tr ("Sorting"))); + tl::SelfTimer timer (tl::verbosity () >= 21, tl::to_string (tr ("Sorting"))); // establish a progress report since this operation can take some time. // HINT: because of some gcc bug, automatic destruction of the tl::Progress // object does not work. We overcome this problem by creating the object with new // and catching exceptions. - tl::RelativeProgress *pr = new tl::RelativeProgress (tl::to_string (QObject::tr ("Sorting layout")), m_cells_size, 1000); + tl::RelativeProgress *pr = new tl::RelativeProgress (tl::to_string (tr ("Sorting layout")), m_cells_size, 1000); pr->set_desc (""); try { @@ -1287,12 +1287,12 @@ Layout::do_update () if (hier_dirty ()) { { tl::SelfTimer timer (tl::verbosity () >= 31, "Updating relations"); - pr->set_desc (tl::to_string (QObject::tr ("Updating relations"))); + pr->set_desc (tl::to_string (tr ("Updating relations"))); update_relations (); } { tl::SelfTimer timer (tl::verbosity () >= 31, "Topological sort"); - pr->set_desc (tl::to_string (QObject::tr ("Topological sorting"))); + pr->set_desc (tl::to_string (tr ("Topological sorting"))); tl_assert (topological_sort ()); } } @@ -1312,7 +1312,7 @@ Layout::do_update () tl::SelfTimer timer (tl::verbosity () >= 31, "Updating bounding boxes"); unsigned int layers = 0; pr->set (0); - pr->set_desc (tl::to_string (QObject::tr ("Updating bounding boxes"))); + pr->set_desc (tl::to_string (tr ("Updating bounding boxes"))); for (bottom_up_iterator c = begin_bottom_up (); c != end_bottom_up (); ++c) { ++*pr; cell_type &cp (cell (*c)); @@ -1333,7 +1333,7 @@ Layout::do_update () { tl::SelfTimer timer (tl::verbosity () >= 31, "Sorting shapes"); pr->set (0); - pr->set_desc (tl::to_string (QObject::tr ("Sorting shapes"))); + pr->set_desc (tl::to_string (tr ("Sorting shapes"))); for (bottom_up_iterator c = begin_bottom_up (); c != end_bottom_up (); ++c) { ++*pr; cell_type &cp (cell (*c)); @@ -1347,7 +1347,7 @@ Layout::do_update () tl::SelfTimer timer (tl::verbosity () >= 31, "Sorting instances"); size_t layers = 0; pr->set (0); - pr->set_desc (tl::to_string (QObject::tr ("Sorting instances"))); + pr->set_desc (tl::to_string (tr ("Sorting instances"))); for (bottom_up_iterator c = begin_bottom_up (); c != end_bottom_up (); ++c) { ++*pr; cell_type &cp (cell (*c)); diff --git a/src/db/db/dbLayoutContextHandler.cc b/src/db/db/dbLayoutContextHandler.cc index 337c18e3f..9ac10f5ac 100644 --- a/src/db/db/dbLayoutContextHandler.cc +++ b/src/db/db/dbLayoutContextHandler.cc @@ -48,7 +48,7 @@ tl::Variant LayoutContextHandler::eval_bracket (const std::string &content) cons lp.read (ex); if (! ex.at_end ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Not a valid layer source expression: ")) + content); + throw tl::Exception (tl::to_string (tr ("Not a valid layer source expression: ")) + content); } for (db::LayerIterator l = mp_layout->begin_layers (); l != mp_layout->end_layers (); ++l) { @@ -60,7 +60,7 @@ tl::Variant LayoutContextHandler::eval_bracket (const std::string &content) cons if (mp_layout_nc) { return tl::Variant (mp_layout_nc->insert_layer (lp)); } else { - throw tl::Exception (tl::to_string (QObject::tr ("Not a valid layer: ")) + lp.to_string ()); + throw tl::Exception (tl::to_string (tr ("Not a valid layer: ")) + lp.to_string ()); } } @@ -82,7 +82,7 @@ tl::Variant LayoutContextHandler::eval_double_bracket (const std::string &s) con db::Library *lib = db::LibraryManager::instance ().lib_ptr_by_name (libname); if (! lib) { - throw tl::Exception (tl::to_string (QObject::tr ("Not a valid library name: ")) + libname); + throw tl::Exception (tl::to_string (tr ("Not a valid library name: ")) + libname); } db::LayoutContextHandler lib_context (&lib->layout (), true); @@ -100,7 +100,7 @@ tl::Variant LayoutContextHandler::eval_double_bracket (const std::string &s) con } else { - throw tl::Exception (tl::to_string (QObject::tr ("Not a valid cell name: ")) + s); + throw tl::Exception (tl::to_string (tr ("Not a valid cell name: ")) + s); } } diff --git a/src/db/db/dbLayoutDiff.cc b/src/db/db/dbLayoutDiff.cc index db6ed019a..3fd1e73a3 100644 --- a/src/db/db/dbLayoutDiff.cc +++ b/src/db/db/dbLayoutDiff.cc @@ -805,7 +805,7 @@ do_compare_layouts (const db::Layout &a, const db::Cell *top_a, const db::Layout } - tl::RelativeProgress progress (tl::to_string (QObject::tr ("Layout diff")), common_cells.size (), 1); + tl::RelativeProgress progress (tl::to_string (tr ("Layout diff")), common_cells.size (), 1); // compare cell by cell diff --git a/src/db/db/dbLayoutQuery.cc b/src/db/db/dbLayoutQuery.cc index 99e20db08..6b831641e 100644 --- a/src/db/db/dbLayoutQuery.cc +++ b/src/db/db/dbLayoutQuery.cc @@ -1438,7 +1438,7 @@ public: FilterStateBase *do_create_state (db::Layout *layout, tl::Eval &eval) const { if (! layout->is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot execute a delete query on a non-editable layout"))); + throw tl::Exception (tl::to_string (tr ("Cannot execute a delete query on a non-editable layout"))); } return new DeleteFilterState (this, eval, layout, m_pids, m_transparent); } @@ -1541,7 +1541,7 @@ public: FilterStateBase *do_create_state (db::Layout *layout, tl::Eval &eval) const { if (! layout->is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot execute a with .. do query on a non-editable layout"))); + throw tl::Exception (tl::to_string (tr ("Cannot execute a with .. do query on a non-editable layout"))); } return new WithDoFilterState (this, m_do_expression, eval, layout, m_transparent); } @@ -1886,7 +1886,7 @@ public: void execute (const tl::ExpressionParserContext &context, tl::Variant &out, const std::vector &args) const { if (args.size () > 0) { - throw tl::EvalError (tl::to_string (QObject::tr ("Query function does not allow parameters")), context); + throw tl::EvalError (tl::to_string (tr ("Query function does not allow parameters")), context); } out = tl::Variant (); diff --git a/src/db/db/dbLayoutUtils.cc b/src/db/db/dbLayoutUtils.cc index 0061f5c3c..b9bbc2431 100644 --- a/src/db/db/dbLayoutUtils.cc +++ b/src/db/db/dbLayoutUtils.cc @@ -195,7 +195,7 @@ merge_layouts (db::Layout &target, // provide the property mapper db::PropertyMapper pm (target, source); - tl::RelativeProgress progress (tl::to_string (QObject::tr ("Merge cells")), all_cells_to_copy.size (), 1); + tl::RelativeProgress progress (tl::to_string (tr ("Merge cells")), all_cells_to_copy.size (), 1); // actually to the mapping for (std::set::const_iterator c = all_cells_to_copy.begin (); c != all_cells_to_copy.end (); ++c) { @@ -305,7 +305,7 @@ copy_or_move_shapes (db::Layout &target, // provide the property mapper db::PropertyMapper pm (target, source); - tl::RelativeProgress progress (tl::to_string (QObject::tr ("Merge cells")), all_cells_to_copy.size () * layer_mapping.size (), 1); + tl::RelativeProgress progress (tl::to_string (tr ("Merge cells")), all_cells_to_copy.size () * layer_mapping.size (), 1); // and copy for (std::set::const_iterator c = all_cells_to_copy.begin (); c != all_cells_to_copy.end (); ++c) { diff --git a/src/db/db/dbManager.cc b/src/db/db/dbManager.cc index 74a5dd139..c9d60ec95 100644 --- a/src/db/db/dbManager.cc +++ b/src/db/db/dbManager.cc @@ -114,7 +114,7 @@ Manager::transaction (const std::string &description, transaction_id_t join_with // close transactions that are still open (was an assertion before) if (m_opened) { - tl::warn << tl::to_string (QObject::tr ("Transaction still opened: ")) << m_current->second; + tl::warn << tl::to_string (tr ("Transaction still opened: ")) << m_current->second; commit (); } @@ -177,7 +177,7 @@ Manager::undo () m_replay = true; --m_current; - tl::RelativeProgress progress (tl::to_string (QObject::tr ("Undoing")), m_current->first.size (), 10); + tl::RelativeProgress progress (tl::to_string (tr ("Undoing")), m_current->first.size (), 10); try { @@ -212,7 +212,7 @@ Manager::redo () tl_assert (! m_opened); tl_assert (! m_replay); - tl::RelativeProgress progress (tl::to_string (QObject::tr ("Redoing")), m_current->first.size (), 10); + tl::RelativeProgress progress (tl::to_string (tr ("Redoing")), m_current->first.size (), 10); try { diff --git a/src/db/db/dbMatrix.cc b/src/db/db/dbMatrix.cc index 5eccca61e..e7572fc4b 100644 --- a/src/db/db/dbMatrix.cc +++ b/src/db/db/dbMatrix.cc @@ -818,7 +818,7 @@ namespace tl template<> void extractor_impl (tl::Extractor &ex, db::Matrix2d &m) { if (! test_extractor_impl (ex, m)) { - ex.error (tl::to_string (QObject::tr ("Expected a 2d matrix specification"))); + ex.error (tl::to_string (tr ("Expected a 2d matrix specification"))); } } @@ -899,7 +899,7 @@ namespace tl template<> void extractor_impl (tl::Extractor &ex, db::Matrix3d &m) { if (! test_extractor_impl (ex, m)) { - ex.error (tl::to_string (QObject::tr ("Expected a 3d matrix specification"))); + ex.error (tl::to_string (tr ("Expected a 3d matrix specification"))); } } } diff --git a/src/db/db/dbPath.cc b/src/db/db/dbPath.cc index 40f997351..4db578db1 100644 --- a/src/db/db/dbPath.cc +++ b/src/db/db/dbPath.cc @@ -603,14 +603,14 @@ namespace tl template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::Path &p) { if (! test_extractor_impl (ex, p)) { - ex.error (tl::to_string (QObject::tr ("Expected a path specification"))); + ex.error (tl::to_string (tr ("Expected a path specification"))); } } template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::DPath &p) { if (! test_extractor_impl (ex, p)) { - ex.error (tl::to_string (QObject::tr ("Expected a path specification"))); + ex.error (tl::to_string (tr ("Expected a path specification"))); } } diff --git a/src/db/db/dbPoint.cc b/src/db/db/dbPoint.cc index a2aa2c5cb..99c7b4006 100644 --- a/src/db/db/dbPoint.cc +++ b/src/db/db/dbPoint.cc @@ -49,7 +49,7 @@ namespace { void _extractor_impl (tl::Extractor &ex, db::point &p) { if (! _test_extractor_impl (ex, p)) { - ex.error (tl::to_string (QObject::tr ("Expected a point specification"))); + ex.error (tl::to_string (tr ("Expected a point specification"))); } } diff --git a/src/db/db/dbPolygon.cc b/src/db/db/dbPolygon.cc index 405433df2..f495119b1 100644 --- a/src/db/db/dbPolygon.cc +++ b/src/db/db/dbPolygon.cc @@ -481,28 +481,28 @@ namespace tl template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::Polygon &p) { if (! test_extractor_impl (ex, p)) { - ex.error (tl::to_string (QObject::tr ("Expected a polygon specification"))); + ex.error (tl::to_string (tr ("Expected a polygon specification"))); } } template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::DPolygon &p) { if (! test_extractor_impl (ex, p)) { - ex.error (tl::to_string (QObject::tr ("Expected a polygon specification"))); + ex.error (tl::to_string (tr ("Expected a polygon specification"))); } } template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::SimplePolygon &p) { if (! test_extractor_impl (ex, p)) { - ex.error (tl::to_string (QObject::tr ("Expected a polygon specification"))); + ex.error (tl::to_string (tr ("Expected a polygon specification"))); } } template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::DSimplePolygon &p) { if (! test_extractor_impl (ex, p)) { - ex.error (tl::to_string (QObject::tr ("Expected a polygon specification"))); + ex.error (tl::to_string (tr ("Expected a polygon specification"))); } } diff --git a/src/db/db/dbPolygon.h b/src/db/db/dbPolygon.h index b506ab98e..ad32211e3 100644 --- a/src/db/db/dbPolygon.h +++ b/src/db/db/dbPolygon.h @@ -40,6 +40,7 @@ #include "tlAlgorithm.h" #include "tlAssert.h" +#include #include #include #include diff --git a/src/db/db/dbReader.cc b/src/db/db/dbReader.cc index bd8326c9f..bd5f28d1c 100644 --- a/src/db/db/dbReader.cc +++ b/src/db/db/dbReader.cc @@ -62,7 +62,7 @@ Reader::Reader (tl::InputStream &stream) } if (! mp_actual_reader) { - throw db::ReaderException (tl::to_string (QObject::tr ("Stream has unknown format: ")) + stream.source ()); + throw db::ReaderException (tl::to_string (tr ("Stream has unknown format: ")) + stream.source ()); } } diff --git a/src/db/db/dbRegion.cc b/src/db/db/dbRegion.cc index d80c205c0..efde4a740 100644 --- a/src/db/db/dbRegion.cc +++ b/src/db/db/dbRegion.cc @@ -1890,7 +1890,7 @@ namespace tl template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::Region &b) { if (! test_extractor_impl (ex, b)) { - ex.error (tl::to_string (QObject::tr ("Expected an region collection specification"))); + ex.error (tl::to_string (tr ("Expected an region collection specification"))); } } } diff --git a/src/db/db/dbShapes.cc b/src/db/db/dbShapes.cc index 1e6b032d3..1b4bcd13d 100644 --- a/src/db/db/dbShapes.cc +++ b/src/db/db/dbShapes.cc @@ -527,7 +527,7 @@ Shapes::do_insert (const Shapes::shape_type &shape, const Trans &t, tl::func_del case shape_type::TextPtrArray: // Arrays are not supported yet // TODO: implement - throw tl::Exception (tl::to_string (QObject::tr ("Function 'insert' with transformation does not support shape arrays"))); + throw tl::Exception (tl::to_string (tr ("Function 'insert' with transformation does not support shape arrays"))); }; } @@ -588,7 +588,7 @@ Shapes::replace_prop_id (const Shapes::shape_type &ref, db::properties_id_type p { tl_assert (! ref.is_array_member ()); if (! is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function 'replace_prop_id' is permitted only in editable mode"))); + throw tl::Exception (tl::to_string (tr ("Function 'replace_prop_id' is permitted only in editable mode"))); } if (ref.with_props ()) { @@ -721,7 +721,7 @@ Shapes::transform (const Shapes::shape_type &ref, const Trans &t) { tl_assert (! ref.is_array_member ()); if (! is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function 'transform' is permitted only in editable mode"))); + throw tl::Exception (tl::to_string (tr ("Function 'transform' is permitted only in editable mode"))); } switch (ref.m_type) { @@ -823,7 +823,7 @@ Shapes::replace (const Shapes::shape_type &ref, const Sh &sh) { tl_assert (! ref.is_array_member ()); if (! is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function 'replace' is permitted only in editable mode"))); + throw tl::Exception (tl::to_string (tr ("Function 'replace' is permitted only in editable mode"))); } switch (ref.m_type) { @@ -1016,7 +1016,7 @@ Shapes::shape_type Shapes::find_shape_by_tag (Tag tag, const shape_type &shape) const { if (! is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function 'find' is permitted only in editable mode"))); + throw tl::Exception (tl::to_string (tr ("Function 'find' is permitted only in editable mode"))); } if (! shape.has_prop_id ()) { typename db::layer::iterator i = get_layer ().find (*shape.basic_ptr (tag)); @@ -1042,7 +1042,7 @@ Shapes::replace_prop_id (const Sh *pos, db::properties_id_type prop_id) { if (pos->properties_id () != prop_id) { if (! is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function 'replace' is permitted only in editable mode"))); + throw tl::Exception (tl::to_string (tr ("Function 'replace' is permitted only in editable mode"))); } if (manager () && manager ()->transacting ()) { db::layer_op::queue_or_append (manager (), this, false /*not insert*/, *pos); @@ -1060,7 +1060,7 @@ Shapes::shape_type Shapes::replace_prop_id_iter (typename db::object_tag, const Iter &iter, db::properties_id_type prop_id) { if (! is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function 'replace' is permitted only in editable mode"))); + throw tl::Exception (tl::to_string (tr ("Function 'replace' is permitted only in editable mode"))); } if (manager () && manager ()->transacting ()) { @@ -1080,7 +1080,7 @@ Shapes::shape_type Shapes::reinsert_member_with_props (typename db::object_tag, const shape_type &ref, const Sh2 &sh) { if (! is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function 'replace' is permitted only in editable mode"))); + throw tl::Exception (tl::to_string (tr ("Function 'replace' is permitted only in editable mode"))); } // the shape types are not equal - resolve into erase and insert (of new) @@ -1099,7 +1099,7 @@ Shapes::shape_type Shapes::replace_member_with_props (typename db::object_tag, const shape_type &ref, const Sh2 &sh) { if (! is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function 'replace' is permitted only in editable mode"))); + throw tl::Exception (tl::to_string (tr ("Function 'replace' is permitted only in editable mode"))); } // the shape types are not equal - resolve into erase and insert (of new) @@ -1149,7 +1149,7 @@ Shapes::replace_member_with_props (typename db::object_tag tag, const shape_ } else { if (! is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function 'replace' is permitted only in editable mode"))); + throw tl::Exception (tl::to_string (tr ("Function 'replace' is permitted only in editable mode"))); } if (! ref.with_props ()) { diff --git a/src/db/db/dbShapes.h b/src/db/db/dbShapes.h index 63710d548..6fa907b9b 100644 --- a/src/db/db/dbShapes.h +++ b/src/db/db/dbShapes.h @@ -959,7 +959,7 @@ public: void erase (Tag /*tag*/, StableTag /*stable_tag*/, typename db::layer::iterator pos) { if (! is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function 'erase' is permitted only in editable mode"))); + throw tl::Exception (tl::to_string (tr ("Function 'erase' is permitted only in editable mode"))); } if (manager () && manager ()->transacting ()) { db::layer_op::queue_or_append (manager (), this, false /*not insert*/, *pos); @@ -1022,7 +1022,7 @@ public: typename db::layer::iterator to) { if (! is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function 'erase' is permitted only in editable mode"))); + throw tl::Exception (tl::to_string (tr ("Function 'erase' is permitted only in editable mode"))); } if (manager () && manager ()->transacting ()) { db::layer_op::queue_or_append (manager (), this, false /*not insert*/, from, to); @@ -1048,7 +1048,7 @@ public: void erase_positions (Tag /*tag*/, StableTag /*stable_tag*/, I first, I last) { if (! is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function 'erase' is permitted only in editable mode"))); + throw tl::Exception (tl::to_string (tr ("Function 'erase' is permitted only in editable mode"))); } if (manager () && manager ()->transacting ()) { db::layer_op::queue_or_append (manager (), this, false /*not insert*/, first, last, true /*dummy*/); diff --git a/src/db/db/dbShapes3.cc b/src/db/db/dbShapes3.cc index 0a44b2a60..f4dd737b9 100644 --- a/src/db/db/dbShapes3.cc +++ b/src/db/db/dbShapes3.cc @@ -249,7 +249,7 @@ bool Shapes::is_valid_shape_by_tag (Tag /*tag*/, const shape_type &shape) const { if (! is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function 'is_valid' is permitted only in editable mode"))); + throw tl::Exception (tl::to_string (tr ("Function 'is_valid' is permitted only in editable mode"))); } if (! shape.has_prop_id ()) { return iterator_from_shape (get_layer (), shape).is_valid (); @@ -327,7 +327,7 @@ void Shapes::erase_shape_by_tag_ws (Tag /*tag*/, StableTag /*stable_tag*/, const shape_type &shape) { if (! is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function 'erase' is permitted only in editable mode"))); + throw tl::Exception (tl::to_string (tr ("Function 'erase' is permitted only in editable mode"))); } if (! shape.has_prop_id ()) { @@ -407,7 +407,7 @@ void Shapes::erase_shape (const Shapes::shape_type &shape) { if (! is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function 'erase' is permitted only in editable mode"))); + throw tl::Exception (tl::to_string (tr ("Function 'erase' is permitted only in editable mode"))); } switch (shape.m_type) { @@ -492,7 +492,7 @@ void Shapes::erase_shapes (const std::vector &shapes) { if (! is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function 'erase' is permitted only in editable mode"))); + throw tl::Exception (tl::to_string (tr ("Function 'erase' is permitted only in editable mode"))); } for (std::vector::const_iterator s = shapes.begin (); s != shapes.end (); ) { diff --git a/src/db/db/dbStatic.cc b/src/db/db/dbStatic.cc index c846c9881..f4e9e7f66 100644 --- a/src/db/db/dbStatic.cc +++ b/src/db/db/dbStatic.cc @@ -42,14 +42,14 @@ void set_default_editable_mode (bool editable) void check_editable_mode (const char *f_str) { if (! ms_editable) { - throw tl::Exception (tl::to_string (QObject::tr ("Function '%s' is permitted only in editable mode")), f_str); + throw tl::Exception (tl::to_string (tr ("Function '%s' is permitted only in editable mode")), f_str); } } void check_editable_mode () { if (! ms_editable) { - throw tl::Exception (tl::to_string (QObject::tr ("Operation is permitted only in editable mode"))); + throw tl::Exception (tl::to_string (tr ("Operation is permitted only in editable mode"))); } } diff --git a/src/db/db/dbStream.cc b/src/db/db/dbStream.cc index 8a82bd6e5..b64bdfca7 100644 --- a/src/db/db/dbStream.cc +++ b/src/db/db/dbStream.cc @@ -38,6 +38,8 @@ namespace db // ------------------------------------------------------------------ // Implementation of load_options_xml_element_list +#if defined(HAVE_XML) + tl::XMLElementList load_options_xml_element_list () { tl::XMLElementList elements; @@ -72,6 +74,8 @@ tl::XMLElementList save_options_xml_element_list () return elements; } +#endif + } diff --git a/src/db/db/dbStream.h b/src/db/db/dbStream.h index 0bc623dc8..999b326fd 100644 --- a/src/db/db/dbStream.h +++ b/src/db/db/dbStream.h @@ -31,8 +31,10 @@ #include "dbLoadLayoutOptions.h" #include "tlClassRegistry.h" -#include "tlXMLParser.h" -#include "tlXMLWriter.h" +#if defined(HAVE_XML) +# include "tlXMLParser.h" +# include "tlXMLWriter.h" +#endif #include #include @@ -109,6 +111,7 @@ public: */ virtual bool can_write () const = 0; +#if defined(HAVE_XML) /** * @brief Delivers the XMLElement object that represents the reader options within a technology XML tree * @@ -136,8 +139,10 @@ public: { return 0; } +#endif }; +#if defined(HAVE_XML) /** * @brief A helper class for the XML serialization of the stream options (custom read adaptor) * @@ -298,6 +303,7 @@ DB_PUBLIC tl::XMLElementList load_options_xml_element_list (); * @brief Returns the XMLElement list that can represent a db::SaveLayoutOptions object */ DB_PUBLIC tl::XMLElementList save_options_xml_element_list (); +#endif } diff --git a/src/db/db/dbStreamLayers.cc b/src/db/db/dbStreamLayers.cc index 673bc582e..2062bc191 100644 --- a/src/db/db/dbStreamLayers.cc +++ b/src/db/db/dbStreamLayers.cc @@ -548,7 +548,7 @@ LayerMap::from_string_file_format (const std::string &s) } } catch (tl::Exception &ex) { - throw tl::Exception (ex.msg () + tl::to_string (QObject::tr (" in line ")) + tl::to_string (lnr)); + throw tl::Exception (ex.msg () + tl::to_string (tr (" in line ")) + tl::to_string (lnr)); } return lm; diff --git a/src/db/db/dbStreamLayers.h b/src/db/db/dbStreamLayers.h index 7fa429a38..707364629 100644 --- a/src/db/db/dbStreamLayers.h +++ b/src/db/db/dbStreamLayers.h @@ -48,7 +48,7 @@ class DB_PUBLIC LayerSpecFormatException { public: LayerSpecFormatException (const char *s) - : tl::Exception (tl::to_string (QObject::tr ("Not a valid layer map expression: '..%s' (use '/' to separated layer and datatype, ',' to list numbers for layer or datatype, '-' to create ranges and ';' to concatenate multiple subexpressions)")), s) + : tl::Exception (tl::to_string (tr ("Not a valid layer map expression: '..%s' (use '/' to separated layer and datatype, ',' to list numbers for layer or datatype, '-' to create ranges and ';' to concatenate multiple subexpressions)")), s) { } }; diff --git a/src/db/db/dbTechnology.cc b/src/db/db/dbTechnology.cc index 1f9d78bc9..3298b572f 100644 --- a/src/db/db/dbTechnology.cc +++ b/src/db/db/dbTechnology.cc @@ -148,7 +148,7 @@ Technologies::add_tech (Technology *tech, bool replace_same) if (replace_same) { *t = *tech; } else { - throw tl::Exception (tl::to_string (QObject::tr ("A technology with this name already exists: %1").arg (tl::to_qstring (tech->name ())))); + throw tl::Exception (tl::to_string (tr ("A technology with this name already exists: %1").arg (tl::to_qstring (tech->name ())))); } } else { m_technologies.push_back (tech_ptr.release ()); diff --git a/src/db/db/dbTechnology.h b/src/db/db/dbTechnology.h index 4056fc2c6..6e05bf070 100644 --- a/src/db/db/dbTechnology.h +++ b/src/db/db/dbTechnology.h @@ -29,7 +29,9 @@ #include "tlStableVector.h" #include "tlString.h" #include "tlEvents.h" -#include "tlXMLParser.h" +#if defined(HAVE_XML) +# include "tlXMLParser.h" +#endif #include "tlTypeTraits.h" #include "tlClassRegistry.h" #include "dbStreamLayers.h" @@ -528,10 +530,12 @@ public: */ void save (const std::string &fn) const; +#if defined(HAVE_XML) /** * @brief Delivers the XMLElementList that specifies the technology's XML representation */ static tl::XMLElementList xml_elements (); +#endif /** * @brief Sets the technology component by the component name @@ -722,14 +726,18 @@ public: */ virtual TechnologyComponent *create_component () const = 0; +#if defined(HAVE_XML) /** * @brief Delivers the XMLElement object that represents this component within a technology XML tree * * The object returned is destroyed by the caller. */ virtual tl::XMLElementBase *xml_element () const = 0; +#endif }; +#if defined(HAVE_XML) + /** * @brief A helper class for the XML serialization of the technology component (custom read adaptor) */ @@ -848,6 +856,8 @@ public: } }; +#endif + } namespace tl diff --git a/src/db/db/dbTestSupport.cc b/src/db/db/dbTestSupport.cc index 3f2e497e8..1698385f6 100644 --- a/src/db/db/dbTestSupport.cc +++ b/src/db/db/dbTestSupport.cc @@ -30,8 +30,7 @@ #include "dbLayoutDiff.h" #include "tlUnitTest.h" - -#include +#include "tlFileUtils.h" namespace db { @@ -110,7 +109,7 @@ void compare_layouts (tl::TestBase *_this, const db::Layout &layout, const std:: fn += tl::sprintf (".%d", n); } - if (QFileInfo (tl::to_qstring (fn)).exists ()) { + if (tl::file_exists (fn)) { if (n == 1 && any) { throw tl::Exception (tl::sprintf ("Inconsistent reference variants for %s: there can be either variants (.1,.2,... suffix) or a single file (without suffix)", au_file)); @@ -138,8 +137,8 @@ void compare_layouts (tl::TestBase *_this, const db::Layout &layout, const std:: if (! equal) { _this->raise (tl::sprintf ("Compare failed - see\n actual: %s\n golden: %s%s", - tl::to_string (QFileInfo (tl::to_qstring (tmp_file)).absoluteFilePath ()), - tl::to_string (QFileInfo (tl::to_qstring (au_file)).absoluteFilePath ()), + tl::absolute_file_path (tmp_file), + tl::absolute_file_path (au_file), (n > 1 ? "\nand variants" : ""))); } } diff --git a/src/db/db/dbText.cc b/src/db/db/dbText.cc index 8a95920e4..92b83e90c 100644 --- a/src/db/db/dbText.cc +++ b/src/db/db/dbText.cc @@ -41,14 +41,14 @@ namespace tl template<> void extractor_impl (tl::Extractor &ex, db::Text &p) { if (! test_extractor_impl (ex, p)) { - ex.error (tl::to_string (QObject::tr ("Expected a text specification"))); + ex.error (tl::to_string (tr ("Expected a text specification"))); } } template<> void extractor_impl (tl::Extractor &ex, db::DText &p) { if (! test_extractor_impl (ex, p)) { - ex.error (tl::to_string (QObject::tr ("Expected a text specification"))); + ex.error (tl::to_string (tr ("Expected a text specification"))); } } diff --git a/src/db/db/dbTilingProcessor.cc b/src/db/db/dbTilingProcessor.cc index 21974afea..eea0f3718 100644 --- a/src/db/db/dbTilingProcessor.cc +++ b/src/db/db/dbTilingProcessor.cc @@ -26,6 +26,7 @@ #include "tlExpression.h" #include "tlProgress.h" #include "tlThreadedWorkers.h" +#include "tlThreads.h" #include "gsiDecl.h" #include @@ -290,7 +291,7 @@ public: void next_progress () { - QMutexLocker locker (&m_mutex); + tl::MutexLocker locker (&m_mutex); ++m_progress; } @@ -298,7 +299,7 @@ public: { unsigned int p; { - QMutexLocker locker (&m_mutex); + tl::MutexLocker locker (&m_mutex); p = m_progress; } @@ -316,7 +317,7 @@ private: TilingProcessor *mp_proc; bool m_has_tiles; unsigned int m_progress; - QMutex m_mutex; + tl::Mutex m_mutex; }; class TilingProcessorTask @@ -711,15 +712,15 @@ TilingProcessor::output (const std::string &name, db::Edges &edges) tl::Variant TilingProcessor::receiver (const std::vector &args) { - QMutexLocker locker (&m_output_mutex); + tl::MutexLocker locker (&m_output_mutex); if (args.size () != 1) { - throw tl::Exception (tl::to_string (QObject::tr ("_rec function requires one argument: the handle of the output channel"))); + throw tl::Exception (tl::to_string (tr ("_rec function requires one argument: the handle of the output channel"))); } size_t index = args[0].to (); if (index >= m_outputs.size ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid handle in _rec function call"))); + throw tl::Exception (tl::to_string (tr ("Invalid handle in _rec function call"))); } gsi::Proxy *proxy = new gsi::Proxy (gsi::cls_decl ()); @@ -733,17 +734,17 @@ TilingProcessor::receiver (const std::vector &args) void TilingProcessor::put (size_t ix, size_t iy, const db::Box &tile, const std::vector &args) { - QMutexLocker locker (&m_output_mutex); + tl::MutexLocker locker (&m_output_mutex); if (args.size () < 2 || args.size () > 3) { - throw tl::Exception (tl::to_string (QObject::tr ("_output function requires two or three arguments: handle and object and a clip flag (optional)"))); + throw tl::Exception (tl::to_string (tr ("_output function requires two or three arguments: handle and object and a clip flag (optional)"))); } bool clip = ((args.size () <= 2 || args [2].to_bool ()) && ! tile.empty ()); size_t index = args[0].to (); if (index >= m_outputs.size ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid handle (first argument) in _output function call"))); + throw tl::Exception (tl::to_string (tr ("Invalid handle (first argument) in _output function call"))); } m_outputs[index].receiver->put (ix, iy, tile, m_outputs[index].id, args[1], dbu (), m_outputs[index].trans, clip); @@ -909,7 +910,7 @@ TilingProcessor::execute (const std::string &desc) } if (job.has_error ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Errors occured during processing. First error message says:\n")) + job.error_messages ().front ()); + throw tl::Exception (tl::to_string (tr ("Errors occured during processing. First error message says:\n")) + job.error_messages ().front ()); } } diff --git a/src/db/db/dbTilingProcessor.h b/src/db/db/dbTilingProcessor.h index f0cc9f4ba..acedad2c5 100644 --- a/src/db/db/dbTilingProcessor.h +++ b/src/db/db/dbTilingProcessor.h @@ -36,6 +36,7 @@ #include "tlExpression.h" #include "tlTypeTraits.h" +#include "tlThreads.h" namespace db { @@ -661,7 +662,7 @@ private: bool m_dbu_specific_set; bool m_scale_to_dbu; std::vector m_scripts; - QMutex m_output_mutex; + tl::Mutex m_output_mutex; tl::Eval m_top_eval; }; diff --git a/src/db/db/dbTrans.cc b/src/db/db/dbTrans.cc index 102debfa7..6df23d32e 100644 --- a/src/db/db/dbTrans.cc +++ b/src/db/db/dbTrans.cc @@ -53,7 +53,7 @@ namespace { void _extractor_impl (tl::Extractor &ex, db::simple_trans &t) { if (! _test_extractor_impl (ex, t)) { - ex.error (tl::to_string (QObject::tr ("Expected a transformation specification"))); + ex.error (tl::to_string (tr ("Expected a transformation specification"))); } } @@ -78,7 +78,7 @@ namespace { void _extractor_impl (tl::Extractor &ex, db::disp_trans &t) { if (! _test_extractor_impl (ex, t)) { - ex.error (tl::to_string (QObject::tr ("Expected a transformation specification"))); + ex.error (tl::to_string (tr ("Expected a transformation specification"))); } } @@ -120,7 +120,7 @@ namespace { void _extractor_impl (tl::Extractor &ex, db::complex_trans &t) { if (! _test_extractor_impl (ex, t)) { - ex.error (tl::to_string (QObject::tr ("Expected transformation specification"))); + ex.error (tl::to_string (tr ("Expected transformation specification"))); } } @@ -148,7 +148,7 @@ namespace { void _extractor_impl (tl::Extractor &ex, db::combined_trans &t) { if (! _test_extractor_impl (ex, t)) { - ex.error (tl::to_string (QObject::tr ("Expected transformation/magnification specification"))); + ex.error (tl::to_string (tr ("Expected transformation/magnification specification"))); } } @@ -162,7 +162,7 @@ void DB_PUBLIC extractor_impl (tl::Extractor &ex, db::FTrans &t) { if (! test_extractor_impl (ex, t)) { - ex.error (tl::to_string (QObject::tr ("Expected rotation/mirror code (r0,r90,r180,r270,m0,m45,m90,m135)"))); + ex.error (tl::to_string (tr ("Expected rotation/mirror code (r0,r90,r180,r270,m0,m45,m90,m135)"))); } } diff --git a/src/db/db/dbVector.cc b/src/db/db/dbVector.cc index 5a2ec7e10..db43023fb 100644 --- a/src/db/db/dbVector.cc +++ b/src/db/db/dbVector.cc @@ -49,7 +49,7 @@ namespace { void _extractor_impl (tl::Extractor &ex, db::vector &p) { if (! _test_extractor_impl (ex, p)) { - ex.error (tl::to_string (QObject::tr ("Expected a vector specification"))); + ex.error (tl::to_string (tr ("Expected a vector specification"))); } } diff --git a/src/db/db/dbWriter.cc b/src/db/db/dbWriter.cc index 9059fbc84..a133b5fa8 100644 --- a/src/db/db/dbWriter.cc +++ b/src/db/db/dbWriter.cc @@ -39,7 +39,7 @@ Writer::Writer (const db::SaveLayoutOptions &options) } } if (! mp_writer) { - throw tl::Exception (tl::to_string (QObject::tr ("Unknown stream format: %s")), m_options.format ()); + throw tl::Exception (tl::to_string (tr ("Unknown stream format: %s")), m_options.format ()); } } diff --git a/src/db/db/gsiDeclDbCell.cc b/src/db/db/gsiDeclDbCell.cc index cb046d98e..b1d8ffe1c 100644 --- a/src/db/db/gsiDeclDbCell.cc +++ b/src/db/db/gsiDeclDbCell.cc @@ -690,14 +690,14 @@ struct cell_inst_array_defs static void check_is_editable (const db::Instances *insts) { if (! insts->is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function permitted on editable layouts only"))); + throw tl::Exception (tl::to_string (tr ("Function permitted on editable layouts only"))); } } static void check_is_editable (const db::Cell *cell) { if (cell->layout () && ! cell->layout ()->is_editable ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Function permitted on editable layouts only"))); + throw tl::Exception (tl::to_string (tr ("Function permitted on editable layouts only"))); } } @@ -745,7 +745,7 @@ static db::Shapes::shape_iterator begin_touching_shapes_um (const db::Cell *s, u { const db::Layout *layout = s->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot use a micrometer search box"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot use a micrometer search box"))); } return s->begin_touching (layer_index, db::CplxTrans (layout->dbu ()).inverted () * box, flags); } @@ -754,7 +754,7 @@ static db::Shapes::shape_iterator begin_touching_shapes_all_um (const db::Cell * { const db::Layout *layout = s->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot use a micrometer search box"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot use a micrometer search box"))); } return s->begin_touching (layer_index, db::CplxTrans (layout->dbu ()).inverted () * box, db::ShapeIterator::All); } @@ -763,7 +763,7 @@ static db::Shapes::shape_iterator begin_overlapping_shapes_um (const db::Cell *s { const db::Layout *layout = s->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot use a micrometer search box"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot use a micrometer search box"))); } return s->begin_overlapping (layer_index, db::CplxTrans (layout->dbu ()).inverted () * box, flags); } @@ -772,7 +772,7 @@ static db::Shapes::shape_iterator begin_overlapping_shapes_all_um (const db::Cel { const db::Layout *layout = s->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot use a micrometer search box"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot use a micrometer search box"))); } return s->begin_overlapping (layer_index, db::CplxTrans (layout->dbu ()).inverted () * box, db::ShapeIterator::All); } @@ -790,7 +790,7 @@ static db::Instance insert_dcell_inst_array_with_props (db::Cell *c, const db::D { const db::Layout *layout = c->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot insert a micrometer-unit cell instance array"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot insert a micrometer-unit cell instance array"))); } db::CellInstArray inst = cell_inst_array_defs::transform_array (dinst, db::CplxTrans (layout->dbu ()).inverted ()); @@ -815,7 +815,7 @@ static db::Instance replace_dinst_with_props (db::Cell *c, const db::Instance &o { const db::Layout *layout = c->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot use a micrometer-unit cell instance array"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot use a micrometer-unit cell instance array"))); } db::CellInstArray inst = cell_inst_array_defs::transform_array (dinst, db::CplxTrans (layout->dbu ()).inverted ()); @@ -890,7 +890,7 @@ static void delete_cell_property (db::Cell *c, const tl::Variant &key) db::Layout *layout = c->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot delete properties"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot delete properties"))); } std::pair nid = layout->properties_repository ().get_id_of_name (key); @@ -913,7 +913,7 @@ static void set_cell_property (db::Cell *c, const tl::Variant &key, const tl::Va db::Layout *layout = c->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot set properties"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot set properties"))); } db::property_names_id_type nid = layout->properties_repository ().prop_name_id (key); @@ -938,7 +938,7 @@ static tl::Variant get_cell_property (db::Cell *c, const tl::Variant &key) db::Layout *layout = c->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot retrieve properties"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot retrieve properties"))); } std::pair nid = layout->properties_repository ().get_id_of_name (key); @@ -1215,10 +1215,10 @@ begin_shapes_rec (const db::Cell *cell, unsigned int layer) { const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell is not inside layout"))); + throw tl::Exception (tl::to_string (tr ("Cell is not inside layout"))); } if (! layout->is_valid_layer (layer)) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid layer index"))); + throw tl::Exception (tl::to_string (tr ("Invalid layer index"))); } return db::RecursiveShapeIterator (*layout, *cell, layer); } @@ -1228,10 +1228,10 @@ begin_shapes_rec_touching (const db::Cell *cell, unsigned int layer, db::Box reg { const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell is not inside layout"))); + throw tl::Exception (tl::to_string (tr ("Cell is not inside layout"))); } if (! layout->is_valid_layer (layer)) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid layer index"))); + throw tl::Exception (tl::to_string (tr ("Invalid layer index"))); } return db::RecursiveShapeIterator (*layout, *cell, layer, region, false); } @@ -1241,10 +1241,10 @@ begin_shapes_rec_touching_um (const db::Cell *cell, unsigned int layer, db::DBox { const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell is not inside layout"))); + throw tl::Exception (tl::to_string (tr ("Cell is not inside layout"))); } if (! layout->is_valid_layer (layer)) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid layer index"))); + throw tl::Exception (tl::to_string (tr ("Invalid layer index"))); } return db::RecursiveShapeIterator (*layout, *cell, layer, db::CplxTrans (layout->dbu ()).inverted () * region, false); } @@ -1254,10 +1254,10 @@ begin_shapes_rec_overlapping (const db::Cell *cell, unsigned int layer, db::Box { const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell is not inside layout"))); + throw tl::Exception (tl::to_string (tr ("Cell is not inside layout"))); } if (! layout->is_valid_layer (layer)) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid layer index"))); + throw tl::Exception (tl::to_string (tr ("Invalid layer index"))); } return db::RecursiveShapeIterator (*layout, *cell, layer, region, true); } @@ -1267,10 +1267,10 @@ begin_shapes_rec_overlapping_um (const db::Cell *cell, unsigned int layer, db::D { const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell is not inside layout"))); + throw tl::Exception (tl::to_string (tr ("Cell is not inside layout"))); } if (! layout->is_valid_layer (layer)) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid layer index"))); + throw tl::Exception (tl::to_string (tr ("Invalid layer index"))); } return db::RecursiveShapeIterator (*layout, *cell, layer, db::CplxTrans (layout->dbu ()).inverted () * region, true); } @@ -1278,16 +1278,16 @@ begin_shapes_rec_overlapping_um (const db::Cell *cell, unsigned int layer, db::D static void copy_shapes2 (db::Cell *cell, const db::Cell &source_cell, const db::LayerMapping &layer_mapping) { if (cell == &source_cell) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot copy shapes within the same cell"))); + throw tl::Exception (tl::to_string (tr ("Cannot copy shapes within the same cell"))); } db::Layout *target_layout = cell->layout (); if (! target_layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside in a layout"))); } const db::Layout *source_layout = source_cell.layout (); if (! source_layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Source cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Source cell does not reside in a layout"))); } if (target_layout != source_layout) { @@ -1306,16 +1306,16 @@ static void copy_shapes2 (db::Cell *cell, const db::Cell &source_cell, const db: static void copy_shapes1 (db::Cell *cell, const db::Cell &source_cell) { if (cell == &source_cell) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot copy shapes within the same cell"))); + throw tl::Exception (tl::to_string (tr ("Cannot copy shapes within the same cell"))); } db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside in a layout"))); } if (layout != source_cell.layout ()) { if (! source_cell.layout ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Source cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Source cell does not reside in a layout"))); } db::LayerMapping lm; lm.create_full (*layout, *source_cell.layout ()); @@ -1330,10 +1330,10 @@ static void copy_shapes1 (db::Cell *cell, const db::Cell &source_cell) static void copy_instances (db::Cell *cell, const db::Cell &source_cell) { if (cell == &source_cell) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot copy instances within the same cell"))); + throw tl::Exception (tl::to_string (tr ("Cannot copy instances within the same cell"))); } if (cell->layout () != source_cell.layout ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Cells do not reside in the same layout"))); + throw tl::Exception (tl::to_string (tr ("Cells do not reside in the same layout"))); } for (db::Cell::const_iterator i = source_cell.begin (); ! i.at_end (); ++i) { @@ -1344,16 +1344,16 @@ static void copy_instances (db::Cell *cell, const db::Cell &source_cell) static std::vector copy_tree (db::Cell *cell, const db::Cell &source_cell) { if (cell == &source_cell) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot copy shapes within the same cell"))); + throw tl::Exception (tl::to_string (tr ("Cannot copy shapes within the same cell"))); } db::Layout *target_layout = cell->layout (); if (! target_layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside in a layout"))); } const db::Layout *source_layout = source_cell.layout (); if (! source_layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Source cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Source cell does not reside in a layout"))); } db::PropertyMapper pm (*target_layout, *source_layout); @@ -1375,16 +1375,16 @@ static std::vector copy_tree (db::Cell *cell, const db::Cel static void copy_tree_shapes2 (db::Cell *cell, const db::Cell &source_cell, const db::CellMapping &cm) { if (cell == &source_cell) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot copy shapes within the same cell"))); + throw tl::Exception (tl::to_string (tr ("Cannot copy shapes within the same cell"))); } db::Layout *target_layout = cell->layout (); if (! target_layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside in a layout"))); } const db::Layout *source_layout = source_cell.layout (); if (! source_layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Source cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Source cell does not reside in a layout"))); } db::PropertyMapper pm (*target_layout, *source_layout); @@ -1401,16 +1401,16 @@ static void copy_tree_shapes2 (db::Cell *cell, const db::Cell &source_cell, cons static void copy_tree_shapes3 (db::Cell *cell, const db::Cell &source_cell, const db::CellMapping &cm, const db::LayerMapping &lm) { if (cell == &source_cell) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot copy shapes within the same cell"))); + throw tl::Exception (tl::to_string (tr ("Cannot copy shapes within the same cell"))); } db::Layout *target_layout = cell->layout (); if (! target_layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside in a layout"))); } const db::Layout *source_layout = source_cell.layout (); if (! source_layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Source cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Source cell does not reside in a layout"))); } db::PropertyMapper pm (*target_layout, *source_layout); @@ -1424,16 +1424,16 @@ static void copy_tree_shapes3 (db::Cell *cell, const db::Cell &source_cell, cons static void move_shapes2 (db::Cell *cell, db::Cell &source_cell, const db::LayerMapping &layer_mapping) { if (cell == &source_cell) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot move shapes within the same cell"))); + throw tl::Exception (tl::to_string (tr ("Cannot move shapes within the same cell"))); } db::Layout *target_layout = cell->layout (); if (! target_layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside in a layout"))); } db::Layout *source_layout = source_cell.layout (); if (! source_layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Source cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Source cell does not reside in a layout"))); } if (target_layout != source_layout) { @@ -1454,16 +1454,16 @@ static void move_shapes2 (db::Cell *cell, db::Cell &source_cell, const db::Layer static void move_shapes1 (db::Cell *cell, db::Cell &source_cell) { if (cell == &source_cell) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot move shapes within the same cell"))); + throw tl::Exception (tl::to_string (tr ("Cannot move shapes within the same cell"))); } db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside in a layout"))); } if (layout != source_cell.layout ()) { if (! source_cell.layout ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Source cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Source cell does not reside in a layout"))); } db::LayerMapping lm; lm.create_full (*layout, *source_cell.layout ()); @@ -1479,10 +1479,10 @@ static void move_shapes1 (db::Cell *cell, db::Cell &source_cell) static void move_instances (db::Cell *cell, db::Cell &source_cell) { if (cell == &source_cell) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot move instances within the same cell"))); + throw tl::Exception (tl::to_string (tr ("Cannot move instances within the same cell"))); } if (cell->layout () != source_cell.layout ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Cells do not reside in the same layout"))); + throw tl::Exception (tl::to_string (tr ("Cells do not reside in the same layout"))); } for (db::Cell::const_iterator i = source_cell.begin (); ! i.at_end (); ++i) { @@ -1495,16 +1495,16 @@ static void move_instances (db::Cell *cell, db::Cell &source_cell) static std::vector move_tree (db::Cell *cell, db::Cell &source_cell) { if (cell == &source_cell) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot move shapes within the same cell"))); + throw tl::Exception (tl::to_string (tr ("Cannot move shapes within the same cell"))); } db::Layout *target_layout = cell->layout (); if (! target_layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside in a layout"))); } db::Layout *source_layout = source_cell.layout (); if (! source_layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Source cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Source cell does not reside in a layout"))); } db::PropertyMapper pm (*target_layout, *source_layout); @@ -1528,16 +1528,16 @@ static std::vector move_tree (db::Cell *cell, db::Cell &sou static void move_tree_shapes2 (db::Cell *cell, db::Cell &source_cell, const db::CellMapping &cm) { if (cell == &source_cell) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot move shapes within the same cell"))); + throw tl::Exception (tl::to_string (tr ("Cannot move shapes within the same cell"))); } db::Layout *target_layout = cell->layout (); if (! target_layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside in a layout"))); } db::Layout *source_layout = source_cell.layout (); if (! source_layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Source cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Source cell does not reside in a layout"))); } db::PropertyMapper pm (*target_layout, *source_layout); @@ -1554,16 +1554,16 @@ static void move_tree_shapes2 (db::Cell *cell, db::Cell &source_cell, const db:: static void move_tree_shapes3 (db::Cell *cell, db::Cell &source_cell, const db::CellMapping &cm, const db::LayerMapping &lm) { if (cell == &source_cell) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot move shapes within the same cell"))); + throw tl::Exception (tl::to_string (tr ("Cannot move shapes within the same cell"))); } db::Layout *target_layout = cell->layout (); if (! target_layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside in a layout"))); } db::Layout *source_layout = source_cell.layout (); if (! source_layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Source cell does not reside in a layout"))); + throw tl::Exception (tl::to_string (tr ("Source cell does not reside in a layout"))); } db::PropertyMapper pm (*target_layout, *source_layout); @@ -1578,7 +1578,7 @@ static void fill_region1 (db::Cell *cell, const db::Region &fr, db::cell_index_type fill_cell_index, const db::Box &fc_box, const db::Point *origin) { if (fc_box.empty () || fc_box.width () == 0 || fc_box.height () == 0) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid fill cell footprint (empty or zero width/height)"))); + throw tl::Exception (tl::to_string (tr ("Invalid fill cell footprint (empty or zero width/height)"))); } db::fill_region (cell, fr, fill_cell_index, fc_box, origin ? *origin : db::Point (), origin == 0, 0, db::Vector (), 0); } @@ -1588,7 +1588,7 @@ fill_region2 (db::Cell *cell, const db::Region &fr, db::cell_index_type fill_cel db::Region *remaining_parts, const db::Vector &fill_margin, db::Region *remaining_polygons) { if (fc_box.empty () || fc_box.width () == 0 || fc_box.height () == 0) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid fill cell footprint (empty or zero width/height)"))); + throw tl::Exception (tl::to_string (tr ("Invalid fill cell footprint (empty or zero width/height)"))); } db::fill_region (cell, fr, fill_cell_index, fc_box, origin ? *origin : db::Point (), origin == 0, remaining_parts, fill_margin, remaining_polygons); } @@ -1597,7 +1597,7 @@ static db::Instance cell_inst_dtransform_simple (db::Cell *cell, const db::Insta { const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot use a micrometer-unit transformation"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot use a micrometer-unit transformation"))); } db::CplxTrans dbu_trans (layout->dbu ()); @@ -1608,7 +1608,7 @@ static db::Instance cell_inst_dtransform_cplx (db::Cell *cell, const db::Instanc { const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot use a micrometer-unit transformation"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot use a micrometer-unit transformation"))); } db::CplxTrans dbu_trans (layout->dbu ()); @@ -1619,7 +1619,7 @@ static db::Instance cell_inst_dtransform_into_simple (db::Cell *cell, const db:: { const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot use a micrometer-unit transformation"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot use a micrometer-unit transformation"))); } db::CplxTrans dbu_trans (layout->dbu ()); @@ -1630,7 +1630,7 @@ static db::Instance cell_inst_dtransform_into_cplx (db::Cell *cell, const db::In { const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot use a micrometer-unit transformation"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot use a micrometer-unit transformation"))); } db::CplxTrans dbu_trans (layout->dbu ()); @@ -1641,7 +1641,7 @@ static void cell_dtransform_into_simple (db::Cell *cell, const db::DTrans &t) { const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot use a micrometer-unit transformation"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot use a micrometer-unit transformation"))); } db::CplxTrans dbu_trans (layout->dbu ()); @@ -1652,7 +1652,7 @@ static void cell_dtransform_into_cplx (db::Cell *cell, const db::DCplxTrans &t) { const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot use a micrometer-unit transformation"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot use a micrometer-unit transformation"))); } db::CplxTrans dbu_trans (layout->dbu ()); @@ -1663,7 +1663,7 @@ static db::DBox cell_dbbox (const db::Cell *cell) { const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot get the micrometer-unit bounding box"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot get the micrometer-unit bounding box"))); } return cell->bbox () * layout->dbu (); @@ -1673,7 +1673,7 @@ static db::DBox cell_dbbox_per_layer (const db::Cell *cell, unsigned int layer_i { const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot get the micrometer-unit bounding box"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot get the micrometer-unit bounding box"))); } return cell->bbox (layer_index) * layout->dbu (); @@ -1683,7 +1683,7 @@ static db::Cell::overlapping_iterator cell_begin_overlapping_inst_um (const db:: { const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot use a micrometer-unit search boxes"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot use a micrometer-unit search boxes"))); } db::CplxTrans dbu_trans (layout->dbu ()); @@ -1694,7 +1694,7 @@ static db::Cell::touching_iterator cell_begin_touching_inst_um (const db::Cell * { const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Cell does not reside inside a layout - cannot use a micrometer-unit search boxes"))); + throw tl::Exception (tl::to_string (tr ("Cell does not reside inside a layout - cannot use a micrometer-unit search boxes"))); } db::CplxTrans dbu_trans (layout->dbu ()); @@ -3077,7 +3077,7 @@ static double inst_dbu (const db::Instance *inst) { const db::Layout *layout = layout_ptr_const (inst); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Instance is not a part of a layout - cannot determine database unit"))); + throw tl::Exception (tl::to_string (tr ("Instance is not a part of a layout - cannot determine database unit"))); } return layout->dbu (); } @@ -3159,13 +3159,13 @@ static void set_parent_cell_ptr (db::Instance *i, db::Cell *new_parent) { db::Cell *parent = parent_cell_ptr (i); if (! parent) { - throw tl::Exception (tl::to_string (QObject::tr ("Instance does not reside in a cell"))); + throw tl::Exception (tl::to_string (tr ("Instance does not reside in a cell"))); } if (! parent->layout ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Instance does not reside in a cell"))); + throw tl::Exception (tl::to_string (tr ("Instance does not reside in a cell"))); } if (new_parent->layout () != parent->layout ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Source and target layouts are not identical"))); + throw tl::Exception (tl::to_string (tr ("Source and target layouts are not identical"))); } if (new_parent != parent) { @@ -3186,7 +3186,7 @@ static void delete_property (db::Instance *i, const tl::Variant &key) db::Layout *layout = layout_ptr (i); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Instance does not reside inside a layout - cannot delete properties"))); + throw tl::Exception (tl::to_string (tr ("Instance does not reside inside a layout - cannot delete properties"))); } std::pair nid = layout->properties_repository ().get_id_of_name (key); @@ -3208,7 +3208,7 @@ static void set_property (db::Instance *i, const tl::Variant &key, const tl::Var db::Layout *layout = layout_ptr (i); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Instance does not reside inside a layout - cannot set properties"))); + throw tl::Exception (tl::to_string (tr ("Instance does not reside inside a layout - cannot set properties"))); } db::property_names_id_type nid = layout->properties_repository ().prop_name_id (key); @@ -3232,7 +3232,7 @@ static tl::Variant get_property (const db::Instance *i, const tl::Variant &key) const db::Layout *layout = layout_ptr_const (i); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Instance does not reside inside a layout - cannot retrieve properties"))); + throw tl::Exception (tl::to_string (tr ("Instance does not reside inside a layout - cannot retrieve properties"))); } std::pair nid = layout->properties_repository ().get_id_of_name (key); @@ -3664,7 +3664,7 @@ db::Box inst_bbox_per_layer (const db::Instance *inst, unsigned int layer_index) { const db::Layout *layout = layout_ptr_const (inst); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Instance is not a part of a layout - cannot compute micrometer bounding box"))); + throw tl::Exception (tl::to_string (tr ("Instance is not a part of a layout - cannot compute micrometer bounding box"))); } db::box_convert bc (*layout, layer_index); diff --git a/src/db/db/gsiDeclDbCommonStreamOptions.cc b/src/db/db/gsiDeclDbCommonStreamOptions.cc index eb44e1004..ec8f2f4da 100644 --- a/src/db/db/gsiDeclDbCommonStreamOptions.cc +++ b/src/db/db/gsiDeclDbCommonStreamOptions.cc @@ -26,8 +26,6 @@ #include "dbLoadLayoutOptions.h" #include "gsiDecl.h" -#include - namespace dn { diff --git a/src/db/db/gsiDeclDbLayout.cc b/src/db/db/gsiDeclDbLayout.cc index 3c0f309a9..2941af667 100644 --- a/src/db/db/gsiDeclDbLayout.cc +++ b/src/db/db/gsiDeclDbLayout.cc @@ -334,7 +334,7 @@ static db::cell_index_type cell_by_name (db::Layout *l, const char *name) { std::pair c = l->cell_by_name (name); if (! c.first) { - throw tl::Exception (tl::sprintf (tl::to_string (QObject::tr ("No such cell: '%s'")), name)); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("No such cell: '%s'")), name)); } return c.second; } @@ -464,7 +464,7 @@ static db::properties_id_type properties_id (db::Layout *layout, const std::vect for (std::vector::const_iterator v = properties.begin (); v != properties.end (); ++v) { if (! v->is_list () || v->get_list ().size () != 2) { - throw tl::Exception (tl::to_string (QObject::tr ("Expected a list of pairs of variants (found at least one that is not a pair)"))); + throw tl::Exception (tl::to_string (tr ("Expected a list of pairs of variants (found at least one that is not a pair)"))); } db::property_names_id_type name_id = layout->properties_repository ().prop_name_id (v->get_list ()[0]); props.insert (std::make_pair (name_id, v->get_list () [1])); @@ -529,7 +529,7 @@ write_simple (db::Layout *layout, const std::string &filename) { db::SaveLayoutOptions options; if (! options.set_format_from_filename (filename)) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot determine format from filename"))); + throw tl::Exception (tl::to_string (tr ("Cannot determine format from filename"))); } db::Writer writer (options); @@ -555,10 +555,10 @@ static db::RecursiveShapeIterator begin_shapes (const db::Layout *layout, db::cell_index_type starting_cell, unsigned int layer) { if (! layout->is_valid_layer (layer)) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid layer index"))); + throw tl::Exception (tl::to_string (tr ("Invalid layer index"))); } if (! layout->is_valid_cell_index (starting_cell)) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid cell index"))); + throw tl::Exception (tl::to_string (tr ("Invalid cell index"))); } return db::RecursiveShapeIterator (*layout, layout->cell (starting_cell), layer); } @@ -573,10 +573,10 @@ static db::RecursiveShapeIterator begin_shapes_touching (const db::Layout *layout, db::cell_index_type starting_cell, unsigned int layer, db::Box region) { if (! layout->is_valid_layer (layer)) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid layer index"))); + throw tl::Exception (tl::to_string (tr ("Invalid layer index"))); } if (! layout->is_valid_cell_index (starting_cell)) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid cell index"))); + throw tl::Exception (tl::to_string (tr ("Invalid cell index"))); } return db::RecursiveShapeIterator (*layout, layout->cell (starting_cell), layer, region, false); } @@ -591,10 +591,10 @@ static db::RecursiveShapeIterator begin_shapes_overlapping (const db::Layout *layout, db::cell_index_type starting_cell, unsigned int layer, db::Box region) { if (! layout->is_valid_layer (layer)) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid layer index"))); + throw tl::Exception (tl::to_string (tr ("Invalid layer index"))); } if (! layout->is_valid_cell_index (starting_cell)) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid cell index"))); + throw tl::Exception (tl::to_string (tr ("Invalid cell index"))); } return db::RecursiveShapeIterator (*layout, layout->cell (starting_cell), layer, region, true); } @@ -609,10 +609,10 @@ static db::RecursiveShapeIterator begin_shapes_touching_um (const db::Layout *layout, db::cell_index_type starting_cell, unsigned int layer, db::DBox region) { if (! layout->is_valid_layer (layer)) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid layer index"))); + throw tl::Exception (tl::to_string (tr ("Invalid layer index"))); } if (! layout->is_valid_cell_index (starting_cell)) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid cell index"))); + throw tl::Exception (tl::to_string (tr ("Invalid cell index"))); } return db::RecursiveShapeIterator (*layout, layout->cell (starting_cell), layer, db::CplxTrans (layout->dbu ()).inverted () * region, false); } @@ -627,10 +627,10 @@ static db::RecursiveShapeIterator begin_shapes_overlapping_um (const db::Layout *layout, db::cell_index_type starting_cell, unsigned int layer, db::DBox region) { if (! layout->is_valid_layer (layer)) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid layer index"))); + throw tl::Exception (tl::to_string (tr ("Invalid layer index"))); } if (! layout->is_valid_cell_index (starting_cell)) { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid cell index"))); + throw tl::Exception (tl::to_string (tr ("Invalid cell index"))); } return db::RecursiveShapeIterator (*layout, layout->cell (starting_cell), layer, db::CplxTrans (layout->dbu ()).inverted () * region, true); } @@ -706,7 +706,7 @@ static std::vector pcell_names (const db::Layout *layout) static db::Cell *cell_from_index (db::Layout *ly, db::cell_index_type ci) { if (! ly->is_valid_cell_index (ci)) { - throw tl::Exception (tl::to_string (QObject::tr ("Not a valid cell index: ")) + tl::to_string (ci)); + throw tl::Exception (tl::to_string (tr ("Not a valid cell index: ")) + tl::to_string (ci)); } return &ly->cell (ci); } @@ -740,7 +740,7 @@ static db::Cell *top_cell (db::Layout *layout) if (! tc) { tc = &layout->cell (*td); } else { - throw tl::Exception (tl::to_string (QObject::tr ("The layout has multiple top cells"))); + throw tl::Exception (tl::to_string (tr ("The layout has multiple top cells"))); } ++td; } @@ -2000,7 +2000,7 @@ static db::SaveLayoutOptions *new_v () static bool set_format_from_filename (db::SaveLayoutOptions *opt, const std::string &fn) { if (! opt->set_format_from_filename (fn)) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot determine format from filename"))); + throw tl::Exception (tl::to_string (tr ("Cannot determine format from filename"))); } return true; } diff --git a/src/db/db/gsiDeclDbShape.cc b/src/db/db/gsiDeclDbShape.cc index 43b4d3b96..309adeae2 100644 --- a/src/db/db/gsiDeclDbShape.cc +++ b/src/db/db/gsiDeclDbShape.cc @@ -48,7 +48,7 @@ static double shape_dbu (const db::Shape *s) { const db::Layout *layout = layout_ptr_const (s); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape does not reside inside a layout - cannot obtain database unit"))); + throw tl::Exception (tl::to_string (tr ("Shape does not reside inside a layout - cannot obtain database unit"))); } return layout->dbu (); } @@ -57,7 +57,7 @@ static db::Shapes *shapes_checked (db::Shape *s) { db::Shapes *shapes = s->shapes (); if (! shapes) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape does not reside inside a shape container - cannot change the shape"))); + throw tl::Exception (tl::to_string (tr ("Shape does not reside inside a shape container - cannot change the shape"))); } return shapes; } @@ -65,21 +65,21 @@ static db::Shapes *shapes_checked (db::Shape *s) static void check_is_path (const db::Shape *s) { if (! s->is_path ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape is not a path"))); + throw tl::Exception (tl::to_string (tr ("Shape is not a path"))); } } static void check_is_text (const db::Shape *s) { if (! s->is_text ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape is not a text"))); + throw tl::Exception (tl::to_string (tr ("Shape is not a text"))); } } static void check_is_box (const db::Shape *s) { if (! s->is_box ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape is not a box"))); + throw tl::Exception (tl::to_string (tr ("Shape is not a box"))); } } @@ -724,17 +724,17 @@ static unsigned int shape_layer_index (const db::Shape *s) { db::Shapes *shapes = s->shapes (); if (! shapes) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape does not belong to a shape container"))); + throw tl::Exception (tl::to_string (tr ("Shape does not belong to a shape container"))); } db::Cell *cell = shapes->cell (); if (! cell) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape does not belong to a cell"))); + throw tl::Exception (tl::to_string (tr ("Shape does not belong to a cell"))); } const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape does not belong to a layout"))); + throw tl::Exception (tl::to_string (tr ("Shape does not belong to a layout"))); } for (db::Layout::layer_iterator l = layout->begin_layers (); l != layout->end_layers (); ++l) { @@ -743,28 +743,28 @@ static unsigned int shape_layer_index (const db::Shape *s) } } - throw tl::Exception (tl::to_string (QObject::tr ("Cannot identify layer of shape"))); + throw tl::Exception (tl::to_string (tr ("Cannot identify layer of shape"))); } static void set_shape_layer_index (db::Shape *s, unsigned int layer) { db::Shapes *shapes = s->shapes (); if (! shapes) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape does not belong to a shape container"))); + throw tl::Exception (tl::to_string (tr ("Shape does not belong to a shape container"))); } db::Cell *cell = shapes->cell (); if (! cell) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape does not belong to a cell"))); + throw tl::Exception (tl::to_string (tr ("Shape does not belong to a cell"))); } const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape does not belong to a layout"))); + throw tl::Exception (tl::to_string (tr ("Shape does not belong to a layout"))); } if (! layout->is_valid_layer (layer)) { - throw tl::Exception (tl::to_string (QObject::tr ("Layer index does not point to a valid layer"))); + throw tl::Exception (tl::to_string (tr ("Layer index does not point to a valid layer"))); } if (& cell->shapes (layer) != shapes) { @@ -778,17 +778,17 @@ static db::LayerProperties shape_layer (const db::Shape *s) { db::Shapes *shapes = s->shapes (); if (! shapes) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape does not belong to a shape container"))); + throw tl::Exception (tl::to_string (tr ("Shape does not belong to a shape container"))); } db::Cell *cell = shapes->cell (); if (! cell) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape does not belong to a cell"))); + throw tl::Exception (tl::to_string (tr ("Shape does not belong to a cell"))); } const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape does not belong to a layout"))); + throw tl::Exception (tl::to_string (tr ("Shape does not belong to a layout"))); } for (db::Layout::layer_iterator l = layout->begin_layers (); l != layout->end_layers (); ++l) { @@ -797,24 +797,24 @@ static db::LayerProperties shape_layer (const db::Shape *s) } } - throw tl::Exception (tl::to_string (QObject::tr ("Cannot identify layer of shape"))); + throw tl::Exception (tl::to_string (tr ("Cannot identify layer of shape"))); } static void set_shape_layer (db::Shape *s, const db::LayerProperties &lp) { db::Shapes *shapes = s->shapes (); if (! shapes) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape does not belong to a shape container"))); + throw tl::Exception (tl::to_string (tr ("Shape does not belong to a shape container"))); } db::Cell *cell = shapes->cell (); if (! cell) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape does not belong to a cell"))); + throw tl::Exception (tl::to_string (tr ("Shape does not belong to a cell"))); } const db::Layout *layout = cell->layout (); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape does not belong to a layout"))); + throw tl::Exception (tl::to_string (tr ("Shape does not belong to a layout"))); } for (db::Layout::layer_iterator l = layout->begin_layers (); l != layout->end_layers (); ++l) { @@ -834,7 +834,7 @@ static void set_shape_layer (db::Shape *s, const db::LayerProperties &lp) } - throw tl::Exception (tl::to_string (QObject::tr ("Layer info object is not giving a valid layer"))); + throw tl::Exception (tl::to_string (tr ("Layer info object is not giving a valid layer"))); } static db::Cell *cell_ptr (db::Shape *s) @@ -847,7 +847,7 @@ static void set_cell_ptr (db::Shape *s, db::Cell *new_cell) { db::Shapes *shapes = shapes_checked (s); if (layout_ptr (s) != new_cell->layout ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Current and new cell belong to a different layout"))); + throw tl::Exception (tl::to_string (tr ("Current and new cell belong to a different layout"))); } unsigned int l = shape_layer_index (s); @@ -881,7 +881,7 @@ static void delete_property (db::Shape *s, const tl::Variant &key) db::Layout *layout = layout_ptr (s); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape does not reside inside a layout - cannot delete properties"))); + throw tl::Exception (tl::to_string (tr ("Shape does not reside inside a layout - cannot delete properties"))); } std::pair nid = layout->properties_repository ().get_id_of_name (key); @@ -903,7 +903,7 @@ static void set_property (db::Shape *s, const tl::Variant &key, const tl::Varian db::Layout *layout = layout_ptr (s); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape does not reside inside a layout - cannot set properties"))); + throw tl::Exception (tl::to_string (tr ("Shape does not reside inside a layout - cannot set properties"))); } db::property_names_id_type nid = layout->properties_repository ().prop_name_id (key); @@ -927,7 +927,7 @@ static tl::Variant get_property (const db::Shape *s, const tl::Variant &key) const db::Layout *layout = layout_ptr_const (s); if (! layout) { - throw tl::Exception (tl::to_string (QObject::tr ("Shape does not reside inside a layout - cannot retrieve properties"))); + throw tl::Exception (tl::to_string (tr ("Shape does not reside inside a layout - cannot retrieve properties"))); } std::pair nid = layout->properties_repository ().get_id_of_name (key); diff --git a/src/db/db/gsiDeclDbShapes.cc b/src/db/db/gsiDeclDbShapes.cc index b3fc549f7..6ceacab9e 100644 --- a/src/db/db/gsiDeclDbShapes.cc +++ b/src/db/db/gsiDeclDbShapes.cc @@ -38,7 +38,7 @@ namespace gsi static double shapes_dbu (const db::Shapes *shapes) { if (! shapes->layout ()) { - throw tl::Exception (tl::to_string (QObject::tr ("The shapes do not reside inside a layout - cannot obtain database unit"))); + throw tl::Exception (tl::to_string (tr ("The shapes do not reside inside a layout - cannot obtain database unit"))); } return shapes->layout ()->dbu (); } diff --git a/src/db/db/gsiDeclDbTechnologies.cc b/src/db/db/gsiDeclDbTechnologies.cc index d56058631..90796b1a3 100644 --- a/src/db/db/gsiDeclDbTechnologies.cc +++ b/src/db/db/gsiDeclDbTechnologies.cc @@ -21,8 +21,11 @@ #include "gsiDecl.h" #include "dbTechnology.h" -#include "tlXMLWriter.h" -#include "tlXMLParser.h" + +#if defined(HAVE_XML) +# include "tlXMLWriter.h" +# include "tlXMLParser.h" +#endif namespace gsi { @@ -59,6 +62,7 @@ static bool has_technology (const std::string &name) return db::Technologies::instance ()->has_technology (name); } +#if defined(HAVE_XML) static std::string technologies_to_xml () { return db::Technologies::instance ()->to_xml (); @@ -90,6 +94,7 @@ static std::string technology_to_xml (const db::Technology *tech) return os.string (); } } +#endif static db::TechnologyComponent *get_component (db::Technology *tech, const std::string &name) { @@ -275,6 +280,7 @@ gsi::Class technology_decl ("db", "Technology", gsi::method ("remove_technology", &remove_technology, gsi::arg ("name"), "@brief Removes the technology with the given name\n" ) + +#if defined(HAVE_XML) gsi::method ("technologies_to_xml", &technologies_to_xml, "@brief Returns a XML representation of all technologies registered in the system\n" "\n" @@ -298,6 +304,7 @@ gsi::Class technology_decl ("db", "Technology", "\n" "See \\technology_to_xml for details." ) + +#endif gsi::method_ext ("component_names", &get_component_names, "@brief Gets the names of all components available for \\component" ) + diff --git a/src/gsi/gsi/gsiClass.cc b/src/gsi/gsi/gsiClass.cc index 6c5821f4d..17c9053c0 100644 --- a/src/gsi/gsi/gsiClass.cc +++ b/src/gsi/gsi/gsiClass.cc @@ -40,7 +40,7 @@ static gsi::Class default_cls ("tl", "EmptyClass", gsi::Methods ()); const ClassBase *fallback_cls_decl (const std::type_info &ti) { // This is the main purpose of this function: print the missing class - tl::warn << tl::to_string (QObject::tr ("Unable to find GSI class binding for: ")) << ti.name (); + tl::warn << tl::to_string (tr ("Unable to find GSI class binding for: ")) << ti.name (); return &default_cls; } diff --git a/src/gsi/gsi/gsiClass.h b/src/gsi/gsi/gsiClass.h index 4c314f425..b51944c4d 100644 --- a/src/gsi/gsi/gsiClass.h +++ b/src/gsi/gsi/gsiClass.h @@ -431,7 +431,7 @@ void _push_ptr_vector_of (SerialArgs &to, const ArgType &a, tl::Heap &heap, cons template void *_create (tl::false_tag) { - throw tl::Exception (tl::to_string (QObject::tr ("Object cannot be created here"))); + throw tl::Exception (tl::to_string (tr ("Object cannot be created here"))); return 0; } @@ -444,7 +444,7 @@ void *_create (tl::true_tag) template void *_clone (tl::false_tag, const void * /*other*/) { - throw tl::Exception (tl::to_string (QObject::tr ("Object cannot be copied here"))); + throw tl::Exception (tl::to_string (tr ("Object cannot be copied here"))); return 0; } @@ -457,7 +457,7 @@ void *_clone (tl::true_tag, const void *other) template void _assign (tl::false_tag /*has_copy_ctor*/, void *, const void *) { - throw tl::Exception (tl::to_string (QObject::tr ("Object cannot be copied here"))); + throw tl::Exception (tl::to_string (tr ("Object cannot be copied here"))); } template diff --git a/src/gsi/gsi/gsiClassBase.cc b/src/gsi/gsi/gsiClassBase.cc index f40d0a596..4f4b86758 100644 --- a/src/gsi/gsi/gsiClassBase.cc +++ b/src/gsi/gsi/gsiClassBase.cc @@ -25,9 +25,6 @@ #include "tlLog.h" #include "tlAssert.h" -#include -#include - #include #include @@ -192,7 +189,7 @@ ClassBase::create_obj_from (const ClassBase *from, void *obj) const for (method_iterator m = begin_constructors (); m != end_constructors (); ++m) { if (is_constructor_of (this, *m, from)) { if (ctor) { - throw tl::Exception (tl::to_string (QObject::tr ("There are multiple conversion constructors available to convert object of type %s to type %s")), from->name (), name ()); + throw tl::Exception (tl::to_string (tr ("There are multiple conversion constructors available to convert object of type %s to type %s")), from->name (), name ()); } ctor = *m; } @@ -242,7 +239,7 @@ static SpecialMethod * sm_default_ctor (const char *name, const gsi::ClassBase *cls) { SpecialMethod *sm = new SpecialMethod (name, - tl::to_string (QObject::tr ("@brief Creates a new object of this class\n")), + tl::to_string (tr ("@brief Creates a new object of this class\n")), false, // non-const true, // static MethodBase::DefaultCtor); @@ -261,8 +258,8 @@ static SpecialMethod * sm_destroy (const char *name) { SpecialMethod *sm = new SpecialMethod (name, - tl::to_string (QObject::tr ("@brief Explicitly destroys the object\nExplicitly destroys the object on C++ side if it was owned by the script interpreter. Subsequent access to this object will throw an exception.\n" - "If the object is not owned by the script, this method will do nothing.")), + tl::to_string (tr ("@brief Explicitly destroys the object\nExplicitly destroys the object on C++ side if it was owned by the script interpreter. Subsequent access to this object will throw an exception.\n" + "If the object is not owned by the script, this method will do nothing.")), false, // non-const false, // non-static MethodBase::Destroy); @@ -274,9 +271,9 @@ static SpecialMethod * sm_create (const char *name) { SpecialMethod *sm = new SpecialMethod (name, - tl::to_string (QObject::tr ("@brief Ensures the C++ object is created\n" - "Use this method to ensure the C++ object is created, for example to ensure that resources are allocated. " - "Usually C++ objects are created on demand and not necessarily when the script object is created.")), + tl::to_string (tr ("@brief Ensures the C++ object is created\n" + "Use this method to ensure the C++ object is created, for example to ensure that resources are allocated. " + "Usually C++ objects are created on demand and not necessarily when the script object is created.")), false, // non-const false, // non-static MethodBase::Create); @@ -288,13 +285,13 @@ static SpecialMethod * sm_keep (const char *name) { SpecialMethod *sm = new SpecialMethod (name, - tl::to_string (QObject::tr ("@brief Marks the object as no longer owned by the script side.\n" - "Calling this method will make this object no longer owned by the script's memory management. " - "Instead, the object must be managed in some other way. Usually this method may be called if it is known that some C++ object holds and manages this object. " - "Technically speaking, this method will turn the script's reference into a weak reference. " - "After the script engine decides to delete the reference, the object itself will still exist. " - "If the object is not managed otherwise, memory leaks will occur.\n\n" - "Usually it's not required to call this method. It has been introduced in version 0.24.")), + tl::to_string (tr ("@brief Marks the object as no longer owned by the script side.\n" + "Calling this method will make this object no longer owned by the script's memory management. " + "Instead, the object must be managed in some other way. Usually this method may be called if it is known that some C++ object holds and manages this object. " + "Technically speaking, this method will turn the script's reference into a weak reference. " + "After the script engine decides to delete the reference, the object itself will still exist. " + "If the object is not managed otherwise, memory leaks will occur.\n\n" + "Usually it's not required to call this method. It has been introduced in version 0.24.")), false, // non-const false, // non-static MethodBase::Keep); @@ -306,11 +303,11 @@ static SpecialMethod * sm_release (const char *name) { SpecialMethod *sm = new SpecialMethod (name, - tl::to_string (QObject::tr ("@brief Marks the object as managed by the script side.\n" - "After calling this method on an object, the script side will be responsible for the management of the object. " - "This method may be called if an object is returned from a C++ function and the object is known not to be owned by any C++ instance. " - "If necessary, the script side may delete the object if the script's reference is no longer required.\n\n" - "Usually it's not required to call this method. It has been introduced in version 0.24.")), + tl::to_string (tr ("@brief Marks the object as managed by the script side.\n" + "After calling this method on an object, the script side will be responsible for the management of the object. " + "This method may be called if an object is returned from a C++ function and the object is known not to be owned by any C++ instance. " + "If necessary, the script side may delete the object if the script's reference is no longer required.\n\n" + "Usually it's not required to call this method. It has been introduced in version 0.24.")), false, // non-const false, // non-static MethodBase::Release); @@ -322,8 +319,8 @@ static SpecialMethod * sm_is_const (const char *name) { SpecialMethod *sm = new SpecialMethod (name, - tl::to_string (QObject::tr ("@brief Returns a value indicating whether the reference is a const reference\nThis method returns true, if self is a const reference.\n" - "In that case, only const methods may be called on self.")), + tl::to_string (tr ("@brief Returns a value indicating whether the reference is a const reference\nThis method returns true, if self is a const reference.\n" + "In that case, only const methods may be called on self.")), true, // const false, // non-static MethodBase::IsConst); @@ -339,8 +336,8 @@ static SpecialMethod * sm_destroyed (const char *name) { SpecialMethod *sm = new SpecialMethod (name, - tl::to_string (QObject::tr ("@brief Returns a value indicating whether the object was already destroyed\nThis method returns true, if the object was destroyed, either explicitly or by the C++ side.\n" - "The latter may happen, if the object is owned by a C++ object which got destroyed itself.")), + tl::to_string (tr ("@brief Returns a value indicating whether the object was already destroyed\nThis method returns true, if the object was destroyed, either explicitly or by the C++ side.\n" + "The latter may happen, if the object is owned by a C++ object which got destroyed itself.")), true, // const false, // non-static MethodBase::Destroyed); @@ -356,7 +353,7 @@ static SpecialMethod * sm_dup (const char *name, const gsi::ClassBase *cls) { SpecialMethod *sm = new SpecialMethod (name, - tl::to_string (QObject::tr ("@brief Creates a copy of self\n")), + tl::to_string (tr ("@brief Creates a copy of self\n")), true, // const false, // non-static MethodBase::Dup); @@ -375,7 +372,7 @@ static SpecialMethod * sm_assign (const char *name, const gsi::ClassBase *cls) { SpecialMethod *sm = new SpecialMethod (name, - tl::to_string (QObject::tr ("@brief Assigns another object to self\n@args other")), + tl::to_string (tr ("@brief Assigns another object to self\n@args other")), false, // non-const false, // non-static MethodBase::Assign); diff --git a/src/gsi/gsi/gsiEnums.h b/src/gsi/gsi/gsiEnums.h index f0050c5d5..dcde774dc 100644 --- a/src/gsi/gsi/gsiEnums.h +++ b/src/gsi/gsi/gsiEnums.h @@ -27,7 +27,9 @@ #include "gsiDecl.h" #include "tlString.h" -#include +#if defined(HAVE_QT) +# include +#endif namespace gsi { @@ -329,6 +331,8 @@ private: EnumSpecs m_specs; }; +#if defined(HAVE_QT) + template class QFlagsClass; @@ -571,6 +575,8 @@ private: gsi::ClassExt m_enum_ext; }; +#endif + } #endif diff --git a/src/gsi/gsi/gsiExpression.cc b/src/gsi/gsi/gsiExpression.cc index ef3635dab..b86b91bc6 100644 --- a/src/gsi/gsi/gsiExpression.cc +++ b/src/gsi/gsi/gsiExpression.cc @@ -34,9 +34,6 @@ #include #include -#include -#include - namespace gsi { @@ -481,7 +478,7 @@ struct writer if (arg->is_nil () && atype.type () != gsi::T_var) { if (! (atype.is_ptr () || atype.is_cptr ())) { - throw tl::Exception (tl::to_string (QObject::tr ("Arguments of reference or direct type cannot be passed nil"))); + throw tl::Exception (tl::to_string (tr ("Arguments of reference or direct type cannot be passed nil"))); } else if (atype.is_ptr ()) { aa->write ((R *)0); } else { @@ -571,7 +568,7 @@ struct writer { if (arg->is_nil ()) { if (! (atype.is_ptr () || atype.is_cptr ())) { - throw tl::Exception (tl::to_string (QObject::tr ("Arguments of reference or direct type cannot be passed nil"))); + throw tl::Exception (tl::to_string (tr ("Arguments of reference or direct type cannot be passed nil"))); } else { aa->write ((void *)0); } @@ -592,7 +589,7 @@ struct writer { if (arg->is_nil ()) { if (! (atype.is_ptr () || atype.is_cptr ())) { - throw tl::Exception (tl::to_string (QObject::tr ("Arguments of reference or direct type cannot be passed nil"))); + throw tl::Exception (tl::to_string (tr ("Arguments of reference or direct type cannot be passed nil"))); } else { aa->write ((void *)0); } @@ -629,7 +626,7 @@ struct writer if (arg->is_nil ()) { if (atype.is_ref () || atype.is_cref ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot pass nil to reference parameters"))); + throw tl::Exception (tl::to_string (tr ("Cannot pass nil to reference parameters"))); } aa->write ((void *) 0); @@ -637,15 +634,15 @@ struct writer } else { if (! arg->is_user ()) { - throw tl::Exception (tl::sprintf (tl::to_string (QObject::tr ("Unexpected object type (expected argument of class %s)")), atype.cls ()->name ())); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Unexpected object type (expected argument of class %s)")), atype.cls ()->name ())); } const tl::VariantUserClassBase *cls = arg->user_cls (); if (!cls) { - throw tl::Exception (tl::sprintf (tl::to_string (QObject::tr ("Unexpected object type (expected argument of class %s)")), atype.cls ()->name ())); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Unexpected object type (expected argument of class %s)")), atype.cls ()->name ())); } if (cls->is_const () && (atype.is_ref () || atype.is_ptr ())) { - throw tl::Exception (tl::sprintf (tl::to_string (QObject::tr ("Cannot pass a const reference of class %s to a non-const reference or pointer parameter")), atype.cls ()->name ())); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Cannot pass a const reference of class %s to a non-const reference or pointer parameter")), atype.cls ()->name ())); } if (cls->gsi_cls ()->is_derived_from (atype.cls ())) { @@ -666,7 +663,7 @@ struct writer aa->write (new_obj); } else { - throw tl::Exception (tl::sprintf (tl::to_string (QObject::tr ("Unexpected object type (expected argument of class %s)")), atype.cls ()->name ())); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Unexpected object type (expected argument of class %s)")), atype.cls ()->name ())); } } @@ -674,15 +671,15 @@ struct writer } else { if (! arg->is_user ()) { - throw tl::Exception (tl::sprintf (tl::to_string (QObject::tr ("Unexpected object type (expected argument of class %s)")), atype.cls ()->name ())); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Unexpected object type (expected argument of class %s)")), atype.cls ()->name ())); } const tl::VariantUserClassBase *cls = arg->user_cls (); if (!cls) { - throw tl::Exception (tl::sprintf (tl::to_string (QObject::tr ("Unexpected object type (expected argument of class %s)")), atype.cls ()->name ())); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Unexpected object type (expected argument of class %s)")), atype.cls ()->name ())); } if (cls->is_const () && (atype.is_ref () || atype.is_ptr ())) { - throw tl::Exception (tl::sprintf (tl::to_string (QObject::tr ("Cannot pass a const reference of class %s to a non-const reference or pointer parameter")), atype.cls ()->name ())); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Cannot pass a const reference of class %s to a non-const reference or pointer parameter")), atype.cls ()->name ())); } if (cls->gsi_cls ()->is_derived_from (atype.cls ())) { @@ -698,7 +695,7 @@ struct writer aa->write (atype.cls ()->create_obj_from (cls->gsi_cls (), get_object (*arg))); } else { - throw tl::Exception (tl::sprintf (tl::to_string (QObject::tr ("Unexpected object type (expected argument of class %s)")), atype.cls ()->name ())); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Unexpected object type (expected argument of class %s)")), atype.cls ()->name ())); } } @@ -1061,7 +1058,7 @@ public: void execute (const tl::ExpressionParserContext & /*context*/, tl::Variant &out, const std::vector &args) const { if (! args.empty ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Class '%s' is not a function - use 'new' to create a new object")), mp_var_cls->name ()); + throw tl::Exception (tl::to_string (tr ("Class '%s' is not a function - use 'new' to create a new object")), mp_var_cls->name ()); } out = tl::Variant ((void *) 0, mp_var_cls, false); } @@ -1235,7 +1232,7 @@ VariantUserClassImpl::execute (const tl::ExpressionParserContext &context, tl::V if (mp_object_cls == 0 && method == "is_a") { if (args.size () != 1) { - throw tl::EvalError (tl::to_string (QObject::tr ("'is_a' method requires exactly one argument")), context); + throw tl::EvalError (tl::to_string (tr ("'is_a' method requires exactly one argument")), context); } bool ret = false; @@ -1273,7 +1270,7 @@ VariantUserClassImpl::execute (const tl::ExpressionParserContext &context, tl::V } else if (mp_object_cls == 0 && method == "dup") { if (args.size () != 0) { - throw tl::EvalError (tl::to_string (QObject::tr ("'dup' method does not allow arguments")), context); + throw tl::EvalError (tl::to_string (tr ("'dup' method does not allow arguments")), context); } void *obj = mp_cls->create (); @@ -1338,7 +1335,7 @@ special_method_impl (gsi::MethodBase::special_method_type smt, tl::Variant &self } else if (smt == gsi::MethodBase::Assign) { tl_assert (args.size () == 1); if (!args.front ().is_user () || self.user_cls () != args.front ().user_cls ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Source and target object must be of the same type for assignment"))); + throw tl::Exception (tl::to_string (tr ("Source and target object must be of the same type for assignment"))); } self.user_assign (args.front ()); } else if (smt == gsi::MethodBase::Dup) { @@ -1380,7 +1377,7 @@ VariantUserClassImpl::execute_gsi (const tl::ExpressionParserContext & /*context } if (cls == 0) { - throw tl::Exception (tl::to_string (QObject::tr ("Unknown method")) + " '" + method + "' of class '" + clsact->name () + "'"); + throw tl::Exception (tl::to_string (tr ("Unknown method")) + " '" + method + "' of class '" + clsact->name () + "'"); } const gsi::MethodBase *meth = 0; @@ -1389,7 +1386,7 @@ VariantUserClassImpl::execute_gsi (const tl::ExpressionParserContext & /*context for (ExpressionMethodTableEntry::method_iterator m = mt->begin (mid); m != mt->end (mid); ++m) { if ((*m)->is_signal()) { - throw tl::Exception (tl::sprintf (tl::to_string (QObject::tr ("Signals are not supported inside expressions (event %s)")), method.c_str ())); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Signals are not supported inside expressions (event %s)")), method.c_str ())); } else if ((*m)->is_callback()) { // ignore callbacks } else if ((*m)->compatible_with_num_args (args.size ())) { @@ -1414,7 +1411,7 @@ VariantUserClassImpl::execute_gsi (const tl::ExpressionParserContext & /*context nargs_s += tl::to_string (*na); } - throw tl::Exception (tl::sprintf (tl::to_string (QObject::tr ("Invalid number of arguments for method %s, class %s (got %d, expected %s)")), method.c_str (), mp_cls->name (), int (args.size ()), nargs_s)); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Invalid number of arguments for method %s, class %s (got %d, expected %s)")), method.c_str (), mp_cls->name (), int (args.size ()), nargs_s)); } // more than one candidate -> refine by checking the arguments @@ -1481,21 +1478,21 @@ VariantUserClassImpl::execute_gsi (const tl::ExpressionParserContext & /*context } if (! meth) { - throw tl::Exception (tl::sprintf (tl::to_string (QObject::tr ("No method with matching arguments for method %s, class %s")), method.c_str (), mp_cls->name ())); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("No method with matching arguments for method %s, class %s")), method.c_str (), mp_cls->name ())); } if (candidates > 1) { - throw tl::Exception (tl::sprintf (tl::to_string (QObject::tr ("Ambiguous overload variants for method %s, class %s - multiple method declarations match arguments")), method.c_str (), mp_cls->name ())); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Ambiguous overload variants for method %s, class %s - multiple method declarations match arguments")), method.c_str (), mp_cls->name ())); } if (m_is_const && ! meth->is_const ()) { - throw tl::Exception (tl::sprintf (tl::to_string (QObject::tr ("Cannot call non-const method %s, class %s on a const reference")), method.c_str (), mp_cls->name ())); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Cannot call non-const method %s, class %s on a const reference")), method.c_str (), mp_cls->name ())); } if (meth->is_signal ()) { // TODO: events not supported yet - throw tl::Exception (tl::sprintf (tl::to_string (QObject::tr ("Signals not supported yet (method %s, class %s)")), method.c_str (), mp_cls->name ())); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Signals not supported yet (method %s, class %s)")), method.c_str (), mp_cls->name ())); } else if (meth->smt () != gsi::MethodBase::None) { @@ -1518,7 +1515,7 @@ VariantUserClassImpl::execute_gsi (const tl::ExpressionParserContext & /*context if (meth->ret_type ().is_iter ()) { // TODO: iterators not supported yet - throw tl::Exception (tl::sprintf (tl::to_string (QObject::tr ("Iterators not supported yet (method %s, class %s)")), method.c_str (), mp_cls->name ())); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Iterators not supported yet (method %s, class %s)")), method.c_str (), mp_cls->name ())); } else { out = tl::Variant (); gsi::do_on_type () (meth->ret_type ().type (), &out, &retlist, meth->ret_type (), &heap); diff --git a/src/gsi/gsi/gsiMethods.h b/src/gsi/gsi/gsiMethods.h index d4bb408bd..8b1cc2ef5 100644 --- a/src/gsi/gsi/gsiMethods.h +++ b/src/gsi/gsi/gsiMethods.h @@ -38,7 +38,7 @@ struct NoArgumentsAllowedException : public tl::Exception { NoArgumentsAllowedException () - : tl::Exception (tl::to_string (QObject::tr ("Method does not allow arguments"))) + : tl::Exception (tl::to_string (tr ("Method does not allow arguments"))) { } }; @@ -46,7 +46,7 @@ struct NeedsArgumentsException : public tl::Exception { NeedsArgumentsException (unsigned int got, unsigned int want) - : tl::Exception (tl::sprintf (tl::to_string (QObject::tr ("Method requires %d arguments, got %d")), want, got)) + : tl::Exception (tl::sprintf (tl::to_string (tr ("Method requires %d arguments, got %d")), want, got)) { } }; @@ -54,7 +54,7 @@ struct IncompatibleReturnTypeException : public tl::Exception { IncompatibleReturnTypeException (const ArgType &got, const ArgType &want) - : tl::Exception (tl::to_string (QObject::tr ("Incompatible return types: got '")) + got.to_string () + tl::to_string (QObject::tr ("', want '")) + want.to_string () + "'") + : tl::Exception (tl::to_string (tr ("Incompatible return types: got '")) + got.to_string () + tl::to_string (tr ("', want '")) + want.to_string () + "'") { } }; diff --git a/src/gsi/gsi/gsiObject.cc b/src/gsi/gsi/gsiObject.cc index 882b97602..7d11f0582 100644 --- a/src/gsi/gsi/gsiObject.cc +++ b/src/gsi/gsi/gsiObject.cc @@ -64,14 +64,14 @@ Proxy::destroy () } if (!m_can_destroy && m_obj) { - throw tl::Exception (tl::to_string (QObject::tr ("Object cannot be destroyed explicitly"))); + throw tl::Exception (tl::to_string (tr ("Object cannot be destroyed explicitly"))); } // first create the object if it was not created yet and check if it has not been // destroyed already (the former is to ensure that the object is created at least) if (! m_obj) { if (m_destroyed) { - throw tl::Exception (tl::to_string (QObject::tr ("Object has been destroyed already"))); + throw tl::Exception (tl::to_string (tr ("Object has been destroyed already"))); } else { m_obj = m_cls_decl->create (); m_owned = true; @@ -203,7 +203,7 @@ Proxy::obj () { if (! m_obj) { if (m_destroyed) { - throw tl::Exception (tl::to_string (QObject::tr ("Object has been destroyed already"))); + throw tl::Exception (tl::to_string (tr ("Object has been destroyed already"))); } else { // delayed creation of a detached C++ object .. set(m_cls_decl->create (), true, false, true); diff --git a/src/gsi/gsi/gsiSerialisation.h b/src/gsi/gsi/gsiSerialisation.h index 31cdecc3e..606e8781a 100644 --- a/src/gsi/gsi/gsiSerialisation.h +++ b/src/gsi/gsi/gsiSerialisation.h @@ -30,6 +30,7 @@ #include #include +#include namespace gsi { @@ -78,7 +79,7 @@ struct GSI_PUBLIC ArglistUnderflowException : public tl::Exception { ArglistUnderflowException () - : tl::Exception (tl::to_string (QObject::tr ("Too few arguments or no return value supplied"))) + : tl::Exception (tl::to_string (tr ("Too few arguments or no return value supplied"))) { } }; @@ -89,7 +90,7 @@ struct GSI_PUBLIC NilPointerToReference : public tl::Exception { NilPointerToReference () - : tl::Exception (tl::to_string (QObject::tr ("nil object passed to a reference"))) + : tl::Exception (tl::to_string (tr ("nil object passed to a reference"))) { } }; @@ -655,6 +656,8 @@ class GSI_PUBLIC_TEMPLATE StringAdaptorImpl { }; +#if defined(HAVE_QT) + /** * @brief Specialization for QByteArray */ @@ -871,6 +874,8 @@ private: mutable QByteArray m_s_utf8; }; +#endif + /** * @brief Specialization for std::string */ @@ -1108,6 +1113,8 @@ class GSI_PUBLIC_TEMPLATE VariantAdaptorImpl { }; +#if defined(HAVE_QT) + /** * @brief Specialization for QVariant */ @@ -1178,6 +1185,8 @@ private: QVariant m_v; }; +#endif + /** * @brief Specialization for tl::Variant */ @@ -1407,6 +1416,8 @@ void push_vector (std::set &v, const X &x) v.insert (x); } +#if defined(HAVE_QT) + template void push_vector (QVector &v, const X &x) { @@ -1430,6 +1441,8 @@ void push_vector (QSet &v, const X &x) v.insert (x); } +#endif + /** * @brief Implementation of the generic adaptor for a specific container */ @@ -1651,6 +1664,8 @@ struct map_access } }; +#if defined(HAVE_QT) + /** * @brief Specialization for QMap */ @@ -1705,6 +1720,8 @@ struct map_access > } }; +#endif + /** * @brief Implementation of the generic iterator adaptor for a specific container */ diff --git a/src/gsi/gsi/gsiSignals.h b/src/gsi/gsi/gsiSignals.h index 896f7980a..9bd43be7e 100644 --- a/src/gsi/gsi/gsiSignals.h +++ b/src/gsi/gsi/gsiSignals.h @@ -38,7 +38,9 @@ # undef access #endif -#include +#if defined(HAVE_QT) +# include +#endif /** * @brief A signal exposure framework @@ -229,6 +231,8 @@ public: // --------------------------------------------------------------------------------------- // Adaptors for Qt signals +#if defined(HAVE_QT) + /** * @brief A base class for Qt signals * This object will act as a connector for Qt signals: when a signal is bound, this adaptor @@ -687,6 +691,8 @@ inline Methods qt_signal (const char *signal, const std::string &name, ->def_arg (s1)->def_arg (s2)->def_arg (s3)->def_arg (s4)->def_arg (s5)->def_arg (s6)->def_arg (s7)->def_arg (s8)->def_arg (s9)); } +#endif + // --------------------------------------------------------------------------------------- // Adaptors for tl::event diff --git a/src/gsi/gsi/gsiTypes.h b/src/gsi/gsi/gsiTypes.h index 5f6be7439..89d40bd0d 100644 --- a/src/gsi/gsi/gsiTypes.h +++ b/src/gsi/gsi/gsiTypes.h @@ -34,6 +34,7 @@ #include #include +#if defined(HAVE_QT) #include #include #include @@ -43,6 +44,7 @@ #include #include #include +#endif namespace tl { @@ -422,11 +424,13 @@ template <> struct type_traits<__int128> : generic_type_trait template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; +#if defined(HAVE_QT) template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; -template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; +#endif +template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; @@ -452,11 +456,13 @@ template <> struct type_traits : generic_type_trait template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; +#if defined(HAVE_QT) template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; -template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; +#endif +template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; @@ -479,11 +485,13 @@ template <> struct type_traits<__int128 &> : generic_type_trait template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; +#if defined(HAVE_QT) template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; -template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; +#endif +template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; @@ -507,11 +515,13 @@ template <> struct type_traits : generic_type_trait template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; +#if defined(HAVE_QT) template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; -template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; +#endif +template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; @@ -535,11 +545,13 @@ template <> struct type_traits<__int128 *> : generic_type_trait template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; +#if defined(HAVE_QT) template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; -template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; +#endif +template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; @@ -615,6 +627,8 @@ struct type_traits static const ClassBase *cls_decl () { return gsi::cls_decl (); } }; +#if defined(HAVE_QT) + template <> struct type_traits : generic_type_traits @@ -755,6 +769,88 @@ struct type_traits< QVector * > typedef X inner_type; }; +template +struct type_traits< QHash > + : generic_type_traits +{ + typedef X inner_k_type; + typedef Y inner_type; +}; + +template +struct type_traits< const QHash & > + : generic_type_traits +{ + typedef X inner_k_type; + typedef Y inner_type; +}; + +template +struct type_traits< QHash & > + : generic_type_traits +{ + typedef X inner_k_type; + typedef Y inner_type; +}; + +template +struct type_traits< const QHash * > + : generic_type_traits +{ + typedef X inner_k_type; + typedef Y inner_type; +}; + +template +struct type_traits< QHash * > + : generic_type_traits +{ + typedef X inner_k_type; + typedef Y inner_type; +}; + +template +struct type_traits< QMap > + : generic_type_traits +{ + typedef X inner_k_type; + typedef Y inner_type; +}; + +template +struct type_traits< const QMap & > + : generic_type_traits +{ + typedef X inner_k_type; + typedef Y inner_type; +}; + +template +struct type_traits< QMap & > + : generic_type_traits +{ + typedef X inner_k_type; + typedef Y inner_type; +}; + +template +struct type_traits< const QMap * > + : generic_type_traits +{ + typedef X inner_k_type; + typedef Y inner_type; +}; + +template +struct type_traits< QMap * > + : generic_type_traits +{ + typedef X inner_k_type; + typedef Y inner_type; +}; + +#endif + template struct type_traits< std::set > : generic_type_traits @@ -853,86 +949,6 @@ struct type_traits< std::list * > typedef X inner_type; }; -template -struct type_traits< QHash > - : generic_type_traits -{ - typedef X inner_k_type; - typedef Y inner_type; -}; - -template -struct type_traits< const QHash & > - : generic_type_traits -{ - typedef X inner_k_type; - typedef Y inner_type; -}; - -template -struct type_traits< QHash & > - : generic_type_traits -{ - typedef X inner_k_type; - typedef Y inner_type; -}; - -template -struct type_traits< const QHash * > - : generic_type_traits -{ - typedef X inner_k_type; - typedef Y inner_type; -}; - -template -struct type_traits< QHash * > - : generic_type_traits -{ - typedef X inner_k_type; - typedef Y inner_type; -}; - -template -struct type_traits< QMap > - : generic_type_traits -{ - typedef X inner_k_type; - typedef Y inner_type; -}; - -template -struct type_traits< const QMap & > - : generic_type_traits -{ - typedef X inner_k_type; - typedef Y inner_type; -}; - -template -struct type_traits< QMap & > - : generic_type_traits -{ - typedef X inner_k_type; - typedef Y inner_type; -}; - -template -struct type_traits< const QMap * > - : generic_type_traits -{ - typedef X inner_k_type; - typedef Y inner_type; -}; - -template -struct type_traits< QMap * > - : generic_type_traits -{ - typedef X inner_k_type; - typedef Y inner_type; -}; - template struct type_traits< std::map > : generic_type_traits @@ -1696,7 +1712,7 @@ struct GSI_PUBLIC IncompatibleTypeException : public tl::Exception { IncompatibleTypeException (const ArgType &got, const ArgType &want) - : tl::Exception (tl::to_string (QObject::tr ("Incompatible types: got '")) + got.to_string () + tl::to_string (QObject::tr ("', want '")) + want.to_string () + "'") + : tl::Exception (tl::to_string (tr ("Incompatible types: got '")) + got.to_string () + tl::to_string (tr ("', want '")) + want.to_string () + "'") { } }; diff --git a/src/gsi/gsi_test/gsiTest.cc b/src/gsi/gsi_test/gsiTest.cc index 20e5e1fff..74ba226ac 100644 --- a/src/gsi/gsi_test/gsiTest.cc +++ b/src/gsi/gsi_test/gsiTest.cc @@ -405,7 +405,7 @@ X::X () } X::X (const char *x) - : m_s (QString::fromUtf8(x)) + : m_s (x) { ++s_xinst; } @@ -467,24 +467,24 @@ std::vector X::vx_ptr () return r; } -QString X::cls_name () const +std::string X::cls_name () const { - return QString::fromUtf8 ("X"); + return "X"; } -QString X::s () const +std::string X::s () const { return m_s; } -void X::set_s (const QString &s) +void X::set_s (const std::string &s) { m_s = s; } void X::set_si (int v) { - m_s = QString::number (v + 1); + m_s = tl::to_string (v + 1); } // ---------------------------------------------------------------- @@ -594,9 +594,9 @@ std::vector Y::vy_ptr() return r; } -QString Y::cls_name() const +std::string Y::cls_name() const { - return QString::fromUtf8 ("Y"); + return "Y"; } int Y::i () const @@ -619,9 +619,9 @@ YY::YY (const char *x) // .. nothing yet .. } -QString YY::cls_name() const +std::string YY::cls_name() const { - return QString::fromUtf8 ("YY"); + return "YY"; } // ---------------------------------------------------------------- @@ -700,6 +700,8 @@ std::string Z_P::f_with_yy (const std::string &s) // ---------------------------------------------------------------- // Implementation of SQ +#if defined(HAVE_QT) + SQ::SQ () : m_tag (0) { @@ -726,6 +728,8 @@ void SQ::trigger_s2 (const QString &s) emit s2 (s, this); } +#endif + // ---------------------------------------------------------------- // Implementation of SE @@ -750,7 +754,7 @@ void SE::trigger_s1 (int x) s1 (x); } -void SE::trigger_s2 (const QString &s) +void SE::trigger_s2 (const std::string &s) { s2 (s, this); } @@ -764,7 +768,9 @@ static gsi::Enum decl_enum ("", "Enum", gsi::enum_const ("c", Enum_c) ); +#if defined(HAVE_QT) static gsi::QFlagsClass decl_qflags_enum ("", "Enums"); +#endif static gsi::Class decl_a ("", "A", gsi::constructor ("new_a|new", &a_ctor) + @@ -781,6 +787,7 @@ static gsi::Class decl_a ("", "A", gsi::method ("set_ecref", &A::set_ecref) + gsi::method ("mod_eptr", &A::mod_eptr) + gsi::method ("mod_eref", &A::mod_eref) + +#if defined(HAVE_QT) gsi::method ("get_ef", &A::get_ef) + gsi::method ("get_efptr", &A::get_efptr) + gsi::method ("get_efcptr", &A::get_efcptr) + @@ -793,6 +800,7 @@ static gsi::Class decl_a ("", "A", gsi::method ("set_efcref", &A::set_efcref) + gsi::method ("mod_efptr", &A::mod_efptr) + gsi::method ("mod_efref", &A::mod_efref) + +#endif gsi::method ("push_ev", &A::push_ev) + gsi::method ("ev", &A::ev) + gsi::method ("af=", &A::set_af) + @@ -805,15 +813,19 @@ static gsi::Class decl_a ("", "A", gsi::method ("a1c", &A::a1c) + gsi::method ("a2", &A::a2) + gsi::method ("a3", &A::a3) + +#if defined(HAVE_QT) gsi::method ("a3_qba", &A::a3_qba) + gsi::method ("a3_qstr", &A::a3_qstr) + gsi::method ("a3_qstrref", &A::a3_qstrref) + +#endif gsi::method ("a4", &A::a4) + gsi::method ("a5|n=", &A::a5) + gsi::method ("a10_d", &A::a10_d) + +#if defined(HAVE_QT) gsi::method ("a10_d_qba", &A::a10_d_qba) + gsi::method ("a10_d_qstr", &A::a10_d_qstr) + gsi::method ("a10_d_qstrref", &A::a10_d_qstrref) + +#endif gsi::method ("*a10_prot", &A::a10_d) + gsi::method ("a10_f", &A::a10_f) + gsi::method ("a10_fptr", &A::a10_fptr) + @@ -1006,7 +1018,9 @@ static gsi::Class decl_b ("", "B", gsi::method ("set_ls", &B::set_ls) + gsi::method ("push_ss", &B::push_ss) + gsi::method ("ss", &B::ss) + - gsi::method ("set_ss", &B::set_ss) + + gsi::method ("set_ss", &B::set_ss) +#if defined(HAVE_QT) + + gsi::method ("push_qls", &B::push_qls) + gsi::method ("qls", &B::qls) + gsi::method ("set_qls", &B::set_qls) + @@ -1028,6 +1042,7 @@ static gsi::Class decl_b ("", "B", gsi::method ("insert_qhash_is", &B::insert_qhash_is) + gsi::method ("qhash_is", &B::qhash_is) + gsi::method ("set_qhash_is", &B::set_qhash_is) +#endif ); // extending B @@ -1153,6 +1168,7 @@ gsi::Class decl_z ("", "Z", gsi::method ("set_x_keep", &Z_P::set_x_keep) ); +#if defined(HAVE_QT) gsi::Class decl_sq ("", "SQ", gsi::method ("trigger_s0", &SQ::trigger_s0) + gsi::method ("trigger_s1", &SQ::trigger_s1) + @@ -1163,6 +1179,7 @@ gsi::Class decl_sq ("", "SQ", gsi::qt_signal ("s1(int)", "s1") + gsi::qt_signal ("s2(const QString &, SQ *)", "s2") ); +#endif gsi::Class decl_se ("", "SE", gsi::method ("trigger_s0", &SE::trigger_s0) + diff --git a/src/gsi/gsi_test/gsiTest.h b/src/gsi/gsi_test/gsiTest.h index 6ffc30c94..09836094e 100644 --- a/src/gsi/gsi_test/gsiTest.h +++ b/src/gsi/gsi_test/gsiTest.h @@ -37,7 +37,9 @@ #include "tlVariant.h" #include "tlString.h" -#include +#if defined(HAVE_QT) +# include +#endif namespace gsi_test { @@ -113,6 +115,7 @@ struct A int a3 (const std::string &x) { return x.size (); } +#if defined(HAVE_QT) int a3_qstr (const QString &x) { return x.size (); } @@ -122,6 +125,7 @@ struct A int a3_qba (const QByteArray &x) { return x.size (); } +#endif double a4 (const std::vector &d) { m_d = d; return d.back (); @@ -152,9 +156,11 @@ struct A int a9b (bool f) const { return f ? 5 : -5; } std::string a10_d (double f) { return tl::to_string (f); } +#if defined(HAVE_QT) QByteArray a10_d_qba (double f) { return tl::to_qstring (tl::to_string (f)).toUtf8 (); } QString a10_d_qstr (double f) { return tl::to_qstring (tl::to_string (f)); } QStringRef a10_d_qstrref (double f) { m_s = tl::to_qstring (tl::to_string (f)); return QStringRef (&m_s); } +#endif std::string a10_f (float f) { return tl::to_string(f); } std::string a10_fptr (float *f) { if (f) { *f += 5; return tl::to_string(*f); } else { return "nil"; } } std::string a10_dptr (double *f) { if (f) { *f += 6; return tl::to_string(*f); } else { return "nil"; } } @@ -212,6 +218,7 @@ struct A void push_ev (Enum e) { ee.push_back (e); } const std::vector &ev () const { return ee; } +#if defined(HAVE_QT) QFlags get_ef () const { return ef; } QFlags *get_efptr () { return int (ef) == 0 ? 0 : &ef; } const QFlags *get_efcptr () const { return int (ef) == 0 ? 0 : &ef; } @@ -224,6 +231,7 @@ struct A void set_efcref (const QFlags &_ef) { ef = _ef; } void mod_efptr (QFlags *_ef, Enum ee) { if (_ef) *_ef |= ee; } void mod_efref (QFlags &_ef, Enum ee) { _ef |= ee; } +#endif const char *a_vp1 (void *s) { return (const char *)s; } void *a_vp2 () { return (void *)"abc"; } @@ -238,9 +246,13 @@ struct A int n; bool f; Enum e; +#if defined(HAVE_QT) QFlags ef; +#endif std::vector ee; +#if defined(HAVE_QT) QString m_s; +#endif }; @@ -774,6 +786,7 @@ struct B std::set ss () { return m_ss; } void set_ss (std::set v) { m_ss = v; } +#if defined(HAVE_QT) static void push_qls (QList &m, const QString &v) { m.push_back (v); } QList qls () { return m_qls; } void set_qls (QList v) { m_qls = v; } @@ -801,6 +814,7 @@ struct B static void insert_qhash_is (QHash &m, int k, const QString &v) { m.insert (k, v); } QHash qhash_is () { return m_qhash_is; } void set_qhash_is (QHash v) { m_qhash_is = v; } +#endif std::string m; A a; @@ -819,6 +833,7 @@ struct B std::vector > m_vvs; std::list m_ls; std::set m_ss; +#if defined_HAVE_QT QList m_qls; QList m_qlv; QStringList m_qsl; @@ -826,6 +841,7 @@ struct B QSet m_qss; QMap m_qmap_is; QHash m_qhash_is; +#endif static B *b_inst; }; @@ -950,13 +966,13 @@ public: static std::vector vx_cptr (); static std::vector vx_ptr (); - virtual QString cls_name () const; - QString s () const; - void set_s (const QString &s); + virtual std::string cls_name () const; + std::string s () const; + void set_s (const std::string &s); void set_si (int v); protected: - QString m_s; + std::string m_s; private: static std::auto_ptr sp_a, sp_b; @@ -984,7 +1000,7 @@ public: static std::vector vy_cptr (); static std::vector vy0_ptr (); static std::vector vy_ptr (); - virtual QString cls_name () const; + virtual std::string cls_name () const; int i () const; private: @@ -1018,7 +1034,7 @@ class YY : public Y public: YY (); YY (const char *x); - virtual QString cls_name() const; + virtual std::string cls_name() const; }; class Z @@ -1097,6 +1113,7 @@ public: gsi::Callback f_cb; }; +#if defined(HAVE_QT) class SQ : public QObject { @@ -1122,6 +1139,7 @@ signals: private: int m_tag; }; +#endif class SE : public tl::Object @@ -1131,7 +1149,7 @@ public: void trigger_s0 (); void trigger_s1 (int x); - void trigger_s2 (const QString &s); + void trigger_s2 (const std::string &s); void set_tag (int x); int tag () const @@ -1142,7 +1160,7 @@ public: public: tl::event<> s0; tl::event s1; - tl::event s2; + tl::event s2; private: int m_tag; @@ -1155,9 +1173,11 @@ 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/klayout.pri b/src/klayout.pri index 96a4595ad..0316acfeb 100644 --- a/src/klayout.pri +++ b/src/klayout.pri @@ -68,16 +68,26 @@ QMAKE_CXXFLAGS_WARN_ON += \ -Wno-deprecated-declarations \ -Wno-reserved-user-defined-literal \ -QT += network xml sql +equals(HAVE_QT, "0") { + + QT = -equals(HAVE_QT5, "1") { - QT += designer printsupport - equals(HAVE_QTBINDINGS, "1") { - QT += multimedia multimediawidgets xmlpatterns svg gui - } } else { - # questionable: use uitools instead? - CONFIG += designer + + DEFINES += HAVE_QT + DEFINES += HAVE_XML + QT += network xml sql + + equals(HAVE_QT5, "1") { + QT += designer printsupport + equals(HAVE_QTBINDINGS, "1") { + QT += multimedia multimediawidgets xmlpatterns svg gui + } + } else { + # questionable: use uitools instead? + CONFIG += designer + } + } # only support the required symbols for shared object load performance diff --git a/src/rdb/rdb/gsiDeclRdb.cc b/src/rdb/rdb/gsiDeclRdb.cc index 7b5070471..4e2e5e3c6 100644 --- a/src/rdb/rdb/gsiDeclRdb.cc +++ b/src/rdb/rdb/gsiDeclRdb.cc @@ -784,6 +784,7 @@ Class decl_RdbItem ("rdb", "RdbItem", "@args tags\n" "@param tags A comma-separated list of tags\n" ) + +#if defined(HAVE_QT) gsi::method ("image_str", &rdb::Item::image_str, "@brief Gets the image associated with this item as a string\n" "@return A base64-encoded image file (usually in PNG format)\n" @@ -793,6 +794,7 @@ Class decl_RdbItem ("rdb", "RdbItem", "@args image\n" "@param image A base64-encoded image file (preferably in PNG format)\n" ) + +#endif /* Not supported yet: gsi::method ("multiplicity", &rdb::Item::multiplicity, "@brief Gets the item's multiplicity\n" @@ -1061,10 +1063,10 @@ void create_items_from_edge_pair_array (rdb::Database *db, rdb::id_type cell_id, static rdb::Item *create_item (rdb::Database *db, rdb::id_type cell_id, rdb::id_type cat_id) { if (! db->cell_by_id (cell_id)) { - throw tl::Exception (tl::to_string (QObject::tr ("Not a valid cell ID: %1").arg (cell_id))); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Not a valid cell ID: %d")), cell_id)); } if (! db->category_by_id (cat_id)) { - throw tl::Exception (tl::to_string (QObject::tr ("Not a valid category ID: %1").arg (cat_id))); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Not a valid category ID: %d")), cat_id)); } return db->create_item (cell_id, cat_id); } diff --git a/src/rdb/rdb/rdb.cc b/src/rdb/rdb/rdb.cc index b62b16292..733f24196 100644 --- a/src/rdb/rdb/rdb.cc +++ b/src/rdb/rdb/rdb.cc @@ -35,10 +35,11 @@ #include "dbText.h" #include "dbShape.h" -#include -#include -#include -#include +#if defined(HAVE_QT) +# include +# include +# include +#endif #include #include @@ -247,7 +248,7 @@ ValueBase::create_from_string (tl::Extractor &ex) return new Value (v); } else { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid value string at '...%s'")), ex.skip ()); + throw tl::Exception (tl::to_string (tr ("Invalid value string at '...%s'")), ex.skip ()); } } @@ -542,7 +543,7 @@ Reference::set_parent_cell_qname (const std::string &qname) tl_assert (mp_database != 0); const Cell *cell = mp_database->cell_by_qname (qname); if (! cell) { - throw tl::Exception (tl::to_string (QObject::tr ("%s is not a valid cell name or name/variant combination")), qname); + throw tl::Exception (tl::to_string (tr ("%s is not a valid cell name or name/variant combination")), qname); } m_parent_cell_id = cell->id (); } @@ -783,26 +784,26 @@ Tags::has_tag (const std::string &name, bool user_tag) const // Item implementation Item::Item (Items *items) - : m_cell_id (0), m_category_id (0), m_multiplicity (1), m_visited (false), mp_database (items->database ()), mp_image (0) + : m_cell_id (0), m_category_id (0), m_multiplicity (1), m_visited (false), mp_database (items->database ()) { // .. nothing yet .. } Item::Item () - : m_cell_id (0), m_category_id (0), m_multiplicity (1), m_visited (false), mp_database (0), mp_image (0) + : m_cell_id (0), m_category_id (0), m_multiplicity (1), m_visited (false), mp_database (0) { // .. nothing yet .. } Item::Item (const Item &d) - : tl::Object (d), m_cell_id (0), m_category_id (0), m_multiplicity (1), m_visited (false), mp_database (d.mp_database), mp_image (0) + : tl::Object (d), m_cell_id (0), m_category_id (0), m_multiplicity (1), m_visited (false), mp_database (d.mp_database) { operator= (d); } Item::~Item () { - set_image (0); + // .. nothing yet .. } Item &Item::operator= (const Item &d) @@ -815,13 +816,14 @@ Item &Item::operator= (const Item &d) m_multiplicity = d.m_multiplicity; m_tag_ids = d.m_tag_ids; +#if defined(HAVE_QT) if (mp_image) { - delete mp_image; - mp_image = 0; + mp_image.reset (0); } - if (d.mp_image) { - mp_image = new QImage (*d.mp_image); + if (d.mp_image.get ()) { + mp_image.reset (new QImage (*d.mp_image)); } +#endif } return *this; @@ -871,7 +873,7 @@ Item::set_cell_qname (const std::string &qname) tl_assert (mp_database != 0); const Cell *cell = mp_database->cell_by_qname (qname); if (! cell) { - throw tl::Exception (tl::to_string (QObject::tr ("%s is not a valid cell name or name/variant combination")), qname); + throw tl::Exception (tl::to_string (tr ("%s is not a valid cell name or name/variant combination")), qname); } m_cell_id = cell->id (); } @@ -891,7 +893,7 @@ Item::set_category_name (const std::string &path) tl_assert (mp_database != 0); const Category *category = mp_database->categories ().category_by_name (path.c_str ()); if (! category) { - throw tl::Exception (tl::to_string (QObject::tr ("%s is not a valid category path")), path); + throw tl::Exception (tl::to_string (tr ("%s is not a valid category path")), path); } m_category_id = category->id (); } @@ -942,22 +944,17 @@ Item::set_tag_str (const std::string &tags) } } +#if defined(HAVE_QT) void Item::set_image (QImage *image) { - if (mp_image) { - delete mp_image; - mp_image = 0; - } - if (image) { - mp_image = image; - } + mp_image.reset (image); } std::string Item::image_str () const { - if (! mp_image) { + if (! mp_image.get ()) { return std::string (); } else { @@ -989,6 +986,7 @@ Item::set_image_str (const std::string &s) } } +#endif // ------------------------------------------------------------------------------------------ // Database implementation @@ -1318,12 +1316,14 @@ Database::remove_item_tag (const Item *item, id_type tag) const_cast (item)->remove_tag (tag); } +#if defined(HAVE_QT) void Database::set_item_image (const Item *item, QImage *image) { set_modified (); const_cast (item)->set_image (image); } +#endif void Database::set_item_multiplicity (const Item *item, size_t n) diff --git a/src/rdb/rdb/rdb.h b/src/rdb/rdb/rdb.h index 10e20a600..21f31ebe7 100644 --- a/src/rdb/rdb/rdb.h +++ b/src/rdb/rdb/rdb.h @@ -37,7 +37,9 @@ #include #include +#if defined(HAVE_QT) class QImage; +#endif namespace tl { @@ -928,6 +930,7 @@ public: */ void set_tag_str (const std::string &tags); +#if defined(HAVE_QT) /** * @brief Get the image object attached to this item * @@ -957,6 +960,7 @@ public: * If the image string is not valid, the image will also be cleared. */ void set_image_str (const std::string &s); +#endif /** * @brief Get the database reference @@ -985,7 +989,9 @@ private: bool m_visited; std::vector m_tag_ids; Database *mp_database; - QImage *mp_image; +#if defined(HAVE_QT) + std::auto_ptr mp_image; +#endif Item (); @@ -2207,10 +2213,12 @@ public: */ void remove_item_tag (const Item *item, id_type tag); +#if defined(HAVE_QT) /** * @brief Set the image of an item */ void set_item_image (const Item *item, QImage *image); +#endif /** * @brief Set the multiplicity of an item diff --git a/src/rdb/rdb/rdbFile.cc b/src/rdb/rdb/rdbFile.cc index 9a722eed1..efccad8c8 100644 --- a/src/rdb/rdb/rdbFile.cc +++ b/src/rdb/rdb/rdbFile.cc @@ -32,7 +32,6 @@ #include #include -#include namespace rdb { diff --git a/src/rdb/rdb/rdbRVEReader.cc b/src/rdb/rdb/rdbRVEReader.cc index ba03e0307..de2be226f 100644 --- a/src/rdb/rdb/rdbRVEReader.cc +++ b/src/rdb/rdb/rdbRVEReader.cc @@ -43,7 +43,7 @@ class RVEReaderException { public: RVEReaderException (const std::string &msg, size_t line) - : ReaderException (tl::sprintf (tl::to_string (QObject::tr ("%s (line=%lu)")), msg, line)) + : ReaderException (tl::sprintf (tl::to_string (tr ("%s (line=%lu)")), msg, line)) { } }; @@ -53,9 +53,9 @@ class RVEReader public: RVEReader (tl::InputStream &stream) : m_input_stream (stream), - m_progress (tl::to_string (QObject::tr ("Reading RVE DB")), 10000) + m_progress (tl::to_string (tr ("Reading RVE DB")), 10000) { - m_progress.set_format (tl::to_string (QObject::tr ("%.0f MB"))); + m_progress.set_format (tl::to_string (tr ("%.0f MB"))); m_progress.set_unit (1024 * 1024); } @@ -88,7 +88,7 @@ public: ex.read (res); if (res < 0.001 || res > 1e6) { - error (tl::sprintf (tl::to_string (QObject::tr ("Invalid resolution value: %g")), res)); + error (tl::sprintf (tl::to_string (tr ("Invalid resolution value: %g")), res)); } dbu = 1.0 / res; @@ -128,7 +128,7 @@ public: cat_name.clear (); if (m_input_stream.at_end ()) { - error (tl::to_string (QObject::tr ("Unexpected end of file"))); + error (tl::to_string (tr ("Unexpected end of file"))); } ex = tl::Extractor (m_input_stream.get_line ().c_str ()); @@ -143,7 +143,7 @@ public: for (size_t i = 0; i < n3; ++i) { if (m_input_stream.at_end ()) { - error (tl::to_string (QObject::tr ("Unexpected end of file"))); + error (tl::to_string (tr ("Unexpected end of file"))); } std::string l = m_input_stream.get_line (); @@ -179,7 +179,7 @@ public: // TODO: add waiver string somehow ... if (m_input_stream.at_end ()) { - warn (tl::to_string (QObject::tr ("Unexpected end of file before the specified number of shapes was read - stopping."))); + warn (tl::to_string (tr ("Unexpected end of file before the specified number of shapes was read - stopping."))); break; } @@ -204,7 +204,7 @@ public: ex = tl::Extractor (s.c_str ()); const char *start = ex.skip (); if (! *start) { - warn (tl::to_string (QObject::tr ("Unexpected end of file before the specified number of shapes was read - stopping."))); + warn (tl::to_string (tr ("Unexpected end of file before the specified number of shapes was read - stopping."))); } else { const char *end = start + strlen (start); while (end > start && isspace (end [-1])) { @@ -214,7 +214,7 @@ public: --end; } cat_name = std::string (start, end - start); - warn (tl::to_string (QObject::tr ("Obviously reaching end of shapes list before the specified number of shapes was read - parsing next category."))); + warn (tl::to_string (tr ("Obviously reaching end of shapes list before the specified number of shapes was read - parsing next category."))); } break; } @@ -222,7 +222,7 @@ public: while (true) { if (m_input_stream.at_end ()) { - error (tl::to_string (QObject::tr ("Unexpected end of file"))); + error (tl::to_string (tr ("Unexpected end of file"))); } ex = tl::Extractor (m_input_stream.get_line ().c_str ()); @@ -341,7 +341,7 @@ public: if (point > 0) { if (m_input_stream.at_end ()) { - error (tl::to_string (QObject::tr ("Unexpected end of file"))); + error (tl::to_string (tr ("Unexpected end of file"))); } ex = tl::Extractor (m_input_stream.get_line ().c_str ()); @@ -369,7 +369,7 @@ public: if (point > 0) { if (m_input_stream.at_end ()) { - error (tl::to_string (QObject::tr ("Unexpected end of file"))); + error (tl::to_string (tr ("Unexpected end of file"))); } ex = tl::Extractor (m_input_stream.get_line ().c_str ()); @@ -400,7 +400,7 @@ public: } } else { - error (tl::sprintf (tl::to_string (QObject::tr ("Invalid shape type: %c")), shape_type)); + error (tl::sprintf (tl::to_string (tr ("Invalid shape type: %c")), shape_type)); } Item *item = db.create_item (cell->id (), cath->id ()); @@ -427,7 +427,7 @@ private: void warn (const std::string &msg) { - tl::warn << tl::sprintf (tl::to_string (QObject::tr ("%s (line=%lu)")), msg, m_input_stream.line_number ()); + tl::warn << tl::sprintf (tl::to_string (tr ("%s (line=%lu)")), msg, m_input_stream.line_number ()); } void error (const std::string &msg) diff --git a/src/rdb/rdb/rdbReader.cc b/src/rdb/rdb/rdbReader.cc index 632531646..75410cb22 100644 --- a/src/rdb/rdb/rdbReader.cc +++ b/src/rdb/rdb/rdbReader.cc @@ -70,7 +70,7 @@ Reader::Reader (tl::InputStream &stream) } if (! mp_actual_reader) { - throw rdb::ReaderException (tl::to_string (QObject::tr ("Marker database has unknown format"))); + throw rdb::ReaderException (tl::to_string (tr ("Marker database has unknown format"))); } } diff --git a/src/tl/tl/tl.pro b/src/tl/tl/tl.pro index 2621960ec..48590562a 100644 --- a/src/tl/tl/tl.pro +++ b/src/tl/tl/tl.pro @@ -21,7 +21,6 @@ SOURCES = \ tlAssert.cc \ tlClassRegistry.cc \ tlDataMapping.cc \ - tlDeferredExecution.cc \ tlDeflate.cc \ tlException.cc \ tlExceptions.cc \ @@ -38,27 +37,21 @@ SOURCES = \ tlStaticObjects.cc \ tlStream.cc \ tlString.cc \ - tlThreadedWorkers.cc \ tlTimer.cc \ tlVariant.cc \ - tlXMLParser.cc \ - tlXMLWriter.cc \ - tlFileSystemWatcher.cc \ tlFileUtils.cc \ - tlWebDAV.cc \ tlArch.cc \ tlCommandLineParser.cc \ tlUnitTest.cc \ tlInt128Support.cc \ - tlHttpStreamCurl.cc \ - tlHttpStreamQt.cc + tlThreadedWorkers.cc \ + tlThreads.cc HEADERS = \ tlAlgorithm.h \ tlAssert.h \ tlClassRegistry.h \ tlDataMapping.h \ - tlDeferredExecution.h \ tlDeflate.h \ tlException.h \ tlExceptions.h \ @@ -82,28 +75,65 @@ HEADERS = \ tlStaticObjects.h \ tlStream.h \ tlString.h \ - tlThreadedWorkers.h \ tlTimer.h \ tlTypeTraits.h \ tlUtils.h \ tlVariant.h \ tlVariantUserClasses.h \ tlVector.h \ - tlXMLParser.h \ - tlXMLWriter.h \ - tlFileSystemWatcher.h \ tlCommon.h \ tlMath.h \ tlCpp.h \ tlFileUtils.h \ - tlWebDAV.h \ tlArch.h \ tlCommandLineParser.h \ tlUnitTest.h \ tlInt128Support.h \ tlHttpStreamCurl.h \ + tlDefs.h \ + tlThreadedWorkers.h \ + tlThreads.h + +equals(HAVE_CURL, "1") { + + SOURCES += \ + tlHttpStreamCurl.cc \ + +} else { + + equals(HAVE_QT, "0") { + # no HTTP stream available + } else { + + SOURCES += \ + tlHttpStreamQt.cc \ + + } + +} + +equals(HAVE_QT, "0") { + + # nothing + +} else { + + HEADERS += \ + tlWebDAV.h \ + tlDeferredExecution.h \ + tlXMLParser.h \ + tlXMLWriter.h \ + tlFileSystemWatcher.h \ tlHttpStreamQt.h \ - tlDefs.h + + SOURCES += \ + tlWebDAV.cc \ + tlDeferredExecution.cc \ + tlXMLParser.cc \ + tlXMLWriter.cc \ + tlFileSystemWatcher.cc \ + +} INCLUDEPATH = DEPENDPATH = diff --git a/src/tl/tl/tlCommandLineParser.cc b/src/tl/tl/tlCommandLineParser.cc index cec541f46..ab6d4992d 100644 --- a/src/tl/tl/tlCommandLineParser.cc +++ b/src/tl/tl/tlCommandLineParser.cc @@ -22,8 +22,7 @@ #include "tlLog.h" #include "tlCommandLineParser.h" - -#include +#include "tlFileUtils.h" namespace tl { @@ -463,7 +462,7 @@ CommandLineOptions::produce_version () void CommandLineOptions::parse (int argc, char *argv[]) { - m_program_name = tl::to_string (QFileInfo (QString::fromLocal8Bit (argv [0])).fileName ()); + m_program_name = tl::filename (tl::to_string_from_local (argv [0])); std::vector plain_args; std::map arg_by_short_option, arg_by_long_option; @@ -493,7 +492,7 @@ CommandLineOptions::parse (int argc, char *argv[]) ArgBase *arg = 0; - std::string arg_as_utf8 = tl::to_string (QString::fromLocal8Bit (argv [i])); + std::string arg_as_utf8 = tl::to_string_from_local (argv [i]); tl::Extractor ex (arg_as_utf8.c_str ()); if (ex.test ("--")) { @@ -502,7 +501,7 @@ CommandLineOptions::parse (int argc, char *argv[]) ex.read_word (n, "_-"); std::map::const_iterator a = arg_by_long_option.find (n); if (a == arg_by_long_option.end ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Unknown command line option --%1 (use -h for help)").arg (tl::to_qstring (n)))); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Unknown command line option --%1 (use -h for help)")), n)); } arg = a->second; @@ -512,14 +511,14 @@ CommandLineOptions::parse (int argc, char *argv[]) ex.read_word (n); std::map::const_iterator a = arg_by_short_option.find (n); if (a == arg_by_short_option.end ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Unknown command line option --%1 (use -h for help)").arg (tl::to_qstring (n)))); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Unknown command line option --%1 (use -h for help)")), n)); } arg = a->second; } else { if (next_plain_arg == plain_args.end ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Unknown command line component %1 - no further plain argument expected (use -h for help)").arg (tl::to_qstring (arg_as_utf8)))); + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Unknown command line component %1 - no further plain argument expected (use -h for help)")), arg_as_utf8)); } arg = *next_plain_arg; @@ -544,10 +543,10 @@ CommandLineOptions::parse (int argc, char *argv[]) ex.expect_end (); ++i; if (i == argc) { - throw tl::Exception (tl::to_string (QObject::tr ("Value missing"))); + throw tl::Exception (tl::to_string (tr ("Value missing"))); } - std::string arg_as_utf8 = tl::to_string (QString::fromLocal8Bit (argv [i])); + std::string arg_as_utf8 = tl::to_string_from_local (argv [i]); tl::Extractor ex_value (arg_as_utf8); arg->take_value (ex_value); @@ -589,7 +588,7 @@ CommandLineOptions::parse (int argc, char *argv[]) } if (next_plain_arg != plain_args.end () && !(*next_plain_arg)->option ().optional) { - throw tl::Exception (tl::to_string (QObject::tr ("Additional arguments required (use -h for help)"))); + throw tl::Exception (tl::to_string (tr ("Additional arguments required (use -h for help)"))); } } diff --git a/src/tl/tl/tlCommandLineParser.h b/src/tl/tl/tlCommandLineParser.h index 690ac0e7c..206b8fc23 100644 --- a/src/tl/tl/tlCommandLineParser.h +++ b/src/tl/tl/tlCommandLineParser.h @@ -26,8 +26,6 @@ #include "tlCommon.h" #include "tlLog.h" -#include - namespace tl { diff --git a/src/tl/tl/tlDeferredExecution.cc b/src/tl/tl/tlDeferredExecution.cc index f373286e8..30033a788 100644 --- a/src/tl/tl/tlDeferredExecution.cc +++ b/src/tl/tl/tlDeferredExecution.cc @@ -20,7 +20,6 @@ */ - #include "tlDeferredExecution.h" #include "tlAssert.h" #include "tlLog.h" @@ -159,4 +158,3 @@ DeferredMethodScheduler::do_execute () } } - diff --git a/src/tl/tl/tlDeferredExecution.h b/src/tl/tl/tlDeferredExecution.h index 092231e1b..c0877de65 100644 --- a/src/tl/tl/tlDeferredExecution.h +++ b/src/tl/tl/tlDeferredExecution.h @@ -20,11 +20,13 @@ */ - - #ifndef HDR_tlDeferredExecution #define HDR_tlDeferredExecution +#if !defined(HAVE_QT) +# error tl::DeferredExecution not available without Qt +#endif + #include "tlCommon.h" #include "tlObject.h" @@ -268,7 +270,5 @@ private: } - - #endif diff --git a/src/tl/tl/tlDeflate.cc b/src/tl/tl/tlDeflate.cc index 9bb9368ab..a10f819d2 100644 --- a/src/tl/tl/tlDeflate.cc +++ b/src/tl/tl/tlDeflate.cc @@ -249,7 +249,7 @@ InflateFilter::get (size_t n) while ((m_b_insert + sizeof (m_buffer) - m_b_read) % sizeof (m_buffer) < n) { if (! process ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Unexpected end of file (DEFLATE implementation)"))); + throw tl::Exception (tl::to_string (tr ("Unexpected end of file (DEFLATE implementation)"))); } } @@ -472,7 +472,7 @@ InflateFilter::process () } } else { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid compression type: %d")), t); + throw tl::Exception (tl::to_string (tr ("Invalid compression type: %d")), t); } } else { diff --git a/src/tl/tl/tlDeflate.h b/src/tl/tl/tlDeflate.h index 7fca8e1d1..f7d69ef4a 100644 --- a/src/tl/tl/tlDeflate.h +++ b/src/tl/tl/tlDeflate.h @@ -70,7 +70,7 @@ public: m_mask = 0; const char *c = mp_input->get (1, true /*bypass_deflate*/); if (c == 0) { - throw tl::Exception (tl::to_string (QObject::tr ("Unexpected end of file (DEFLATE implementation)"))); + throw tl::Exception (tl::to_string (tr ("Unexpected end of file (DEFLATE implementation)"))); } return *c; } diff --git a/src/tl/tl/tlException.h b/src/tl/tl/tlException.h index e1cba8700..d324806bf 100644 --- a/src/tl/tl/tlException.h +++ b/src/tl/tl/tlException.h @@ -141,7 +141,7 @@ struct TL_PUBLIC CancelException : public Exception { CancelException () - : Exception (tl::to_string (QObject::tr ("Operation cancelled"))) + : Exception (tl::to_string (tr ("Operation cancelled"))) { } }; @@ -152,7 +152,7 @@ struct TL_PUBLIC InternalException : public Exception { InternalException (const char *file, int line, const char *cond) - : Exception (tl::to_string (QObject::tr ("Internal error: %s:%d %s was not true")).c_str (), file, line, cond) + : Exception (tl::to_string (tr ("Internal error: %s:%d %s was not true")).c_str (), file, line, cond) { } }; diff --git a/src/tl/tl/tlExceptions.cc b/src/tl/tl/tlExceptions.cc index afc25cfdf..0d546f63a 100644 --- a/src/tl/tl/tlExceptions.cc +++ b/src/tl/tl/tlExceptions.cc @@ -30,8 +30,6 @@ #include -#include - namespace tl { @@ -54,9 +52,9 @@ void handle_exception_silent (const tl::Exception &ex) if (script_error) { if (script_error->line () > 0) { tl::error << script_error->sourcefile () << ":" << script_error->line () << ": " - << script_error->msg () << tl::to_string (QObject::tr (" (class ")) << script_error->cls () << ")"; + << script_error->msg () << tl::to_string (tr (" (class ")) << script_error->cls () << ")"; } else { - tl::error << script_error->msg () << tl::to_string (QObject::tr (" (class ")) << script_error->cls () << ")"; + tl::error << script_error->msg () << tl::to_string (tr (" (class ")) << script_error->cls () << ")"; } } else { tl::error << ex.msg (); @@ -98,7 +96,7 @@ void handle_exception_ui (const std::exception &ex, QWidget *parent) void handle_exception_silent () { - tl::error << tl::to_string (QObject::tr ("An unspecific error occured")); + tl::error << tl::to_string (tr ("An unspecific error occured")); } void handle_exception () diff --git a/src/tl/tl/tlExpression.cc b/src/tl/tl/tlExpression.cc index 25a80ba35..217949315 100644 --- a/src/tl/tl/tlExpression.cc +++ b/src/tl/tl/tlExpression.cc @@ -25,6 +25,7 @@ #include "tlInternational.h" #include "tlString.h" #include "tlGlobPattern.h" +#include "tlFileUtils.h" #include #include @@ -35,9 +36,6 @@ #include #include -#include -#include - // Suggestions for further functions: // - provide date/time function // - file functions: (drive), combine, split_path @@ -53,7 +51,7 @@ static std::locale c_locale ("C"); // Implementation of EvalError EvalError::EvalError (const std::string &what, const ExpressionParserContext &context) - : tl::Exception (what + tl::to_string (QObject::tr (" at ")) + context.where ()) + : tl::Exception (what + tl::to_string (tr (" at ")) + context.where ()) { // .. nothing yet .. } @@ -62,7 +60,7 @@ EvalError::EvalError (const std::string &what, const ExpressionParserContext &co // Implementation of NoMethodError NoMethodError::NoMethodError (const std::string &cls_name, const std::string &method, const ExpressionParserContext &context) - : EvalError (tl::sprintf (tl::to_string (QObject::tr ("'%s' is not a valid method name for objects of class '%s'")), method, cls_name), context) + : EvalError (tl::sprintf (tl::to_string (tr ("'%s' is not a valid method name for objects of class '%s'")), method, cls_name), context) { // .. nothing yet .. } @@ -99,7 +97,7 @@ ExpressionParserContext::where () const size_t len = strlen (text); if (pos >= len) { - return tl::to_string (QObject::tr ("end of text")); + return tl::to_string (tr ("end of text")); } else { int line = 1; @@ -116,9 +114,9 @@ ExpressionParserContext::where () const std::ostringstream os; if (line == 1) { - os << tl::to_string (QObject::tr ("position")) << " " << pos; + os << tl::to_string (tr ("position")) << " " << pos; } else { - os << tl::to_string (QObject::tr ("line")) << " " << line << ", " << tl::to_string (QObject::tr ("position")) << " " << col; + os << tl::to_string (tr ("line")) << " " << line << ", " << tl::to_string (tr ("position")) << " " << col; } os << " ("; @@ -138,7 +136,7 @@ ExpressionParserContext::where () const } } else { - return std::string (tl::to_string (QObject::tr ("[unspecified location]"))); + return std::string (tl::to_string (tr ("[unspecified location]"))); } } @@ -152,14 +150,14 @@ static double to_double (const ExpressionParserContext &context, const tl::Varia } else if (v.is_list ()) { return v.get_list ().size (); } else { - throw EvalError (tl::to_string (QObject::tr ("Double precision floating point value expected")), context); + throw EvalError (tl::to_string (tr ("Double precision floating point value expected")), context); } } static double to_double (const ExpressionParserContext &context, const std::vector &v) { if (v.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("Function expects a single numeric argument")), context); + throw EvalError (tl::to_string (tr ("Function expects a single numeric argument")), context); } return to_double (context, v [0]); @@ -172,7 +170,7 @@ static long to_long (const ExpressionParserContext &context, const tl::Variant & } else if (v.is_list ()) { return long (v.get_list ().size ()); } else { - throw EvalError (tl::to_string (QObject::tr ("Integer value expected")), context); + throw EvalError (tl::to_string (tr ("Integer value expected")), context); } } @@ -183,7 +181,7 @@ static unsigned long to_ulong (const ExpressionParserContext &context, const tl: } else if (v.is_list ()) { return (unsigned long) (v.get_list ().size ()); } else { - throw EvalError (tl::to_string (QObject::tr ("Unsigned integer value expected")), context); + throw EvalError (tl::to_string (tr ("Unsigned integer value expected")), context); } } @@ -194,7 +192,7 @@ static long long to_longlong (const ExpressionParserContext &context, const tl:: } else if (v.is_list ()) { return long (v.get_list ().size ()); } else { - throw EvalError (tl::to_string (QObject::tr ("Integer value expected")), context); + throw EvalError (tl::to_string (tr ("Integer value expected")), context); } } @@ -205,7 +203,7 @@ static unsigned long long to_ulonglong (const ExpressionParserContext &context, } else if (v.is_list ()) { return (unsigned long long) (v.get_list ().size ()); } else { - throw EvalError (tl::to_string (QObject::tr ("Unsigned integer value expected")), context); + throw EvalError (tl::to_string (tr ("Unsigned integer value expected")), context); } } @@ -311,7 +309,7 @@ public: if (method == "push") { if (args.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'push' method expects one argument")), context); + throw EvalError (tl::to_string (tr ("'push' method expects one argument")), context); } object.push (args [0]); @@ -320,13 +318,13 @@ public: } else if (method == "size") { if (args.size () != 0) { - throw EvalError (tl::to_string (QObject::tr ("'size' method does not accept an argument")), context); + throw EvalError (tl::to_string (tr ("'size' method does not accept an argument")), context); } out = object.size (); } else { - throw EvalError (tl::to_string (QObject::tr ("Unknown method")) + " '" + method + "' for list", context); + throw EvalError (tl::to_string (tr ("Unknown method")) + " '" + method + "' for list", context); } } @@ -348,7 +346,7 @@ public: if (method == "insert") { if (args.size () != 2) { - throw EvalError (tl::to_string (QObject::tr ("'insert' method expects two arguments")), context); + throw EvalError (tl::to_string (tr ("'insert' method expects two arguments")), context); } object.insert (args [0], args [1]); @@ -357,7 +355,7 @@ public: } else if (method == "size") { if (args.size () != 0) { - throw EvalError (tl::to_string (QObject::tr ("'size' method does not accept an argument")), context); + throw EvalError (tl::to_string (tr ("'size' method does not accept an argument")), context); } out = object.array_size (); @@ -365,7 +363,7 @@ public: } else if (method == "keys") { if (args.size () != 0) { - throw EvalError (tl::to_string (QObject::tr ("'keys' method does not accept an argument")), context); + throw EvalError (tl::to_string (tr ("'keys' method does not accept an argument")), context); } out.set_list (object.array_size ()); @@ -376,7 +374,7 @@ public: } else if (method == "values") { if (args.size () != 0) { - throw EvalError (tl::to_string (QObject::tr ("'keys' method does not accept an argument")), context); + throw EvalError (tl::to_string (tr ("'keys' method does not accept an argument")), context); } out.set_list (object.array_size ()); @@ -385,7 +383,7 @@ public: } } else { - throw EvalError (tl::to_string (QObject::tr ("Unknown method")) + " '" + method + "' for array", context); + throw EvalError (tl::to_string (tr ("Unknown method")) + " '" + method + "' for array", context); } } @@ -470,7 +468,7 @@ public: m_c[1]->execute (a); if (! v.lvalue ()) { - throw EvalError (tl::to_string (QObject::tr ("Assignment needs a lvalue")), m_context); + throw EvalError (tl::to_string (tr ("Assignment needs a lvalue")), m_context); } a.swap (*v.lvalue ()); } @@ -511,7 +509,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -561,7 +559,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -611,7 +609,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -661,7 +659,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -711,7 +709,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -761,7 +759,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -811,7 +809,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -908,7 +906,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -1079,7 +1077,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -1135,7 +1133,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -1191,7 +1189,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -1253,7 +1251,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -1313,7 +1311,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -1326,7 +1324,7 @@ public: long x = to_long (m_context, *b); if (x < 0) { - throw EvalError (tl::to_string (QObject::tr ("Numeric argument of '*' operator with string must be positive")), m_context); + throw EvalError (tl::to_string (tr ("Numeric argument of '*' operator with string must be positive")), m_context); } std::string s; @@ -1341,7 +1339,7 @@ public: long x = to_long (m_context, *v); if (x < 0) { - throw EvalError (tl::to_string (QObject::tr ("Numeric argument of '*' operator with string must be positive")), m_context); + throw EvalError (tl::to_string (tr ("Numeric argument of '*' operator with string must be positive")), m_context); } std::string s; @@ -1403,7 +1401,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -1415,37 +1413,37 @@ public: } else if (v->is_double () || b->is_double ()) { double d = to_double (m_context, *b); if (d == 0) { - throw EvalError (tl::to_string (QObject::tr ("Division by zero")), m_context); + throw EvalError (tl::to_string (tr ("Division by zero")), m_context); } v.set (tl::Variant (to_double (m_context, *v) / d)); } else if (v->is_ulonglong () || b->is_ulonglong ()) { unsigned long long d = to_ulonglong (m_context, *b); if (d == 0) { - throw EvalError (tl::to_string (QObject::tr ("Division by zero")), m_context); + throw EvalError (tl::to_string (tr ("Division by zero")), m_context); } v.set (tl::Variant (to_ulonglong (m_context, *v) / d)); } else if (v->is_longlong () || b->is_longlong ()) { long long d = to_longlong (m_context, *b); if (d == 0) { - throw EvalError (tl::to_string (QObject::tr ("Division by zero")), m_context); + throw EvalError (tl::to_string (tr ("Division by zero")), m_context); } v.set (tl::Variant (to_longlong (m_context, *v) / d)); } else if (v->is_ulong () || b->is_ulong ()) { unsigned long d = to_ulong (m_context, *b); if (d == 0) { - throw EvalError (tl::to_string (QObject::tr ("Division by zero")), m_context); + throw EvalError (tl::to_string (tr ("Division by zero")), m_context); } v.set (tl::Variant (to_ulong (m_context, *v) / d)); } else if (v->is_long () || b->is_long ()) { long d = to_long (m_context, *b); if (d == 0) { - throw EvalError (tl::to_string (QObject::tr ("Division by zero")), m_context); + throw EvalError (tl::to_string (tr ("Division by zero")), m_context); } v.set (tl::Variant (to_long (m_context, *v) / d)); } else { double d = to_double (m_context, *b); if (d == 0) { - throw EvalError (tl::to_string (QObject::tr ("Division by zero")), m_context); + throw EvalError (tl::to_string (tr ("Division by zero")), m_context); } v.set (tl::Variant (to_double (m_context, *v) / d)); } @@ -1487,7 +1485,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -1499,25 +1497,25 @@ public: } else if (v->is_ulonglong () || b->is_ulonglong ()) { unsigned long long d = to_ulonglong (m_context, *b); if (d == 0) { - throw EvalError (tl::to_string (QObject::tr ("Modulo by zero")), m_context); + throw EvalError (tl::to_string (tr ("Modulo by zero")), m_context); } v.set (tl::Variant (to_ulonglong (m_context, *v) % d)); } else if (v->is_longlong () || b->is_longlong ()) { long long d = to_longlong (m_context, *b); if (d == 0) { - throw EvalError (tl::to_string (QObject::tr ("Modulo by zero")), m_context); + throw EvalError (tl::to_string (tr ("Modulo by zero")), m_context); } v.set (tl::Variant (to_longlong (m_context, *v) % d)); } else if (v->is_ulong () || b->is_ulong ()) { unsigned long d = to_ulong (m_context, *b); if (d == 0) { - throw EvalError (tl::to_string (QObject::tr ("Modulo by zero")), m_context); + throw EvalError (tl::to_string (tr ("Modulo by zero")), m_context); } v.set (tl::Variant (to_ulong (m_context, *v) % d)); } else { long d = to_long (m_context, *b); if (d == 0) { - throw EvalError (tl::to_string (QObject::tr ("Modulo by zero")), m_context); + throw EvalError (tl::to_string (tr ("Modulo by zero")), m_context); } v.set (tl::Variant (to_long (m_context, *v) % d)); } @@ -1559,7 +1557,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -1615,7 +1613,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -1671,7 +1669,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -1727,7 +1725,7 @@ public: const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -1739,7 +1737,7 @@ public: } else if (v->is_list ()) { if (! e->can_convert_to_ulong ()) { - throw EvalError (tl::to_string (QObject::tr ("Invalid index for [] operator")), m_context); + throw EvalError (tl::to_string (tr ("Invalid index for [] operator")), m_context); } unsigned long i = e->to_ulong (); if (i >= (unsigned long) v->size ()) { @@ -1769,7 +1767,7 @@ public: } } else { - throw EvalError (tl::to_string (QObject::tr ("[] operator expects a list or an array")), m_context); + throw EvalError (tl::to_string (tr ("[] operator expects a list or an array")), m_context); } } }; @@ -1804,11 +1802,11 @@ public: if (v->is_user ()) { - throw EvalError (tl::to_string (QObject::tr ("Unary minus not implemented for objects")), m_context); + throw EvalError (tl::to_string (tr ("Unary minus not implemented for objects")), m_context); /* const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -1861,11 +1859,11 @@ public: if (v->is_user ()) { - throw EvalError (tl::to_string (QObject::tr ("Unary tilde not implemented for objects")), m_context); + throw EvalError (tl::to_string (tr ("Unary tilde not implemented for objects")), m_context); /* const EvalClass *c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object)")), m_context); + throw EvalError (tl::to_string (tr ("Not a valid object for a method call (not an object)")), m_context); } tl::Variant o; @@ -2041,10 +2039,10 @@ public: } else if (v->is_user ()) { c = v->user_cls () ? v->user_cls ()->eval_cls () : 0; if (! c) { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (not an object) - value is %1").arg (tl::to_qstring (v->to_parsable_string ()))), m_context); + throw EvalError (tl::sprintf (tl::to_string (tr ("Not a valid object for a method call (not an object) - value is %s")), v->to_parsable_string ()), m_context); } } else { - throw EvalError (tl::to_string (QObject::tr ("Not a valid object for a method call (wrong type) - value is %1").arg (tl::to_qstring (v->to_parsable_string ()))), m_context); + throw EvalError (tl::sprintf (tl::to_string (tr ("Not a valid object for a method call (wrong type) - value is %1")), v->to_parsable_string ()), m_context); } tl::Variant o; @@ -2358,7 +2356,7 @@ static void abs_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &v) { if (v.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'abs' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'abs' function expects exactly one argument")), context); } if (v[0].is_long ()) { @@ -2444,7 +2442,7 @@ static void pow_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 2) { - throw EvalError (tl::to_string (QObject::tr ("'pow' function expects exactly two arguments")), context); + throw EvalError (tl::to_string (tr ("'pow' function expects exactly two arguments")), context); } out = pow (to_double (context, vv [0]), to_double (context, vv [1])); @@ -2454,7 +2452,7 @@ static void atan2_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 2) { - throw EvalError (tl::to_string (QObject::tr ("'atan2' function expects exactly two arguments")), context); + throw EvalError (tl::to_string (tr ("'atan2' function expects exactly two arguments")), context); } out = atan2 (to_double (context, vv [0]), to_double (context, vv [1])); @@ -2464,7 +2462,7 @@ static void to_f_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'to_f' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'to_f' function expects exactly one argument")), context); } out = vv [0].to_double (); @@ -2474,7 +2472,7 @@ static void to_s_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'to_s' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'to_s' function expects exactly one argument")), context); } out = vv [0].to_string (); @@ -2484,7 +2482,7 @@ static void to_i_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'to_i' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'to_i' function expects exactly one argument")), context); } out = vv [0].to_long (); @@ -2494,7 +2492,7 @@ static void to_ui_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'to_ui' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'to_ui' function expects exactly one argument")), context); } out = vv [0].to_ulong (); @@ -2504,7 +2502,7 @@ static void to_l_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'to_l' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'to_l' function expects exactly one argument")), context); } out = vv [0].to_longlong (); @@ -2514,7 +2512,7 @@ static void to_ul_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'to_ul' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'to_ul' function expects exactly one argument")), context); } out = vv [0].to_ulonglong (); @@ -2524,7 +2522,7 @@ static void is_string_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'is_string' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'is_string' function expects exactly one argument")), context); } out = vv[0].is_a_string (); @@ -2534,7 +2532,7 @@ static void is_numeric_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'is_numeric' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'is_numeric' function expects exactly one argument")), context); } out = vv [0].can_convert_to_double (); @@ -2544,7 +2542,7 @@ static void is_array_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'is_array' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'is_array' function expects exactly one argument")), context); } out = vv [0].is_list (); @@ -2554,7 +2552,7 @@ static void is_nil_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'is_nil' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'is_nil' function expects exactly one argument")), context); } out = vv [0].is_nil (); @@ -2564,7 +2562,7 @@ static void gsub_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 3) { - throw EvalError (tl::to_string (QObject::tr ("'gsub' function expects exactly three arguments")), context); + throw EvalError (tl::to_string (tr ("'gsub' function expects exactly three arguments")), context); } std::string s (vv [0].to_string ()); @@ -2589,7 +2587,7 @@ static void sub_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 3) { - throw EvalError (tl::to_string (QObject::tr ("'sub' function expects exactly three arguments")), context); + throw EvalError (tl::to_string (tr ("'sub' function expects exactly three arguments")), context); } std::string s (vv [0].to_string ()); @@ -2617,7 +2615,7 @@ static void find_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 2) { - throw EvalError (tl::to_string (QObject::tr ("'find' function expects exactly two arguments")), context); + throw EvalError (tl::to_string (tr ("'find' function expects exactly two arguments")), context); } std::string s (vv [0].to_string ()); @@ -2635,7 +2633,7 @@ static void rfind_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 2) { - throw EvalError (tl::to_string (QObject::tr ("'rfind' function expects exactly two arguments")), context); + throw EvalError (tl::to_string (tr ("'rfind' function expects exactly two arguments")), context); } std::string s (vv [0].to_string ()); @@ -2653,7 +2651,7 @@ static void len_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'len' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'len' function expects exactly one argument")), context); } if (vv [0].is_list ()) { @@ -2667,7 +2665,7 @@ static void substr_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 3 && vv.size () != 2) { - throw EvalError (tl::to_string (QObject::tr ("'substr' function expects two or three arguments")), context); + throw EvalError (tl::to_string (tr ("'substr' function expects two or three arguments")), context); } std::string s (vv [0].to_string ()); @@ -2701,11 +2699,11 @@ static void join_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 2) { - throw EvalError (tl::to_string (QObject::tr ("'join' function expects exactly two arguments")), context); + throw EvalError (tl::to_string (tr ("'join' function expects exactly two arguments")), context); } if (! vv[0].is_list ()) { - throw EvalError (tl::to_string (QObject::tr ("First argument of 'join' function must be a list")), context); + throw EvalError (tl::to_string (tr ("First argument of 'join' function must be a list")), context); } std::ostringstream r; @@ -2729,11 +2727,11 @@ static void item_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 2) { - throw EvalError (tl::to_string (QObject::tr ("'item' function expects exactly two arguments")), context); + throw EvalError (tl::to_string (tr ("'item' function expects exactly two arguments")), context); } if (! vv[0].is_list ()) { - throw EvalError (tl::to_string (QObject::tr ("First argument of 'item' function must be a list")), context); + throw EvalError (tl::to_string (tr ("First argument of 'item' function must be a list")), context); } long index = to_long (context, vv [1]); @@ -2748,7 +2746,7 @@ static void split_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 2) { - throw EvalError (tl::to_string (QObject::tr ("'split' function expects exactly two arguments")), context); + throw EvalError (tl::to_string (tr ("'split' function expects exactly two arguments")), context); } out = tl::Variant::empty_list (); @@ -2767,7 +2765,7 @@ static void true_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 0) { - throw EvalError (tl::to_string (QObject::tr ("'true' function must not have arguments")), context); + throw EvalError (tl::to_string (tr ("'true' function must not have arguments")), context); } out = true; @@ -2777,7 +2775,7 @@ static void false_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 0) { - throw EvalError (tl::to_string (QObject::tr ("'false' function must not have arguments")), context); + throw EvalError (tl::to_string (tr ("'false' function must not have arguments")), context); } out = false; @@ -2787,7 +2785,7 @@ static void nil_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 0) { - throw EvalError (tl::to_string (QObject::tr ("'nil' function must not have arguments")), context); + throw EvalError (tl::to_string (tr ("'nil' function must not have arguments")), context); } out = tl::Variant (); @@ -2797,7 +2795,7 @@ static void env_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'env' function expects exactly two arguments")), context); + throw EvalError (tl::to_string (tr ("'env' function expects exactly two arguments")), context); } const char *env = getenv (vv [0].to_string ()); @@ -2812,7 +2810,7 @@ static void error_f (const ExpressionParserContext &context, tl::Variant &, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'error' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'error' function expects exactly one argument")), context); } throw tl::Exception (vv [0].to_string ()); @@ -2822,87 +2820,87 @@ static void absolute_file_path_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'absolute_file_path' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'absolute_file_path' function expects exactly one argument")), context); } - out = QFileInfo (vv [0].to_qstring ()).absoluteFilePath (); + out = tl::absolute_file_path (vv [0].to_string ()); } static void absolute_path_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'absolute_path' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'absolute_path' function expects exactly one argument")), context); } - out = QFileInfo (vv [0].to_qstring ()).absolutePath (); + out = tl::absolute_path (vv [0].to_string ()); } static void path_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'path' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'path' function expects exactly one argument")), context); } - out = QFileInfo (vv [0].to_qstring ()).path (); + out = tl::dirname (vv [0].to_string ()); } static void basename_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'basename' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'basename' function expects exactly one argument")), context); } - out = QFileInfo (vv [0].to_qstring ()).baseName (); + out = tl::basename (vv [0].to_string ()); } static void extension_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'extension' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'extension' function expects exactly one argument")), context); } - out = QFileInfo (vv [0].to_qstring ()).completeSuffix (); + out = tl::extension (vv [0].to_string ()); } static void file_exists_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'file_exists' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'file_exists' function expects exactly one argument")), context); } - out = QFileInfo (vv [0].to_qstring ()).exists (); + out = tl::file_exists (vv [0].to_string ()); } static void is_dir_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 1) { - throw EvalError (tl::to_string (QObject::tr ("'is_dir' function expects exactly one argument")), context); + throw EvalError (tl::to_string (tr ("'is_dir' function expects exactly one argument")), context); } - out = QFileInfo (vv [0].to_qstring ()).isDir (); + out = tl::is_dir (vv [0].to_string ()); } static void combine_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () != 2) { - throw EvalError (tl::to_string (QObject::tr ("'combine' function expects two arguments")), context); + throw EvalError (tl::to_string (tr ("'combine' function expects two arguments")), context); } - out = QFileInfo (QDir (vv [0].to_qstring ()), vv [1].to_qstring ()).filePath (); + out = tl::combine_path (vv [0].to_string (), vv [1].to_string ()); } static void sprintf_f (const ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) { if (vv.size () < 1) { - throw EvalError (tl::to_string (QObject::tr ("'sprintf' function expects at least one argument")), context); + throw EvalError (tl::to_string (tr ("'sprintf' function expects at least one argument")), context); } out = tl::sprintf (vv[0].to_string (), vv, 1); @@ -2912,7 +2910,7 @@ static void printf_f (const ExpressionParserContext &context, tl::Variant &, const std::vector &vv) { if (vv.size () < 1) { - throw EvalError (tl::to_string (QObject::tr ("'printf' function expects at least one argument")), context); + throw EvalError (tl::to_string (tr ("'printf' function expects at least one argument")), context); } std::cout << tl::sprintf (vv[0].to_string (), vv, 1); @@ -3240,7 +3238,7 @@ Eval::eval_if (ExpressionParserContext &ex, std::auto_ptr &n) std::auto_ptr b, c; eval_if (ex, b); if (! ex.test (":")) { - throw EvalError (tl::to_string (QObject::tr ("Expected ':'")), ex); + throw EvalError (tl::to_string (tr ("Expected ':'")), ex); } eval_if (ex, c); n.reset (new IfExpressionNode (ex1, n.release (), b.release (), c.release ())); @@ -3556,7 +3554,7 @@ Eval::eval_suffix (ExpressionParserContext &ex, std::auto_ptr &n if (ex.test (")")) { break; } else if (! ex.test (",")) { - throw EvalError (tl::to_string (QObject::tr ("Expected closing bracket ')'")), ex); + throw EvalError (tl::to_string (tr ("Expected closing bracket ')'")), ex); } } while (true); @@ -3625,7 +3623,7 @@ Eval::eval_atomic (ExpressionParserContext &ex, std::auto_ptr &n eval_top (ex, n); if (! ex.test (")")) { - throw EvalError (tl::to_string (QObject::tr ("Expected closing bracket ')'")), ex); + throw EvalError (tl::to_string (tr ("Expected closing bracket ')'")), ex); } } else if (ex.test ("[")) { @@ -3643,7 +3641,7 @@ Eval::eval_atomic (ExpressionParserContext &ex, std::auto_ptr &n if (ex.test ("]")) { break; } else if (! ex.test (",")) { - throw EvalError (tl::to_string (QObject::tr ("Expected closing bracket ']'")), ex); + throw EvalError (tl::to_string (tr ("Expected closing bracket ']'")), ex); } } while (true); @@ -3664,7 +3662,7 @@ Eval::eval_atomic (ExpressionParserContext &ex, std::auto_ptr &n } else if (ctx_handler ()) { n.reset (new ContextEvaluationNode (ex1, ctx_handler (), n.release (), true /*double bracket*/)); } else { - throw EvalError (tl::to_string (QObject::tr ("<<..>> expression not available in this context")), ex1); + throw EvalError (tl::to_string (tr ("<<..>> expression not available in this context")), ex1); } } else { @@ -3677,7 +3675,7 @@ Eval::eval_atomic (ExpressionParserContext &ex, std::auto_ptr &n } else if (ctx_handler ()) { n.reset (new ConstantExpressionNode (ex1, ctx_handler ()->eval_double_bracket (s))); } else { - throw EvalError (tl::to_string (QObject::tr ("<<..>> expression not available in this context")), ex1); + throw EvalError (tl::to_string (tr ("<<..>> expression not available in this context")), ex1); } } @@ -3696,7 +3694,7 @@ Eval::eval_atomic (ExpressionParserContext &ex, std::auto_ptr &n } else if (ctx_handler ()) { n.reset (new ContextEvaluationNode (ex1, ctx_handler (), n.release (), false /*single bracket*/)); } else { - throw EvalError (tl::to_string (QObject::tr ("<<..>> expression not available in this context")), ex1); + throw EvalError (tl::to_string (tr ("<<..>> expression not available in this context")), ex1); } } else { @@ -3709,7 +3707,7 @@ Eval::eval_atomic (ExpressionParserContext &ex, std::auto_ptr &n } else if (ctx_handler ()) { n.reset (new ConstantExpressionNode (ex1, ctx_handler ()->eval_bracket (s))); } else { - throw EvalError (tl::to_string (QObject::tr ("<..> expression not available in this context")), ex1); + throw EvalError (tl::to_string (tr ("<..> expression not available in this context")), ex1); } } @@ -3745,7 +3743,7 @@ Eval::eval_atomic (ExpressionParserContext &ex, std::auto_ptr &n if (ex.test ("}")) { break; } else if (! ex.test (",")) { - throw EvalError (tl::to_string (QObject::tr ("Expected closing bracket ']'")), ex); + throw EvalError (tl::to_string (tr ("Expected closing bracket ']'")), ex); } } while (true); @@ -3758,7 +3756,7 @@ Eval::eval_atomic (ExpressionParserContext &ex, std::auto_ptr &n while (! ex.at_end ()) { if (isdigit (*ex) || (tolower (*ex) <= 'f' && tolower (*ex) >= 'a')) { if ((x * 16) / 16 != x) { - throw EvalError (tl::to_string (QObject::tr ("Hexadecimal number overflow")), ex1); + throw EvalError (tl::to_string (tr ("Hexadecimal number overflow")), ex1); } x *= 16; if (isdigit (*ex)) { @@ -3836,7 +3834,7 @@ Eval::eval_atomic (ExpressionParserContext &ex, std::auto_ptr &n } else { if (dbu_units && ! ctx_handler ()) { - throw EvalError (tl::to_string (QObject::tr ("Length or area value with unit requires a layout context")), ex1); + throw EvalError (tl::to_string (tr ("Length or area value with unit requires a layout context")), ex1); } if (dbu_units) { @@ -3844,7 +3842,7 @@ Eval::eval_atomic (ExpressionParserContext &ex, std::auto_ptr &n double gg = g; g = floor (0.5 + g); if (fabs (g) < 1e12 && fabs (g - gg) > 1e-3) { - throw EvalError (tl::to_string (QObject::tr ("Value is not a multiple of the database unit")), ex1); + throw EvalError (tl::to_string (tr ("Value is not a multiple of the database unit")), ex1); } } @@ -3898,7 +3896,7 @@ Eval::eval_atomic (ExpressionParserContext &ex, std::auto_ptr &n if (ex.test (")")) { break; } else if (! ex.test (",")) { - throw EvalError (tl::to_string (QObject::tr ("Expected closing bracket ')'")), ex); + throw EvalError (tl::to_string (tr ("Expected closing bracket ')'")), ex); } } while (true); @@ -3914,11 +3912,11 @@ Eval::eval_atomic (ExpressionParserContext &ex, std::auto_ptr &n } else if (m_sloppy) { n.reset (new ConstantExpressionNode (ex1, tl::Variant ())); } else { - throw EvalError (tl::to_string (QObject::tr ("Unknown variable or function")) + " '" + t + "'", ex1); + throw EvalError (tl::to_string (tr ("Unknown variable or function")) + " '" + t + "'", ex1); } } else { - throw EvalError (tl::to_string (QObject::tr ("Expected constant, function or bracket expression")), ex1); + throw EvalError (tl::to_string (tr ("Expected constant, function or bracket expression")), ex1); } } diff --git a/src/tl/tl/tlFileSystemWatcher.cc b/src/tl/tl/tlFileSystemWatcher.cc index f8ae06f20..0db0e8ff1 100644 --- a/src/tl/tl/tlFileSystemWatcher.cc +++ b/src/tl/tl/tlFileSystemWatcher.cc @@ -20,7 +20,6 @@ */ - #include "tlFileSystemWatcher.h" #include "tlString.h" #include "tlTimer.h" diff --git a/src/tl/tl/tlFileSystemWatcher.h b/src/tl/tl/tlFileSystemWatcher.h index 2edccee5c..7f465ce89 100644 --- a/src/tl/tl/tlFileSystemWatcher.h +++ b/src/tl/tl/tlFileSystemWatcher.h @@ -23,6 +23,10 @@ #ifndef HDR_tlFileSystemWatcher #define HDR_tlFileSystemWatcher +#if !defined(HAVE_QT) +# error tl::FileSystemWatcher not available +#endif + #include "tlEvents.h" #include diff --git a/src/tl/tl/tlFileUtils.cc b/src/tl/tl/tlFileUtils.cc index a8f742759..ce3cc2f61 100644 --- a/src/tl/tl/tlFileUtils.cc +++ b/src/tl/tl/tlFileUtils.cc @@ -24,36 +24,176 @@ #include "tlLog.h" #include "tlInternational.h" -#include -#include +#include + +#include +#include namespace tl { -bool -is_parent_path (const QString &parent, const QString &path) +#if defined(_WIN32) +static bool is_drive (const std::string &part) { - QFileInfo parent_info (parent); - if (! parent_info.exists ()) { + return (part.size () == 2 && isletter (part[0]) && part[1] == ':'); +} +#else +static bool is_drive (const std::string &) +{ + return false; +} +#endif + +static std::string trimmed_part (const std::string &part) +{ + const char *cp = part.c_str (); + +#if defined(_WIN32) + while (*cp && *cp != '\\' && *cp != '/') { + ++cp; + } +#else + while (*cp && *cp != '/') { + ++cp; + } +#endif + + return std::string (part, 0, cp - part.c_str ()); +} + +static bool is_part_with_separator (const std::string &part) +{ + const char *cp = part.c_str (); +#if defined(_WIN32) + return (*cp == '\\' || *cp == '/'); +#else + return (*cp == '/'); +#endif +} + +std::vector split_path (const std::string &p) +{ + std::vector parts; + +#if defined(_WIN32) + + const char *cp = p.c_str (); + if (*cp && isletter (*cp) && cp[1] == ':') { + + // drive name + parts.push_back (std::string ()); + parts.back () += toupper (*cp); + parts.back () += ":"; + + cp += 2; + + } else if ((*cp == '\\' && cp[1] == '\\') || (*cp == '/' && cp[1] == '/')) { + + // UNC server name + const char *cp0 = cp; + cp += 2; + while (*cp && *cp != '\\' && *cp != '/') { + ++cp; + } + parts.push_back (std::string (cp0, 0, cp - cp0)); + + } + + while (*cp) { + + const char *cp0 = cp; + bool any = false; + while (*cp && (!any || (*cp != '\\' && *cp != '/'))) { + if (*cp != '\\' && *cp != '/') { + any = true; + } + ++cp; + } + + parts.push_back (std::string (cp0, 0, cp - cp0)); + + } + +#else + + const char *cp = p.c_str (); + while (*cp) { + + const char *cp0 = cp; + bool any = false; + while (*cp && (!any || *cp != '/')) { + if (*cp != '/') { + any = true; + } + // backslash escape + if (*cp == '\\' && cp[1]) { + ++cp; + } + ++cp; + } + + parts.push_back (std::string (cp0, 0, cp - cp0)); + + } + +#endif + + return parts; +} + +static std::vector split_filename (const std::string &fn) +{ + std::vector parts; + + const char *cp = fn.c_str (); + + while (*cp) { + + const char *cp0 = cp; + ++cp; + while (*cp && *cp != '.') { + // backslash escaping (ineffective on Windows because that is a path separator) + if (*cp == '\\' && cp[1]) { + ++cp; + } + ++cp; + } + + parts.push_back (std::string (cp0, 0, cp - cp0)); + if (*cp) { + ++cp; + } + + } + + return parts; +} + +bool +is_parent_path (const std::string &parent, const std::string &path) +{ + if (! file_exists (parent)) { // If the parent path does not exist, we always return false. This cannot be a parent. return false; } - QFileInfo path_info (path); + std::vector parts = split_path (absolute_file_path (path)); - while (parent_info != path_info) { - if (path_info.isRoot ()) { - return false; + while (! parts.empty () && ! (parts.size () == 1 && is_drive (parts[0]))) { + if (is_same_file (parent, tl::join (parts, ""))) { + return true; + } else { + parts.pop_back (); } - path_info = path_info.path (); } - return true; + // We did not find a match - now maybe the parent is root + return (is_same_file (parent, tl::combine_path (tl::join (parts, ""), ""))); } -bool -rm_dir_recursive (const QString &path) +bool rm_dir_recursive (const std::string &path) { +#if 0 // @@@ QDir dir (path); QStringList entries = dir.entryList (QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs); @@ -65,7 +205,7 @@ rm_dir_recursive (const QString &path) } } else if (fi.isFile ()) { if (! dir.remove (*e)) { - tl::error << QObject::tr ("Unable to remove file: %1").arg (dir.absoluteFilePath (*e)); + tl::error << tr ("Unable to remove file: %1").arg (dir.absoluteFilePath (*e)); return false; } } @@ -74,17 +214,20 @@ rm_dir_recursive (const QString &path) QString name = dir.dirName (); if (dir.cdUp ()) { if (! dir.rmdir (name)) { - tl::error << QObject::tr ("Unable to remove directory: %1").arg (dir.absoluteFilePath (name)); + tl::error << tr ("Unable to remove directory: %1").arg (dir.absoluteFilePath (name)); return false; } } +#endif + return true; } bool -cp_dir_recursive (const QString &source, const QString &target) +cp_dir_recursive (const std::string &source, const std::string &target) { +#if 0 // @@@ QDir dir (source); QDir dir_target (target); @@ -99,11 +242,11 @@ cp_dir_recursive (const QString &source, const QString &target) // Copy subdirectory if (! fi_target.exists ()) { if (! dir_target.mkdir (*e)) { - tl::error << QObject::tr ("Unable to create target directory: %1").arg (dir_target.absoluteFilePath (*e)); + tl::error << tr ("Unable to create target directory: %1").arg (dir_target.absoluteFilePath (*e)); return false; } } else if (! fi_target.isDir ()) { - tl::error << QObject::tr ("Unable to create target directory (is a file already): %1").arg (dir_target.absoluteFilePath (*e)); + tl::error << tr ("Unable to create target directory (is a file already): %1").arg (dir_target.absoluteFilePath (*e)); return false; } if (! cp_dir_recursive (fi.filePath (), fi_target.filePath ())) { @@ -117,11 +260,11 @@ cp_dir_recursive (const QString &source, const QString &target) QFile file_target (fi_target.filePath ()); if (! file.open (QIODevice::ReadOnly)) { - tl::error << QObject::tr ("Unable to open source file for reading: %1").arg (fi.filePath ()); + tl::error << tr ("Unable to open source file for reading: %1").arg (fi.filePath ()); return false; } if (! file_target.open (QIODevice::WriteOnly)) { - tl::error << QObject::tr ("Unable to open target file for writing: %1").arg (fi_target.filePath ()); + tl::error << tr ("Unable to open target file for writing: %1").arg (fi_target.filePath ()); return false; } @@ -139,7 +282,227 @@ cp_dir_recursive (const QString &source, const QString &target) } +#endif + return true; } +bool mkpath (const std::string &path) +{ + // @@@ + return false; +} + +std::string absolute_path (const std::string &s) +{ + std::vector parts = split_path (absolute_file_path (s)); + if (parts.size () > 0) { + parts.pop_back (); + } + + return tl::join (parts, ""); +} + +std::string current_dir () +{ + char *cwd; +#if defined(_WIN32) + cwd = _getcwd (NULL, 0); +#else + cwd = getcwd (NULL, 0); +#endif + + if (cwd == NULL) { + return std::string (); + } else { + std::string cwds (cwd); + free (cwd); + return cwds; + } +} + + +static std::pair absolute_path_of_existing (const std::string &s) +{ + char *fp; +#if defined (_WIN32) + fp = _fullpath (NULL, s.c_str (), 0); +#else + fp = realpath (s.c_str (), NULL); +#endif + + if (fp == NULL) { + return std::make_pair (std::string (), false); + } else { + std::string fps (fp); + free (fp); + return std::make_pair (fps, true); + } +} + +std::string absolute_file_path (const std::string &s) +{ + std::vector parts = split_path (s); + if (parts.empty ()) { + return current_dir (); + } + + std::pair known_part; + std::vector unknown_parts; + + while (! parts.empty () && ! (parts.size () == 1 && is_drive (parts[0]))) { + known_part = absolute_path_of_existing (tl::join (parts, "")); + if (! known_part.second) { + unknown_parts.push_back (parts.back ()); + parts.pop_back (); + } else { + break; + } + } + + std::reverse (unknown_parts.begin (), unknown_parts.end ()); + + if (! known_part.second) { + + // the top-level component is unknown. This can mean: + // 1.) the path is already absolute, but the top-level entry does not exist + // 2.) the path is relative, but the entry does not exist + + tl_assert (! unknown_parts.empty ()); + if (is_part_with_separator (unknown_parts.front ())) { + + // case 1: return the full path as absolute + return s; + + } else if (parts.size () == 1 && is_drive (parts[0])) { + + // case 2 (for Windows): try to root on drive's working dir + known_part = absolute_path_of_existing (parts[0]); + if (! known_part.second) { + // drive is not known ... return the original path as fallback + return s; + } else { + return combine_path (known_part.first, tl::join (unknown_parts, "")); + } + + } else { + + // case 2 (for *nix): try to root on current working dir + return combine_path (current_dir (), tl::join (unknown_parts, "")); + + } + + } else { + return combine_path (known_part.first, tl::join (unknown_parts, "")); + } +} + +std::string dirname (const std::string &s) +{ + std::vector parts = split_path (s); + if (parts.size () > 0) { + parts.pop_back (); + } + + return tl::join (parts, ""); +} + +std::string filename (const std::string &s) +{ + std::vector parts = split_path (s); + if (parts.size () > 0) { + return trimmed_part (parts.back ()); + } else { + return std::string (); + } +} + +std::string basename (const std::string &s) +{ + std::vector fnp = split_filename (filename (s)); + if (fnp.size () > 0) { + return fnp.front (); + } else { + return std::string (); + } +} + +std::string extension (const std::string &s) +{ + std::vector fnp = split_filename (filename (s)); + if (fnp.size () > 0) { + fnp.erase (fnp.begin ()); + } + return tl::join (fnp, "."); +} + +bool file_exists (const std::string &p) +{ + struct stat st; + return stat (p.c_str (), &st) == 0; +} + +bool is_dir (const std::string &p) +{ + struct stat st; + if (stat (p.c_str (), &st) != 0) { + return false; + } else { + return !S_ISREG (st.st_mode); + } +} + +std::string combine_path (const std::string &p1, const std::string &p2) +{ +#if defined(_WIN32) + return p1 + "\\" + p2; +#else + return p1 + "/" + p2; +#endif +} + +bool is_same_file (const std::string &a, const std::string &b) +{ + +#if defined(_WIN32) + + HANDLE h1 = ::CreateFile (a.c_str (), 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE h2 = ::CreateFile (b.c_str (), 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + + bool result = false; + + if (h1 != INVALID_HANDLE_VALUE && h2 != INVALID_HANDLE_VALUE) { + BY_HANDLE_FILE_INFORMATION fi1, fi2; + if (::GetFileInformationByHandle(h1, &fi1) && ::GetFileInformationByHandle(h2, &fi2)) { + result = fi1.dwVolumeSerialNumber == fi2.dwVolumeSerialNumber && + fi1.nFileIndexHigh == fi2.nFileIndexHigh && + fi1.nFileIndexLow == fi2.nFileIndexLow; + } + } + + if (h1 != INVALID_HANDLE_VALUE) { + ::CloseHandle(h1); + } + + if (h2 != INVALID_HANDLE_VALUE) { + ::CloseHandle(h2); + } + + return result; + +#else + + struct stat sta, stb; + if (stat (a.c_str (), &sta) != 0) { + return false; + } + if (stat (b.c_str (), &stb) != 0) { + return false; + } + + return sta.st_dev == stb.st_dev && sta.st_ino == stb.st_ino; + +#endif +} + } diff --git a/src/tl/tl/tlFileUtils.h b/src/tl/tl/tlFileUtils.h index 9ff7dcf78..9c70f3703 100644 --- a/src/tl/tl/tlFileUtils.h +++ b/src/tl/tl/tlFileUtils.h @@ -25,55 +25,102 @@ #include "tlCommon.h" #include "tlString.h" -#include namespace tl { -/** - * @brief Returns a value indicating whether the parent path is a parent directory of the path - */ -bool TL_PUBLIC is_parent_path (const QString &parent, const QString &path); - /** * @brief Returns a value indicating whether the parent path is a parent directory of the path (version with std::string) */ -inline bool is_parent_path (const std::string &parent, const std::string &path) -{ - return is_parent_path (tl::to_qstring (parent), tl::to_qstring (path)); -} - -/** - * @brief Recursively remove the given directory, the files from that directory and all sub-directories - * @return True, if successful. false otherwise. - */ -bool TL_PUBLIC rm_dir_recursive (const QString &path); +bool TL_PUBLIC is_parent_path (const std::string &parent, const std::string &path); /** * @brief Recursively remove the given directory, the files from that directory and all sub-directories (version with std::string) * @return True, if successful. false otherwise. */ -inline bool rm_dir_recursive (const std::string &path) -{ - return rm_dir_recursive (tl::to_qstring (path)); -} +bool TL_PUBLIC rm_dir_recursive (const std::string &path); /** - * @brief Recursively copies a given directory to a target directory - * Both target and source directories need to exist. New directories are created in the target - * directory if required. + * @brief Creates the given path as far it does not exist yet * @return True, if successful. false otherwise. */ -bool TL_PUBLIC cp_dir_recursive (const QString &source, const QString &target); +bool TL_PUBLIC mkpath (const std::string &path); /** * @brief Recursively remove the given directory, the files from that directory and all sub-directories (version with std::string) * @return True, if successful. false otherwise. */ -inline bool cp_dir_recursive (const std::string &source, const std::string &target) -{ - return cp_dir_recursive (tl::to_qstring (source), tl::to_qstring (target)); -} +bool TL_PUBLIC cp_dir_recursive (const std::string &source, const std::string &target); + +/** + * @brief Gets the absolute path for a given file path + * This will deliver the directory of the file as absolute path. + */ +std::string TL_PUBLIC absolute_path (const std::string &s); + +/** + * @brief Gets the absolute file path for a given file path + * This will deliver the directory and the file part as absolute path. + */ +std::string TL_PUBLIC absolute_file_path (const std::string &s); + +/** + * @brief Gets the directory name for a given file path + */ +std::string TL_PUBLIC dirname (const std::string &s); + +/** + * @brief Gets the filename for a given file path (file name without directory part) + */ +std::string TL_PUBLIC filename (const std::string &s); + +/** + * @brief Gets the basename for a given file path (file name without any extensions) + * This will strip all extensions (i.e. "archive.tar.gz" will become "archive"). + */ +std::string TL_PUBLIC basename (const std::string &s); + +/** + * @brief Gets the complete extension for a given file path + */ +std::string TL_PUBLIC extension (const std::string &s); + +/** + * @brief Returns true, if the given path exists + * If the path is a directory, file_exists will return true, if the directory exists. + */ +bool TL_PUBLIC file_exists (const std::string &s); + +/** + * @brief Returns true, if the given path is a directory + */ +bool TL_PUBLIC is_dir (const std::string &s); + +/** + * @brief Returns true, if the given path is the same directory of file than the other one + */ +bool TL_PUBLIC is_same_file (const std::string &a, const std::string &b); + +/** + * @brief Combines the two path components into one path + */ +std::string TL_PUBLIC combine_path (const std::string &p1, const std::string &p2); + +/** + * @brief Gets the current directory + */ +std::string TL_PUBLIC current_dir (); + +/** + * @brief This function splits the path into it's components + * On Windows, the first component may be the drive prefix ("C:") or + * UNC server name ("\\server"). + * The components will keep their path separator, so joining the + * parts will render the original path. A trailing empty element is + * added if the path terminates with a separator (like "C:\" or "/home/user/"). + * The idea is that the last element is the file name part. + */ +static std::vector split_path (const std::string &p); } diff --git a/src/tl/tl/tlHttpStream.h b/src/tl/tl/tlHttpStream.h index b526071af..8f9fa536c 100644 --- a/src/tl/tl/tlHttpStream.h +++ b/src/tl/tl/tlHttpStream.h @@ -23,10 +23,14 @@ #ifndef HDR_tlHttpStream #define HDR_tlHttpStream -#include "tlHttpStreamCurl.h" -#include "tlHttpStreamQt.h" +#if defined(HAVE_CURL) +# include "tlHttpStreamCurl.h" +#elif defined(HAVE_QT) +# include "tlHttpStreamQt.h" +#endif #include "tlObject.h" +#include "tlException.h" namespace tl { @@ -55,7 +59,7 @@ class TL_PUBLIC HttpErrorException { public: HttpErrorException (const std::string &f, int en, const std::string &url) - : tl::Exception (tl::to_string (QObject::tr ("Error %d: %s, fetching %s")), en, f, url) + : tl::Exception (tl::to_string (tr ("Error %d: %s, fetching %s")), en, f, url) { } }; diff --git a/src/tl/tl/tlHttpStreamCurl.cc b/src/tl/tl/tlHttpStreamCurl.cc index 9bfdb1e5a..b1c3c1416 100644 --- a/src/tl/tl/tlHttpStreamCurl.cc +++ b/src/tl/tl/tlHttpStreamCurl.cc @@ -20,8 +20,6 @@ */ -#if defined(HAVE_CURL) - #include "tlHttpStream.h" #include "tlHttpStreamCurl.h" #include "tlLog.h" @@ -1231,5 +1229,3 @@ InputHttpStream::set_credential_provider (HttpCredentialProvider *cp) } } - -#endif diff --git a/src/tl/tl/tlHttpStreamCurl.h b/src/tl/tl/tlHttpStreamCurl.h index 0424e035d..3d17517af 100644 --- a/src/tl/tl/tlHttpStreamCurl.h +++ b/src/tl/tl/tlHttpStreamCurl.h @@ -23,8 +23,6 @@ #ifndef HDR_tlHttpStreamCurl #define HDR_tlHttpStreamCurl -#if defined(HAVE_CURL) - #include "tlStream.h" #include "tlEvents.h" #include "tlObject.h" @@ -165,5 +163,3 @@ private: #endif -#endif - diff --git a/src/tl/tl/tlHttpStreamQt.cc b/src/tl/tl/tlHttpStreamQt.cc index c591f6ca1..c1e8dfe23 100644 --- a/src/tl/tl/tlHttpStreamQt.cc +++ b/src/tl/tl/tlHttpStreamQt.cc @@ -20,8 +20,6 @@ */ -#if !defined(HAVE_CURL) - #include "tlHttpStream.h" #include "tlLog.h" #include "tlStaticObjects.h" @@ -300,5 +298,3 @@ InputHttpStream::filename () const } } - -#endif diff --git a/src/tl/tl/tlHttpStreamQt.h b/src/tl/tl/tlHttpStreamQt.h index 7fcb78894..1d4ecef78 100644 --- a/src/tl/tl/tlHttpStreamQt.h +++ b/src/tl/tl/tlHttpStreamQt.h @@ -24,8 +24,6 @@ #ifndef HDR_tlHttpStreamQt #define HDR_tlHttpStreamQt -#if !defined(HAVE_CURL) - #include "tlStream.h" #include "tlEvents.h" @@ -191,5 +189,3 @@ private: #endif -#endif - diff --git a/src/tl/tl/tlInternational.cc b/src/tl/tl/tlInternational.cc index 50294d0a8..874a79289 100644 --- a/src/tl/tl/tlInternational.cc +++ b/src/tl/tl/tlInternational.cc @@ -24,19 +24,23 @@ #include "tlInternational.h" #include "tlString.h" -#include +#if defined(HAVE_QT) +# include +#endif #include #include #include #include -#ifndef _WIN32 -# include +#if !defined(_WIN32) +# include #endif namespace tl { +#if defined(HAVE_QT) + QTextCodec *ms_system_codec = 0; QString to_qstring (const std::string &s) @@ -49,7 +53,7 @@ std::string to_string (const QString &s) return std::string (s.toUtf8 ().constData ()); } -#ifndef _WIN32 +#if !defined(_WIN32) std::string system_to_string (const std::string &s) { if (! ms_system_codec) { @@ -92,5 +96,21 @@ void initialize_codecs () std::cerr.imbue (c_locale); } +#else + +std::string system_to_string (const std::string &s) +{ + // TODO: this fallback implementation assumes the system encoding is UTF-8 + return s; +} + +std::string string_to_system (const std::string &s) +{ + // TODO: this fallback implementation assumes the system encoding is UTF-8 + return std::string (s); +} + +#endif + } diff --git a/src/tl/tl/tlInternational.h b/src/tl/tl/tlInternational.h index 318ac4410..4449c712c 100644 --- a/src/tl/tl/tlInternational.h +++ b/src/tl/tl/tlInternational.h @@ -27,14 +27,29 @@ #include "tlCommon.h" #include -#include +#if defined(HAVE_QT) +# include // provides QObject for QObject::tr -#include +# include +#endif + +/** + * @brief Generic tr function for non-Qt and Qt builds + */ +#if defined(HAVE_QT) +QString tr (const char *s) +{ + return QObject::tr (s); +} +#else +std::string tr (const char *s); +#endif namespace tl { +#if defined(HAVE_QT) /** * @brief Convert a UTF8 std::string to a QString */ @@ -44,6 +59,15 @@ TL_PUBLIC QString to_qstring (const std::string &s); * @brief Convert a QString to a UTF8 std::string */ TL_PUBLIC std::string to_string (const QString &s); +#endif + +/** + * @brief Dummy conversion for convenience and as non-Qt replacement for to_string (const QString &) + */ +inline const std::string &to_string (const std::string &s) +{ + return s; +} #ifndef _WIN32 /** diff --git a/src/tl/tl/tlLog.cc b/src/tl/tl/tlLog.cc index 251830959..22f574d04 100644 --- a/src/tl/tl/tlLog.cc +++ b/src/tl/tl/tlLog.cc @@ -51,7 +51,7 @@ verbosity () // Channel implementation Channel::Channel () - : m_lock (), m_no_endl (false), m_active (false) + : m_no_endl (false), m_active (false) { // .. nothing else .. } diff --git a/src/tl/tl/tlLog.h b/src/tl/tl/tlLog.h index ab7f59e3f..28bc567a0 100644 --- a/src/tl/tl/tlLog.h +++ b/src/tl/tl/tlLog.h @@ -27,10 +27,9 @@ #include "tlCommon.h" #include "tlString.h" +#include "tlThreads.h" #include "tlObjectCollection.h" -#include - namespace tl { @@ -138,7 +137,7 @@ protected: virtual void end () = 0; virtual void begin () = 0; - QMutex m_lock; + tl::Mutex m_lock; private: friend class ChannelProxy; diff --git a/src/tl/tl/tlObject.cc b/src/tl/tl/tlObject.cc index 442375724..05e8b528a 100644 --- a/src/tl/tl/tlObject.cc +++ b/src/tl/tl/tlObject.cc @@ -23,7 +23,6 @@ #include "tlObject.h" -#include #include namespace tl @@ -181,27 +180,27 @@ namespace { GlobalLockInitializer () { if (! sp_lock) { - sp_lock = new QMutex (); + sp_lock = new tl::Mutex (); } } - QMutex &gl () + tl::Mutex &gl () { return *sp_lock; } private: - static QMutex *sp_lock; + static tl::Mutex *sp_lock; }; - QMutex *GlobalLockInitializer::sp_lock = 0; + tl::Mutex *GlobalLockInitializer::sp_lock = 0; // This ensures the instance is created in the initialization code static GlobalLockInitializer s_gl_init; } -QMutex &WeakOrSharedPtr::lock () +tl::Mutex &WeakOrSharedPtr::lock () { // NOTE: to ensure proper function in static initialization code we cannot simply use // a static QMutex instance - this may not be initialized. This is not entirely thread @@ -224,7 +223,7 @@ const Object *WeakOrSharedPtr::get () const void WeakOrSharedPtr::reset_object () { - QMutexLocker locker (&lock ()); + tl::MutexLocker locker (&lock ()); if (mp_t) { mp_t->unregister_ptr (this); @@ -242,7 +241,7 @@ void WeakOrSharedPtr::reset (Object *t, bool is_shared, bool is_event) Object *to_delete = 0; { - QMutexLocker locker (&lock ()); + tl::MutexLocker locker (&lock ()); if (mp_t) { Object *told = mp_t; diff --git a/src/tl/tl/tlObject.h b/src/tl/tl/tlObject.h index 8403bb455..aa0399631 100644 --- a/src/tl/tl/tlObject.h +++ b/src/tl/tl/tlObject.h @@ -27,9 +27,7 @@ #include "tlCommon.h" #include "tlAssert.h" - -#include -#include +#include "tlThreads.h" #include #include @@ -232,7 +230,7 @@ private: Object *mp_t; bool m_is_shared : 1; bool m_is_event : 1; - static QMutex &lock (); + static tl::Mutex &lock (); }; /** diff --git a/src/tl/tl/tlObjectCollection.h b/src/tl/tl/tlObjectCollection.h index 5a0148329..e72b451c2 100644 --- a/src/tl/tl/tlObjectCollection.h +++ b/src/tl/tl/tlObjectCollection.h @@ -26,8 +26,7 @@ #include "tlObject.h" #include "tlEvents.h" - -#include +#include "tlThreads.h" #include #include @@ -435,11 +434,11 @@ public: private: friend class holder_type; - QMutex m_lock; + tl::Mutex m_lock; void remove_element (holder_type *h) { - QMutexLocker locker (&m_lock); + tl::MutexLocker locker (&m_lock); tl_assert (! empty ()); m_about_to_change (); erase (h); diff --git a/src/tl/tl/tlProgress.cc b/src/tl/tl/tlProgress.cc index f1212ee09..2078a43eb 100644 --- a/src/tl/tl/tlProgress.cc +++ b/src/tl/tl/tlProgress.cc @@ -27,9 +27,7 @@ #include "tlProgress.h" #include "tlString.h" #include "tlAssert.h" - -#include -#include +#include "tlThreads.h" namespace tl { @@ -65,7 +63,7 @@ ProgressAdaptor::prev () // Hint: we don't want the QThreadStorage take ownership over the object. Hence we don't // store a pointer but a pointer to a pointer. -static QThreadStorage s_thread_data; +static tl::ThreadStorage s_thread_data; Progress::Progress (const std::string &desc, size_t yield_interval) : m_desc (desc), m_title (desc), diff --git a/src/tl/tl/tlScriptError.cc b/src/tl/tl/tlScriptError.cc index 0bd637bfc..ae59b713b 100644 --- a/src/tl/tl/tlScriptError.cc +++ b/src/tl/tl/tlScriptError.cc @@ -69,7 +69,7 @@ ScriptError::basic_msg () const { std::string m = tl::Exception::msg (); if (! m_context.empty ()) { - m += tl::to_string (QObject::tr (" in ")) + m_context; + m += tl::to_string (tr (" in ")) + m_context; } return m; } diff --git a/src/tl/tl/tlStream.cc b/src/tl/tl/tlStream.cc index 202eb1e9b..0cad3e585 100644 --- a/src/tl/tl/tlStream.cc +++ b/src/tl/tl/tlStream.cc @@ -22,7 +22,8 @@ -#include +#include +#include #include #include #include @@ -36,12 +37,14 @@ #include "tlHttpStream.h" #include "tlDeflate.h" #include "tlAssert.h" +#include "tlFileUtils.h" #include "tlException.h" #include "tlString.h" -#include -#include +#if defined(HAVE_QT) +# include +#endif namespace tl { @@ -54,7 +57,7 @@ class FileWriteErrorException { public: FileWriteErrorException (const std::string &f, int en) - : tl::Exception (tl::to_string (QObject::tr ("Write error on file: %s (errno=%d)")), f, en) + : tl::Exception (tl::to_string (tr ("Write error on file: %s (errno=%d)")), f, en) { } }; @@ -63,7 +66,7 @@ class FileReadErrorException { public: FileReadErrorException (const std::string &f, int en) - : tl::Exception (tl::to_string (QObject::tr ("Read error on file: %s (errno=%d)")), f, en) + : tl::Exception (tl::to_string (tr ("Read error on file: %s (errno=%d)")), f, en) { } }; @@ -72,7 +75,7 @@ class ZLibWriteErrorException { public: ZLibWriteErrorException (const std::string &f, const char *em) - : tl::Exception (tl::to_string (QObject::tr ("Write error on file in decompression library: %s (message=%s)")), f, em) + : tl::Exception (tl::to_string (tr ("Write error on file in decompression library: %s (message=%s)")), f, em) { } }; @@ -81,7 +84,7 @@ class ZLibReadErrorException { public: ZLibReadErrorException (const std::string &f, const char *em) - : tl::Exception (tl::to_string (QObject::tr ("Read error on file in decompression library: %s (message=%s)")), f, em) + : tl::Exception (tl::to_string (tr ("Read error on file in decompression library: %s (message=%s)")), f, em) { } }; @@ -90,7 +93,7 @@ class FileOpenErrorException { public: FileOpenErrorException (const std::string &f, int en) - : tl::Exception (tl::to_string (QObject::tr ("Unable to open file: %s (errno=%d)")), f, en) + : tl::Exception (tl::to_string (tr ("Unable to open file: %s (errno=%d)")), f, en) { } }; @@ -99,7 +102,7 @@ class FilePOpenErrorException { public: FilePOpenErrorException (const std::string &f, int en) - : tl::Exception (tl::to_string (QObject::tr ("Unable to get input from command through pipe: %s (errno=%d)")), f, en) + : tl::Exception (tl::to_string (tr ("Unable to get input from command through pipe: %s (errno=%d)")), f, en) { } }; @@ -108,7 +111,7 @@ class FilePReadErrorException { public: FilePReadErrorException (const std::string &f, int en) - : tl::Exception (tl::to_string (QObject::tr ("Read error on pipe from command: %s (errno=%d)")), f, en) + : tl::Exception (tl::to_string (tr ("Read error on pipe from command: %s (errno=%d)")), f, en) { } }; @@ -117,7 +120,7 @@ class FilePWriteErrorException { public: FilePWriteErrorException (const std::string &f, int en) - : tl::Exception (tl::to_string (QObject::tr ("Write error on pipe from command: %s (errno=%d)")), f, en) + : tl::Exception (tl::to_string (tr ("Write error on pipe from command: %s (errno=%d)")), f, en) { } }; @@ -327,16 +330,24 @@ InputStream::InputStream (const std::string &abstract_path) mp_buffer = new char [m_bcap]; tl::Extractor ex (abstract_path.c_str ()); +#if defined(HAVE_CURL) || defined(HAVE_QT) if (ex.test ("http:") || ex.test ("https:")) { mp_delegate = new InputHttpStream (abstract_path); -#ifndef _WIN32 // not available on Windows - } else if (ex.test ("pipe:")) { - mp_delegate = new InputPipe (ex.get ()); + } else #endif - } else if (ex.test ("file:")) { +#if !defined (_WIN32) // not available on Windows + if (ex.test ("pipe:")) { + mp_delegate = new InputPipe (ex.get ()); + } else +#endif +#if defined(HAVE_QT) + // TODO: provide a substitute for QUrl + if (ex.test ("file:")) { QUrl url (tl::to_qstring (abstract_path)); mp_delegate = new InputZLibFile (tl::to_string (url.toLocalFile ())); - } else { + } else +#endif + { mp_delegate = new InputZLibFile (abstract_path); } @@ -350,15 +361,18 @@ std::string InputStream::absolute_path (const std::string &abstract_path) tl::Extractor ex (abstract_path.c_str ()); if (ex.test ("http:") || ex.test ("https:")) { return abstract_path; -#ifndef _WIN32 // not available on Windows +#if !defined(_WIN32) // not available on Windows } else if (ex.test ("pipe:")) { return abstract_path; #endif +#if defined(HAVE_QT) + // TODO: provide a substitute for QUrl } else if (ex.test ("file:")) { QUrl url (tl::to_qstring (abstract_path)); return tl::to_string (QFileInfo (url.toLocalFile ()).absoluteFilePath ()); +#endif } else { - return tl::to_string (QFileInfo (tl::to_qstring (abstract_path)).absoluteFilePath ()); + return tl::absolute_file_path (abstract_path); } } @@ -698,13 +712,13 @@ InputFile::reset () std::string InputFile::absolute_path () const { - return tl::to_string (QFileInfo (tl::to_qstring (m_source)).absoluteFilePath ()); + return tl::absolute_file_path (m_source); } std::string InputFile::filename () const { - return tl::to_string (QFileInfo (tl::to_qstring (m_source)).fileName ()); + return tl::filename (m_source); } // --------------------------------------------------------------- @@ -771,13 +785,13 @@ InputZLibFile::reset () std::string InputZLibFile::absolute_path () const { - return tl::to_string (QFileInfo (tl::to_qstring (m_source)).absoluteFilePath ()); + return tl::absolute_file_path (m_source); } std::string InputZLibFile::filename () const { - return tl::to_string (QFileInfo (tl::to_qstring (m_source)).fileName ()); + return tl::filename (m_source); } // --------------------------------------------------------------------------------- @@ -964,7 +978,7 @@ OutputStream::OutputStream (const std::string &abstract_path, OutputStreamMode o tl::Extractor ex (abstract_path.c_str ()); if (ex.test ("http:") || ex.test ("https:")) { - throw tl::Exception (tl::to_string (QObject::tr ("Cannot write to http:, https: or pipe: URL's"))); + throw tl::Exception (tl::to_string (tr ("Cannot write to http:, https: or pipe: URL's"))); #ifndef _WIN32 // not available on Windows } else if (ex.test ("pipe:")) { mp_delegate = new OutputPipe (ex.get ()); @@ -1213,7 +1227,7 @@ InputPipe::read (char *b, size_t n) void InputPipe::reset () { - throw tl::Exception (tl::to_string (QObject::tr ("'reset' is not supported on pipeline input files"))); + throw tl::Exception (tl::to_string (tr ("'reset' is not supported on pipeline input files"))); } // --------------------------------------------------------------- @@ -1267,19 +1281,19 @@ InputPipe::~InputPipe () size_t InputPipe::read (char * /*b*/, size_t /*n*/) { - throw tl::Exception (tl::to_string (QObject::tr ("pipeline input files not available on Windows"))); + throw tl::Exception (tl::to_string (tr ("pipeline input files not available on Windows"))); } void InputPipe::reset () { - throw tl::Exception (tl::to_string (QObject::tr ("pipeline input files not available on Windows"))); + throw tl::Exception (tl::to_string (tr ("pipeline input files not available on Windows"))); } void InputPipe::close () { - throw tl::Exception (tl::to_string (QObject::tr ("pipeline input files not available on Windows"))); + throw tl::Exception (tl::to_string (tr ("pipeline input files not available on Windows"))); } // --------------------------------------------------------------- @@ -1298,7 +1312,7 @@ OutputPipe::~OutputPipe () void OutputPipe::write (const char * /*b*/, size_t /*n*/) { - throw tl::Exception (tl::to_string (QObject::tr ("pipeline input files not available on Windows"))); + throw tl::Exception (tl::to_string (tr ("pipeline input files not available on Windows"))); } #endif diff --git a/src/tl/tl/tlString.cc b/src/tl/tl/tlString.cc index aaf8ab3a0..dbcd854e6 100644 --- a/src/tl/tl/tlString.cc +++ b/src/tl/tl/tlString.cc @@ -29,6 +29,7 @@ #include #include #include +#include #include "tlString.h" #include "tlExpression.h" @@ -36,6 +37,81 @@ static std::locale c_locale ("C"); +// ------------------------------------------------------------------------- +// Conversion of UTF8 to wchar_t + +static std::vector utf8_to_wchar (const std::string &s) +{ + std::vector ws; + + const char *cpe = s.c_str () + s.size (); + for (const char *cp = s.c_str (); cp < cpe; ) { + + uint32_t c32 = (unsigned char) *cp++; + if (c32 >= 0xf0 && cp + 2 < cpe) { + c32 = (c32 << 18) | ((uint32_t (cp [0]) & 0x3f) << 12) | ((uint32_t (cp [1]) & 0x3f) << 6) | (uint32_t (cp [2]) & 0x3f); + cp += 3; + } else if (c32 >= 0xe0 && cp + 1 < cpe) { + c32 = (c32 << 12) | ((uint32_t (cp [0]) & 0x3f) << 6) | (uint32_t (cp [1]) & 0x3f); + cp += 2; + } else if (c32 >= 0xc0 && cp < cpe) { + c32 = (c32 << 6) | (uint32_t (*cp) & 0x3f); + ++cp; + } + + if (c32 >= 0x10000) { + c32 -= 0x10000; + ws.push_back (wchar_t (0xd800 + (c32 >> 10))); + ws.push_back (wchar_t (0xdc00 + (c32 & 0x3ff))); + } else { + ws.push_back (wchar_t (c32)); + } + + } + + return ws; +} + +static std::string wchar_to_utf8 (const std::vector &ws) +{ + std::string s; + + for (std::vector::const_iterator c = ws.begin (); c != ws.end (); ++c) { + + uint32_t c32 = *c; + if (c32 >= 0xd800 && c + 1 < ws.end ()) { + ++c; + c32 = (c32 & 0x3ff) << 10; + c32 |= uint32_t (*c) & 0x3ff; + } + + if (c32 >= 0x10000) { + + s.push_back (0xf0 | ((c32 >> 18) & 0x7)); + s.push_back (0x80 | ((c32 >> 12) & 0x3f)); + s.push_back (0x80 | ((c32 >> 6) & 0x3f)); + s.push_back (0x80 | (c32 & 0x3f)); + + } else if (c32 >= 0x800) { + + s.push_back (0xf0 | ((c32 >> 12) & 0xf)); + s.push_back (0x80 | ((c32 >> 6) & 0x3f)); + s.push_back (0x80 | (c32 & 0x3f)); + + } else if (c32 >= 0x80) { + + s.push_back (0xf0 | ((c32 >> 6) & 0xc)); + s.push_back (0x80 | (c32 & 0x3f)); + + } else { + s.push_back (char (c32)); + } + + } + + return s; +} + // ------------------------------------------------------------------------- // Utility: a strtod version that is independent of the locale @@ -64,12 +140,44 @@ std::string tl::db_to_string (double d) std::string tl::to_upper_case (const std::string &s) { - return tl::to_string (tl::to_qstring (s).toUpper ()); + std::vector ws = utf8_to_wchar (s); + for (std::vector::iterator c = ws.begin (); c != ws.end (); ++c) { + *c = towupper (*c); + } + return wchar_to_utf8 (ws); } std::string tl::to_lower_case (const std::string &s) { - return tl::to_string (tl::to_qstring (s).toLower ()); + std::vector ws = utf8_to_wchar (s); + for (std::vector::iterator c = ws.begin (); c != ws.end (); ++c) { + *c = towlower (*c); + } + return wchar_to_utf8 (ws); +} + +std::string to_string_from_local (const char *cp) +{ + mbstate_t state; + memset ((void *) &state, 0, sizeof (mbstate_t)); + + std::vector ws; + + size_t max = strlen (cp); + + while (max > 0) { + wchar_t wc; + // NOTE: mbrtowc uses the current LOCALE, hence "local" + int length = mbrtowc (&wc, cp, max, &state); + if (length < 1) { + break; + } + ws.push_back (wc); + cp += length; + max -= length; + } + + return wchar_to_utf8 (ws); } // ------------------------------------------------------------------------- @@ -575,7 +683,7 @@ tl::from_string (const std::string &s, double &v) throw (tl::Exception) ++cp; } if (! *cp) { - throw tl::Exception (tl::to_string (QObject::tr ("Got empty string where a real number was expected"))); + throw tl::Exception (tl::to_string (tr ("Got empty string where a real number was expected"))); } const char *cp_end = cp; v = local_strtod (cp, cp_end); @@ -596,14 +704,14 @@ convert_string_to_int (const std::string &s, T &v) throw (tl::Exception) // HACK: this should be some real string-to-int conversion tl::from_string (s, x); if (x < std::numeric_limits ::min ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Range underflow: ")) + s); + throw tl::Exception (tl::to_string (tr ("Range underflow: ")) + s); } if (x > std::numeric_limits ::max ()) { - throw tl::Exception (tl::to_string (QObject::tr ("Range overflow: ")) + s); + throw tl::Exception (tl::to_string (tr ("Range overflow: ")) + s); } v = T (x); if (x != v) { - throw tl::Exception (tl::to_string (QObject::tr ("Number cannot be represented precisely: ")) + s); + throw tl::Exception (tl::to_string (tr ("Number cannot be represented precisely: ")) + s); } } @@ -656,7 +764,7 @@ tl::from_string (const std::string &s, bool &b) throw (tl::Exception) } else if (t == "0") { b = false; } else { - throw tl::Exception (tl::to_string (QObject::tr ("Invalid boolean value: ")) + s); + throw tl::Exception (tl::to_string (tr ("Invalid boolean value: ")) + s); } } @@ -727,7 +835,7 @@ tl::Extractor & tl::Extractor::read (unsigned int &value) { if (! try_read (value)) { - error (tl::to_string (QObject::tr ("Expected an unsigned integer value"))); + error (tl::to_string (tr ("Expected an unsigned integer value"))); } return *this; } @@ -736,7 +844,7 @@ tl::Extractor & tl::Extractor::read (unsigned long &value) { if (! try_read (value)) { - error (tl::to_string (QObject::tr ("Expected an unsigned long integer value"))); + error (tl::to_string (tr ("Expected an unsigned long integer value"))); } return *this; } @@ -745,7 +853,7 @@ tl::Extractor & tl::Extractor::read (unsigned long long &value) { if (! try_read (value)) { - error (tl::to_string (QObject::tr ("Expected an unsigned long integer value"))); + error (tl::to_string (tr ("Expected an unsigned long integer value"))); } return *this; } @@ -754,7 +862,7 @@ tl::Extractor & tl::Extractor::read (double &value) { if (! try_read (value)) { - error (tl::to_string (QObject::tr ("Expected a real number"))); + error (tl::to_string (tr ("Expected a real number"))); } return *this; } @@ -763,7 +871,7 @@ tl::Extractor & tl::Extractor::read (int &value) { if (! try_read (value)) { - error (tl::to_string (QObject::tr ("Expected a integer value"))); + error (tl::to_string (tr ("Expected a integer value"))); } return *this; } @@ -772,7 +880,7 @@ tl::Extractor & tl::Extractor::read (long &value) { if (! try_read (value)) { - error (tl::to_string (QObject::tr ("Expected a long integer value"))); + error (tl::to_string (tr ("Expected a long integer value"))); } return *this; } @@ -781,7 +889,7 @@ tl::Extractor & tl::Extractor::read (long long &value) { if (! try_read (value)) { - error (tl::to_string (QObject::tr ("Expected a long integer value"))); + error (tl::to_string (tr ("Expected a long integer value"))); } return *this; } @@ -790,7 +898,7 @@ tl::Extractor & tl::Extractor::read (bool &value) { if (! try_read (value)) { - error (tl::to_string (QObject::tr ("Expected a boolean value ('true', 'false')"))); + error (tl::to_string (tr ("Expected a boolean value ('true', 'false')"))); } return *this; } @@ -799,7 +907,7 @@ tl::Extractor & tl::Extractor::read (std::string &value, const char *term) { if (! try_read (value, term)) { - error (tl::to_string (QObject::tr ("Expected a string"))); + error (tl::to_string (tr ("Expected a string"))); } return *this; } @@ -808,7 +916,7 @@ tl::Extractor & tl::Extractor::read_word (std::string &value, const char *non_term) { if (! try_read_word (value, non_term)) { - error (tl::to_string (QObject::tr ("Expected a word string"))); + error (tl::to_string (tr ("Expected a word string"))); } return *this; } @@ -817,7 +925,7 @@ tl::Extractor & tl::Extractor::read_word_or_quoted (std::string &value, const char *non_term) { if (! try_read_word (value, non_term) && ! try_read_quoted (value)) { - error (tl::to_string (QObject::tr ("Expected a word or quoted string"))); + error (tl::to_string (tr ("Expected a word or quoted string"))); } return *this; } @@ -826,7 +934,7 @@ tl::Extractor & tl::Extractor::read_quoted (std::string &value) { if (! try_read_quoted (value)) { - error (tl::to_string (QObject::tr ("Expected a quoted string"))); + error (tl::to_string (tr ("Expected a quoted string"))); } return *this; } @@ -839,7 +947,7 @@ namespace { std::string operator() () const { - return tl::to_string (QObject::tr ("Range overflow on long long integer")); + return tl::to_string (tr ("Range overflow on long long integer")); } }; @@ -847,7 +955,7 @@ namespace { std::string operator() () const { - return tl::to_string (QObject::tr ("Range overflow on unsigned long long integer")); + return tl::to_string (tr ("Range overflow on unsigned long long integer")); } }; @@ -855,7 +963,7 @@ namespace { std::string operator() () const { - return tl::to_string (QObject::tr ("Range overflow on long integer")); + return tl::to_string (tr ("Range overflow on long integer")); } }; @@ -863,7 +971,7 @@ namespace { std::string operator() () const { - return tl::to_string (QObject::tr ("Range overflow on unsigned long integer")); + return tl::to_string (tr ("Range overflow on unsigned long integer")); } }; @@ -871,7 +979,7 @@ namespace { std::string operator() () const { - return tl::to_string (QObject::tr ("Range overflow on integer")); + return tl::to_string (tr ("Range overflow on integer")); } }; @@ -879,7 +987,7 @@ namespace { std::string operator() () const { - return tl::to_string (QObject::tr ("Range overflow on unsigned integer")); + return tl::to_string (tr ("Range overflow on unsigned integer")); } }; } @@ -1096,7 +1204,7 @@ tl::Extractor & tl::Extractor::expect_end () { if (! at_end ()) { - error (tl::to_string (QObject::tr ("Expected end of text"))); + error (tl::to_string (tr ("Expected end of text"))); } return *this; } @@ -1105,7 +1213,7 @@ tl::Extractor & tl::Extractor::expect_more () { if (at_end ()) { - error (tl::to_string (QObject::tr ("Expected more text"))); + error (tl::to_string (tr ("Expected more text"))); } return *this; } @@ -1114,7 +1222,7 @@ tl::Extractor & tl::Extractor::expect (const char *token) { if (! test (token)) { - error (tl::sprintf (tl::to_string (QObject::tr ("Expected '%s'")).c_str (), token)); + error (tl::sprintf (tl::to_string (tr ("Expected '%s'")).c_str (), token)); } return *this; } @@ -1156,9 +1264,9 @@ tl::Extractor::error (const std::string &msg) std::string m (msg); if (at_end ()) { - m += tl::to_string (QObject::tr (", but text ended")); + m += tl::to_string (tr (", but text ended")); } else { - m += tl::to_string (QObject::tr (" here: ")); + m += tl::to_string (tr (" here: ")); const char *cp = m_cp; for (unsigned int i = 0; i < 10 && *cp; ++i, ++cp) { m += *cp; diff --git a/src/tl/tl/tlString.h b/src/tl/tl/tlString.h index 11c8b05a4..4b2c7817f 100644 --- a/src/tl/tl/tlString.h +++ b/src/tl/tl/tlString.h @@ -261,6 +261,7 @@ TL_PUBLIC std::string to_string (double d, int prec); TL_PUBLIC std::string to_string (float d, int prec); TL_PUBLIC std::string to_string (const unsigned char *cp, int length); TL_PUBLIC std::string to_string (const char *cp, int length); +TL_PUBLIC std::string to_string_from_local (const char *cp); template inline std::string to_string (const T &o) { return o.to_string (); } template <> inline std::string to_string (const double &d) { return to_string (d, 12); } diff --git a/src/tl/tl/tlThreadedWorkers.cc b/src/tl/tl/tlThreadedWorkers.cc index 16a3e7c5a..707f5a7b5 100644 --- a/src/tl/tl/tlThreadedWorkers.cc +++ b/src/tl/tl/tlThreadedWorkers.cc @@ -189,11 +189,11 @@ JobBase::~JobBase () void JobBase::log_error (const std::string &s) { - tl::error << tl::to_string (QObject::tr ("Worker thread: ")) << s; + tl::error << tl::to_string (tr ("Worker thread: ")) << s; m_lock.lock (); if (m_error_messages.size () == max_errors) { - m_error_messages.push_back (tl::to_string (QObject::tr ("Error list abbreviated (more errors were ignored)"))); + m_error_messages.push_back (tl::to_string (tr ("Error list abbreviated (more errors were ignored)"))); } else if (m_error_messages.size () < max_errors) { m_error_messages.push_back (s); } @@ -293,7 +293,7 @@ JobBase::start () } catch (std::exception &ex) { log_error (ex.what ()); } catch (...) { - log_error (tl::to_string (QObject::tr ("Unspecific error"))); + log_error (tl::to_string (tr ("Unspecific error"))); } } @@ -324,7 +324,7 @@ JobBase::wait (long timeout) bool status = true; m_lock.lock (); - if (m_nworkers > 0 && m_running && ! m_queue_empty_condition.wait (&m_lock, timeout >= 0 ? (unsigned long) timeout : ULONG_MAX)) { + if (m_nworkers > 0 && m_running && ! m_queue_empty_condition.wait (&m_lock, timeout >= 0 ? (unsigned long) timeout : std::numeric_limits::max ())) { status = false; } m_lock.unlock (); @@ -567,7 +567,7 @@ Worker::start (JobBase *job, int worker_index) { mp_job = job; m_worker_index = worker_index; - QThread::start (); + tl::Thread::start (); } void @@ -598,7 +598,7 @@ Worker::run () } catch (std::exception &ex) { mp_job->log_error (ex.what ()); } catch (...) { - mp_job->log_error (tl::to_string (QObject::tr ("Unspecific error"))); + mp_job->log_error (tl::to_string (tr ("Unspecific error"))); } } } diff --git a/src/tl/tl/tlThreadedWorkers.h b/src/tl/tl/tlThreadedWorkers.h index b91b6aa68..0dc414b1d 100644 --- a/src/tl/tl/tlThreadedWorkers.h +++ b/src/tl/tl/tlThreadedWorkers.h @@ -25,10 +25,7 @@ #define HDR_tlThreadedWorkers #include "tlCommon.h" - -#include -#include -#include +#include "tlThreads.h" #include #include @@ -268,9 +265,9 @@ private: bool m_stopping; bool m_running; - QMutex m_lock; - QWaitCondition m_task_available_condition; - QWaitCondition m_queue_empty_condition; + tl::Mutex m_lock; + tl::WaitCondition m_task_available_condition; + tl::WaitCondition m_queue_empty_condition; std::vector mp_workers; std::set m_bosses; @@ -313,7 +310,7 @@ protected: * A worker is provided with a sequence of tasks with define the operations that the * worker is supposed to perform. */ -class TL_PUBLIC Worker : protected QThread +class TL_PUBLIC Worker : protected tl::Thread { public: friend class JobBase; diff --git a/src/tl/tl/tlThreads.cc b/src/tl/tl/tlThreads.cc new file mode 100644 index 000000000..68f36ac68 --- /dev/null +++ b/src/tl/tl/tlThreads.cc @@ -0,0 +1,22 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2018 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + diff --git a/src/tl/tl/tlThreads.h b/src/tl/tl/tlThreads.h new file mode 100644 index 000000000..6ee35a886 --- /dev/null +++ b/src/tl/tl/tlThreads.h @@ -0,0 +1,191 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2018 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#ifndef HDR_tlThreads +#define HDR_tlThreads + +#include "tlCommon.h" + +#include + +namespace tl +{ + +/** + * @brief A mutex implementation + * This class acts as an abstraction. Qt-based and other implementations are + * available. + */ + +#if defined(HAVE_QT) + +class TL_PUBLIC Mutex + : public QMutex +{ +public: + Mutex () : QMutex () { } +}; + +#else + +// The non-Qt version is a dummy implementation as threading is not supported (yet) +class TL_PUBLIC Mutex +{ +public: + Mutex () { } + void lock () { } + void unlock () { } +}; + +#endif + +/** + * @brief A wait condition implementation + * This class acts as an abstraction. Qt-based and other implementations are + * available. + */ + +#if defined(HAVE_QT) + +class TL_PUBLIC WaitCondition + : public QWaitCondition +{ +public: + WaitCondition () : QWaitCondition () { } + + bool wait (Mutex *mutex, unsigned long time = std::numeric_limits::max ()) { QWaitCondition::wakt (mutex, time); } +}; + +#else + +// The non-Qt version is a dummy implementation as threading is not supported (yet) +class TL_PUBLIC WaitCondition +{ +public: + WaitCondition () { } + bool wait (Mutex * /*mutex*/, unsigned long /*time*/ = std::numeric_limits::max ()) { return true; } + void wakeAll () { } + void wakeOne () { } +}; + +#endif + +/** + * @brief A RAII-based Mutex locker + */ +class TL_PUBLIC MutexLocker +{ +public: + MutexLocker (Mutex *mutex) + : mp_mutex (mutex) + { + mp_mutex->lock (); + } + + ~MutexLocker () + { + mp_mutex->unlock (); + } + +private: + Mutex *mp_mutex; +}; + +/** + * @brief A thread implementation + * This class acts as an abstraction. Qt-based and other implementations are + * available. + */ + +#if defined(HAVE_QT) + +public TL_PUBLIC Thread + : public QThread +{ +public: + Thread () + : QThread () + { } +}; + +#else + +// TODO: this is a non-threaded dummy implementation +class TL_PUBLIC Thread +{ +public: + Thread () { } + virtual ~Thread () { } + + void exit (int /*returnCode*/ = 0) { } + bool isFinished () const { return true; } + bool isRunning () const { return false; } + void quit () { } + void start () { run (); } + void terminate () { } + bool wait (unsigned long /*time*/ = std::numeric_limits::max ()) { return true; } + +protected: + virtual void run () { } +}; + +#endif + +/** + * @brief A thread local storage implementation + * This class acts as an abstraction. Qt-based and other implementations are + * available. + */ + +#if defined(HVE_QT) + +template +class TL_PUBLIC ThreadStorage + : public QThreadStorage +{ +public: + ThreadStorage () : QThreadStorage () { } +}; + +#else + +// TODO: this is the non-threaded dummy implementation +template +class TL_PUBLIC ThreadStorage +{ +public: + ThreadStorage () : m_t () { } + + bool hasLocalData () const { return true; } + T &localData () { return m_t; } + T localData () const { return m_t; } + void setLocalData (T data) { m_t = data; } + +private: + T m_t; +}; + +#endif + +} + +#endif diff --git a/src/tl/tl/tlTimer.cc b/src/tl/tl/tlTimer.cc index df3819210..b3b86ded3 100644 --- a/src/tl/tl/tlTimer.cc +++ b/src/tl/tl/tlTimer.cc @@ -25,8 +25,6 @@ #include "tlLog.h" #include "tlString.h" -#include - #ifndef _WIN32 # include #endif @@ -42,15 +40,14 @@ namespace tl { // ------------------------------------------------------------- -// Implementation of msecs_to +// Gets the current time in ms from epoch -int64_t msecs_to (const QDateTime &from, const QDateTime &to) +static int64_t ms_time () { -#if QT_VERSION >= 0x040700 - return from.msecsTo (to); -#else - return int64_t (from.secsTo (to)) * 1000 + (from.time ().msecsTo (to.time ()) % 1000); -#endif + struct timespec spec; + clock_gettime (CLOCK_REALTIME, &spec); + + return int64_t (spec.tv_sec) * 1000 + int64_t (0.5 + spec.tv_nsec / 1.0e6); } // ------------------------------------------------------------- @@ -78,7 +75,11 @@ Timer::start () m_user_ms += (timer_t) ((clks.tms_utime + clks.tms_cutime) * clk2msec + 0.5); m_sys_ms += (timer_t) ((clks.tms_stime + clks.tms_cstime) * clk2msec + 0.5); #endif - m_wall_ms += msecs_to (QDateTime::fromTime_t (0), QDateTime::currentDateTime ()); + + struct timespec spec; + clock_gettime (CLOCK_REALTIME, &spec); + + m_wall_ms = ms_time (); } void @@ -202,7 +203,7 @@ Clock Clock::current () { Clock c; - c.m_clock_ms += msecs_to (QDateTime::fromTime_t (0), QDateTime::currentDateTime ()); + c.m_clock_ms += ms_time (); return c; } diff --git a/src/tl/tl/tlUnitTest.cc b/src/tl/tl/tlUnitTest.cc index 65159cfb4..d743d95cc 100644 --- a/src/tl/tl/tlUnitTest.cc +++ b/src/tl/tl/tlUnitTest.cc @@ -25,7 +25,6 @@ #include "tlTimer.h" #include "tlStream.h" -#include #include namespace tl @@ -95,11 +94,11 @@ std::string testsrc () std::string testsrc_private () { - QDir d (QDir (tl::to_qstring (tl::testsrc ())).filePath (QString::fromUtf8 ("private"))); - if (! d.exists ()) { + std::string pp = tl::combine_path (tl::testsrc (), "private"); + if (! tl::file_exists (pp)) { throw tl::CancelException (); } - return tl::to_string (d.path ()); + return pp; } std::string testtmp () @@ -206,9 +205,8 @@ TestRegistrar::tests () const TestBase::TestBase (const std::string &file, const std::string &name) : m_editable (false), m_slow (false), m_cp_line (0), m_any_failed (false) { - QFileInfo f (tl::to_qstring (file)); - m_test = tl::to_string (f.baseName ()) + ":" + name; - m_testdir = tl::to_string (f.baseName ()) + "_" + name; + m_test = tl::basename (file) + ":" + name; + m_testdir = tl::basename (file) + "_" + name; tl::TestRegistrar::reg (this); } @@ -218,17 +216,15 @@ bool TestBase::do_test (bool editable, bool slow) m_slow = slow; // Ensures the test temp directory is present - QDir dir (tl::to_qstring (testtmp ())); - QDir tmpdir (dir.absoluteFilePath (tl::to_qstring (m_testdir))); - if (tmpdir.exists () && ! tl::rm_dir_recursive (tmpdir.absolutePath ())) { - throw tl::Exception ("Unable to clean temporary dir: " + tl::to_string (tmpdir.absolutePath ())); + std::string tmpdir = tl::combine_path (tl::absolute_file_path (testtmp ()), m_testdir); + if (tl::file_exists (tmpdir) && ! tl::rm_dir_recursive (tmpdir)) { + throw tl::Exception ("Unable to clean temporary dir: " + tmpdir); } - if (! dir.mkpath (tl::to_qstring (m_testdir))) { - throw tl::Exception ("Unable to create path for temporary files: " + tl::to_string (tmpdir.absolutePath ())); + if (! tl::mkpath (tmpdir)) { + throw tl::Exception ("Unable to create path for temporary files: " + tmpdir); } - dir.cd (tl::to_qstring (m_testdir)); - m_testtmp = dir.absolutePath (); + m_testtmp = tmpdir; static std::string testname_value; static std::string testtmp_value; @@ -238,7 +234,7 @@ bool TestBase::do_test (bool editable, bool slow) putenv (const_cast (testname_value.c_str ())); putenv (const_cast ("TESTTMP_WITH_NAME=")); - testtmp_value = std::string ("TESTTMP_WITH_NAME=") + m_testtmp.toUtf8().constData(); + testtmp_value = std::string ("TESTTMP_WITH_NAME=") + m_testtmp; putenv (const_cast (testtmp_value.c_str ())); reset_checkpoint (); @@ -252,42 +248,8 @@ bool TestBase::do_test (bool editable, bool slow) std::string TestBase::tmp_file (const std::string &fn) const { - tl_assert (! m_testtmp.isEmpty ()); - QDir dir (m_testtmp); - return tl::to_string (dir.absoluteFilePath (tl::to_qstring (fn))); -} - -/** - * @brief Recursively empties a directory - */ -static void empty_dir (QDir dir) -{ - QStringList entries = dir.entryList (QDir::AllEntries | QDir::NoDotAndDotDot); - for (QStringList::const_iterator e = entries.begin (); e != entries.end (); ++e) { - QString epath = dir.absoluteFilePath (*e); - if (QFileInfo (epath).isDir ()) { - empty_dir (QDir (epath)); - dir.rmdir (*e); - } else if (! dir.remove (*e)) { - throw tl::Exception ("Unable to remove file or directory: " + tl::to_string (dir.filePath (*e))); - } - } -} - -void TestBase::remove_tmp_folder () -{ - // Ensures the test temp directory is present - QDir dir (tl::to_qstring (testtmp ())); - if (dir.cd (tl::to_qstring (m_test))) { - - empty_dir (dir); - - dir.cdUp (); - if (! dir.rmdir (tl::to_qstring (m_test))) { - throw tl::Exception ("Unable to remove directory: " + tl::to_string (dir.filePath (tl::to_qstring (m_test)))); - } - - } + tl_assert (! m_testtmp.empty ()); + return tl::combine_path (m_testtmp, fn); } void TestBase::checkpoint (const std::string &file, int line) @@ -359,13 +321,8 @@ void TestBase::write_detailed_diff (std::ostream &os, const std::string &subject static std::string read_file (const std::string &path) { - QFile file (tl::to_qstring (path)); - if (! file.open (QIODevice::ReadOnly | QIODevice::Text)) { - tl::warn << tl::sprintf ("Unable to open file %s", path); - } - - QByteArray ba = file.readAll (); - return std::string (ba.constData (), 0, ba.size ()); + tl::InputStream s (path); + return s.read_all (); } void TestBase::compare_text_files (const std::string &path_a, const std::string &path_b) @@ -375,8 +332,8 @@ void TestBase::compare_text_files (const std::string &path_a, const std::string if (text_a != text_b) { raise (tl::sprintf ("Compare failed - see:\n file 1: %s\n file 2: %s", - tl::to_string (QFileInfo (tl::to_qstring (path_a)).absoluteFilePath ()), - tl::to_string (QFileInfo (tl::to_qstring (path_b)).absoluteFilePath ()))); + tl::absolute_file_path (path_a), + tl::absolute_file_path (path_b))); } } diff --git a/src/tl/tl/tlUnitTest.h b/src/tl/tl/tlUnitTest.h index 66aea9fde..846e6c877 100644 --- a/src/tl/tl/tlUnitTest.h +++ b/src/tl/tl/tlUnitTest.h @@ -32,8 +32,6 @@ #include #include #include -#include - namespace tl { /** @@ -296,11 +294,6 @@ public: */ std::string tmp_file (const std::string &fn = "tmp") const; - /** - * @brief Removes all temporary files - */ - void remove_tmp_folder (); - /** * @brief A generic diff printer */ @@ -468,7 +461,7 @@ private: std::string m_cp_file; int m_cp_line; bool m_any_failed; - QString m_testtmp; + std::string m_testtmp; }; /** diff --git a/src/tl/tl/tlVariant.cc b/src/tl/tl/tlVariant.cc index 322e17820..fb5ab023e 100644 --- a/src/tl/tl/tlVariant.cc +++ b/src/tl/tl/tlVariant.cc @@ -27,56 +27,61 @@ #include #include -#include -#include + +#if defined(HAVE_QT) + +# include +# include // the Qt classes supported by QVariant: -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if QT_VERSION >= 0x040600 -# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# if QT_VERSION >= 0x040600 +# include +# endif +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include + #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include namespace tl { @@ -233,6 +238,8 @@ Variant::Variant () // .. nothing yet .. } +#if defined(HAVE_QT) + Variant::Variant (const QByteArray &qba) : m_type (t_qbytearray), m_string (0) { @@ -245,124 +252,7 @@ Variant::Variant (const QString &qs) m_var.m_qstring = new QString (qs); } -Variant::Variant (const std::string &s) - : m_type (t_stdstring), m_string (0) -{ - m_var.m_stdstring = new std::string (s); -} - -Variant::Variant (const char *s) - : m_type (t_string) -{ - m_string = new char [strlen (s) + 1]; - strcpy (m_string, s); -} - -Variant::Variant (double d) - : m_type (t_double), m_string (0) -{ - m_var.m_double = d; -} - -Variant::Variant (float d) - : m_type (t_float), m_string (0) -{ - m_var.m_float = d; -} - -Variant::Variant (bool b) - : m_type (t_bool), m_string (0) -{ - m_var.m_bool = b; -} - -Variant::Variant (char c) - : m_type (t_char), m_string (0) -{ - m_var.m_char = c; -} - -Variant::Variant (signed char c) - : m_type (t_schar), m_string (0) -{ - m_var.m_schar = c; -} - -Variant::Variant (unsigned char c) - : m_type (t_uchar), m_string (0) -{ - m_var.m_uchar = c; -} - -Variant::Variant (short s) - : m_type (t_short), m_string (0) -{ - m_var.m_short = s; -} - -Variant::Variant (unsigned short s) - : m_type (t_ushort), m_string (0) -{ - m_var.m_ushort = s; -} - -Variant::Variant (int l) - : m_type (t_int), m_string (0) -{ - m_var.m_int = l; -} - -Variant::Variant (unsigned int l) - : m_type (t_uint), m_string (0) -{ - m_var.m_uint = l; -} - -Variant::Variant (long long l) - : m_type (t_longlong), m_string (0) -{ - m_var.m_longlong = l; -} - -Variant::Variant (unsigned long long l) - : m_type (t_ulonglong), m_string (0) -{ - m_var.m_ulonglong = l; -} - -#if defined(HAVE_64BIT_COORD) -Variant::Variant (__int128 l) - : m_type (t_int128), m_string (0) -{ - m_var.m_int128 = l; -} -#endif - -Variant::Variant (long l) - : m_type (t_long), m_string (0) -{ - m_var.m_long = l; -} - -Variant::Variant (unsigned long l) - : m_type (t_ulong), m_string (0) -{ - m_var.m_ulong = l; -} - -Variant::Variant (size_t l, bool /*dummy*/) - : m_type (t_id), m_string (0) -{ - m_var.m_id = l; -} - -Variant::Variant (const Variant &v) - : m_type (t_nil), m_string (0) -{ - operator= (v); -} - -Variant::Variant (const QVariant &v) +Variant::Variant (const QVariant &v) : m_type (t_nil), m_string (0) { switch (v.type ()) { @@ -549,6 +439,125 @@ Variant::Variant (const QVariant &v) } } +#endif + +Variant::Variant (const std::string &s) + : m_type (t_stdstring), m_string (0) +{ + m_var.m_stdstring = new std::string (s); +} + +Variant::Variant (const char *s) + : m_type (t_string) +{ + m_string = new char [strlen (s) + 1]; + strcpy (m_string, s); +} + +Variant::Variant (double d) + : m_type (t_double), m_string (0) +{ + m_var.m_double = d; +} + +Variant::Variant (float d) + : m_type (t_float), m_string (0) +{ + m_var.m_float = d; +} + +Variant::Variant (bool b) + : m_type (t_bool), m_string (0) +{ + m_var.m_bool = b; +} + +Variant::Variant (char c) + : m_type (t_char), m_string (0) +{ + m_var.m_char = c; +} + +Variant::Variant (signed char c) + : m_type (t_schar), m_string (0) +{ + m_var.m_schar = c; +} + +Variant::Variant (unsigned char c) + : m_type (t_uchar), m_string (0) +{ + m_var.m_uchar = c; +} + +Variant::Variant (short s) + : m_type (t_short), m_string (0) +{ + m_var.m_short = s; +} + +Variant::Variant (unsigned short s) + : m_type (t_ushort), m_string (0) +{ + m_var.m_ushort = s; +} + +Variant::Variant (int l) + : m_type (t_int), m_string (0) +{ + m_var.m_int = l; +} + +Variant::Variant (unsigned int l) + : m_type (t_uint), m_string (0) +{ + m_var.m_uint = l; +} + +Variant::Variant (long long l) + : m_type (t_longlong), m_string (0) +{ + m_var.m_longlong = l; +} + +Variant::Variant (unsigned long long l) + : m_type (t_ulonglong), m_string (0) +{ + m_var.m_ulonglong = l; +} + +#if defined(HAVE_64BIT_COORD) +Variant::Variant (__int128 l) + : m_type (t_int128), m_string (0) +{ + m_var.m_int128 = l; +} +#endif + +Variant::Variant (long l) + : m_type (t_long), m_string (0) +{ + m_var.m_long = l; +} + +Variant::Variant (unsigned long l) + : m_type (t_ulong), m_string (0) +{ + m_var.m_ulong = l; +} + +Variant::Variant (size_t l, bool /*dummy*/) + : m_type (t_id), m_string (0) +{ + m_var.m_id = l; +} + +Variant::Variant (const Variant &v) + : m_type (t_nil), m_string (0) +{ + operator= (v); +} + Variant::~Variant () { reset (); @@ -565,10 +574,12 @@ Variant::reset () delete m_var.m_list; } else if (m_type == t_array) { delete m_var.m_array; +#if defined(HAVE_QT) } else if (m_type == t_qstring) { delete m_var.m_qstring; } else if (m_type == t_qbytearray) { delete m_var.m_qbytearray; +#endif } else if (m_type == t_stdstring) { delete m_var.m_stdstring; } else if (m_type == t_user_ref) { @@ -611,6 +622,8 @@ Variant::operator= (const std::string &s) return *this; } +#if defined(HAVE_QT) + Variant & Variant::operator= (const QByteArray &qs) { @@ -639,6 +652,8 @@ Variant::operator= (const QString &qs) return *this; } +#endif + Variant & Variant::operator= (double d) { @@ -822,10 +837,12 @@ Variant::operator= (const Variant &v) #endif } else if (m_type == t_id) { m_var.m_id = v.m_var.m_id; +#if defined(HAVE_QT) } else if (m_type == t_qstring) { m_var.m_qstring = new QString (*v.m_var.m_qstring); } else if (m_type == t_qbytearray) { m_var.m_qbytearray = new QByteArray (*v.m_var.m_qbytearray); +#endif } else if (m_type == t_stdstring) { m_var.m_stdstring = new std::string (*v.m_var.m_stdstring); } else if (m_type == t_string) { @@ -911,8 +928,10 @@ normalized_type (Variant::type type) #endif case Variant::t_bool: case Variant::t_nil: +#if defined(HAVE_QT) case Variant::t_qstring: case Variant::t_qbytearray: +#endif return type; } } @@ -970,10 +989,12 @@ Variant::operator== (const tl::Variant &d) const return to_double () == d.to_double (); } else if (t == t_string) { return strcmp (to_string (), d.to_string ()) == 0; +#if defined(HAVE_QT) } else if (t == t_qstring) { return *m_var.m_qstring == *d.m_var.m_qstring; } else if (t == t_qbytearray) { return *m_var.m_qbytearray == *d.m_var.m_qbytearray; +#endif } else if (t == t_list) { return *m_var.m_list == *d.m_var.m_list; } else if (t == t_array) { @@ -1021,10 +1042,12 @@ Variant::operator< (const tl::Variant &d) const return to_double () < d.to_double (); } else if (t == t_string) { return strcmp (to_string (), d.to_string ()) < 0; +#if defined(HAVE_QT) } else if (t == t_qstring) { return *m_var.m_qstring < *d.m_var.m_qstring; } else if (t == t_qbytearray) { return *m_var.m_qbytearray < *d.m_var.m_qbytearray; +#endif } else if (t == t_list) { return *m_var.m_list < *d.m_var.m_list; } else if (t == t_array) { @@ -1072,8 +1095,10 @@ Variant::can_convert_to_float () const return true; case t_double: return m_var.m_double < std::numeric_limits::max () && m_var.m_double > std::numeric_limits::min (); +#if defined(HAVE_QT) case t_qstring: case t_qbytearray: +#endif case t_stdstring: case t_string: { @@ -1109,8 +1134,10 @@ Variant::can_convert_to_double () const case t_bool: case t_nil: return true; +#if defined(HAVE_QT) case t_qstring: case t_qbytearray: +#endif case t_stdstring: case t_string: { @@ -1146,8 +1173,10 @@ Variant::can_convert_to_int128 () const case t_nil: return true; case t_string: +#if defined(HAVE_QT) case t_qstring: case t_qbytearray: +#endif case t_stdstring: // TODO: there is no range checking currently return true; @@ -1190,8 +1219,10 @@ Variant::can_convert_to_ulonglong () const case t_int: return m_var.m_int >= 0; case t_string: +#if defined(HAVE_QT) case t_qstring: case t_qbytearray: +#endif case t_stdstring: { tl::Extractor ex (to_string ()); @@ -1235,8 +1266,10 @@ Variant::can_convert_to_longlong () const case t_nil: return true; case t_string: +#if defined(HAVE_QT) case t_qstring: case t_qbytearray: +#endif case t_stdstring: { tl::Extractor ex (to_string ()); @@ -1286,8 +1319,10 @@ Variant::can_convert_to_ulong () const case t_int: return m_var.m_int >= 0; case t_string: +#if defined(HAVE_QT) case t_qstring: case t_qbytearray: +#endif case t_stdstring: { tl::Extractor ex (to_string ()); @@ -1333,8 +1368,10 @@ Variant::can_convert_to_long () const case t_nil: return true; case t_string: +#if defined(HAVE_QT) case t_qstring: case t_qbytearray: +#endif case t_stdstring: { tl::Extractor ex (to_string ()); @@ -1382,8 +1419,10 @@ Variant::can_convert_to_int () const case t_nil: return true; case t_string: +#if defined(HAVE_QT) case t_qstring: case t_qbytearray: +#endif case t_stdstring: { tl::Extractor ex (to_string ()); @@ -1431,8 +1470,10 @@ Variant::can_convert_to_uint () const case t_nil: return true; case t_string: +#if defined(HAVE_QT) case t_qstring: case t_qbytearray: +#endif case t_stdstring: { tl::Extractor ex (to_string ()); @@ -1478,6 +1519,8 @@ Variant::can_convert_to_uchar () const return can_convert_to_long () && (to_short () <= (long) std::numeric_limits::max () && to_short () >= (long) std::numeric_limits::min ()); } +#if defined(HAVE_QT) + QByteArray Variant::to_qbytearray () const { @@ -1506,15 +1549,19 @@ Variant::to_qstring () const } } +#endif + std::string Variant::to_stdstring () const { if (m_type == t_stdstring) { return *m_var.m_stdstring; +#if defined(HAVE_QT) } else if (m_type == t_qstring) { return tl::to_string (*m_var.m_qstring); } else if (m_type == t_qbytearray) { return std::string (m_var.m_qbytearray->constData (), m_var.m_qbytearray->size ()); +#endif } else { return std::string (to_string ()); } @@ -1527,10 +1574,12 @@ Variant::to_string () const return m_var.m_stdstring->c_str (); +#if defined(HAVE_QT) } else if (m_type == t_qbytearray) { // TODO: content may be longer - const char * terminates at first 0 character return m_var.m_qbytearray->constData (); +#endif // conversion needed } else if (! m_string) { @@ -1571,10 +1620,12 @@ Variant::to_string () const #endif } else if (m_type == t_bool) { r = tl::to_string (m_var.m_bool); +#if defined(HAVE_QT) } else if (m_type == t_qstring) { r = tl::to_string (*m_var.m_qstring); } else if (m_type == t_qbytearray) { r = std::string (m_var.m_qbytearray->constData (), m_var.m_qbytearray->size ()); +#endif } else if (m_type == t_list) { for (std::vector::const_iterator v = m_var.m_list->begin (); v != m_var.m_list->end (); ++v) { if (v != m_var.m_list->begin ()) { @@ -1657,17 +1708,25 @@ Variant::to_int128 () const return m_var.m_longlong; } else if (m_type == t_bool) { return m_var.m_bool; - } else if (m_type == t_stdstring) { - tl::Extractor ex (m_var.m_stdstring->c_str ()); - __int128 l = 0; - ex.read (l); - return l; +#if defined(HAVE_QT) } else if (m_type == t_qbytearray) { tl::Extractor ex (m_var.m_qbytearray->constData ()); __int128 l = 0; ex.read (l); return l; - } else if (m_type == t_string || m_type == t_qstring) { + } else if (m_type == t_qstring) { + std::string s (to_string ()); + tl::Extractor ex (s.c_str ()); + __int128 l = 0; + ex.read (l); + return l; +#endif + } else if (m_type == t_stdstring) { + tl::Extractor ex (m_var.m_stdstring->c_str ()); + __int128 l = 0; + ex.read (l); + return l; + } else if (m_type == t_string) { std::string s (to_string ()); tl::Extractor ex (s.c_str ()); __int128 l = 0; @@ -1720,7 +1779,11 @@ Variant::to_ulonglong () const unsigned long long l = 0; tl::from_string (*m_var.m_stdstring, l); return l; +#if defined(HAVE_QT) } else if (m_type == t_string || m_type == t_qstring || m_type == t_qbytearray) { +#else + } else if (m_type == t_string) { +#endif unsigned long long l = 0; tl::from_string (to_string (), l); return l; @@ -1770,7 +1833,11 @@ Variant::to_longlong () const long long l = 0; tl::from_string (*m_var.m_stdstring, l); return l; +#if defined(HAVE_QT) } else if (m_type == t_string || m_type == t_qstring || m_type == t_qbytearray) { +#else + } else if (m_type == t_string) { +#endif long long l = 0; tl::from_string (to_string (), l); return l; @@ -1820,7 +1887,11 @@ Variant::to_ulong () const unsigned long l = 0; tl::from_string (*m_var.m_stdstring, l); return l; +#if defined(HAVE_QT) } else if (m_type == t_string || m_type == t_qstring || m_type == t_qbytearray) { +#else + } else if (m_type == t_string) { +#endif unsigned long l = 0; tl::from_string (to_string (), l); return l; @@ -1870,7 +1941,11 @@ Variant::to_long () const long l = 0; tl::from_string (*m_var.m_stdstring, l); return l; +#if defined(HAVE_QT) } else if (m_type == t_string || m_type == t_qstring || m_type == t_qbytearray) { +#else + } else if (m_type == t_string) { +#endif long l = 0; tl::from_string (to_string (), l); return l; @@ -1972,7 +2047,11 @@ Variant::to_double () const double d = 0; tl::from_string (*m_var.m_stdstring, d); return d; +#if defined(HAVE_QT) } else if (m_type == t_string || m_type == t_qstring || m_type == t_qbytearray) { +#else + } else if (m_type == t_string) { +#endif double d = 0; tl::from_string (to_string (), d); return d; @@ -2029,10 +2108,12 @@ Variant::native_ptr () const return &m_var.m_uint; case t_string: return m_string; +#if defined(HAVE_QT) case t_qstring: return m_var.m_qstring; case t_qbytearray: return m_var.m_qbytearray; +#endif case t_stdstring: return m_var.m_stdstring; case t_array: @@ -2116,7 +2197,11 @@ Variant::to_parsable_string () const return "nil"; } else if (is_stdstring ()) { return tl::to_quoted_string (*m_var.m_stdstring); +#if defined(HAVE_QT) } else if (is_cstring () || is_qstring () || is_qbytearray ()) { +#else + } else if (is_cstring ()) { +#endif return tl::to_quoted_string (to_string ()); } else if (is_list ()) { std::string r = "("; @@ -2177,6 +2262,8 @@ tl::Variant::swap (tl::Variant &other) std::swap (m_string, other.m_string); } +#if defined(HAVE_QT) + QVariant Variant::to_qvariant () const { switch (m_type) { @@ -2217,14 +2304,16 @@ QVariant Variant::to_qvariant () const #endif case t_bool: return QVariant (m_var.m_bool); - case t_qstring: - return QVariant (*m_var.m_qstring); case t_stdstring: return QVariant (tl::to_qstring (*m_var.m_stdstring)); case t_string: return QVariant (tl::to_qstring (m_string)); +#if defined(HAVE_QT) + case t_qstring: + return QVariant (*m_var.m_qstring); case t_qbytearray: return QVariant (*m_var.m_qbytearray); +#endif case t_list: { QList l; @@ -2340,6 +2429,8 @@ QVariant Variant::to_qvariant () const } } +#endif + void Variant::set_user_object (void *obj, bool shared) { m_var.mp_user.object = obj; @@ -2527,7 +2618,7 @@ template <> TL_PUBLIC void extractor_impl (tl::Extractor &ex, tl::Variant &v) { if (! test_extractor_impl (ex, v)) { - ex.error (tl::to_string (QObject::tr ("Expected a value specification"))); + ex.error (tl::to_string (tr ("Expected a value specification"))); } } diff --git a/src/tl/tl/tlVariant.h b/src/tl/tl/tlVariant.h index df9fda803..587a57293 100644 --- a/src/tl/tl/tlVariant.h +++ b/src/tl/tl/tlVariant.h @@ -36,9 +36,11 @@ #include "tlAssert.h" #include "tlObject.h" -#include -#include -#include +#if defined(HAVE_QT) +# include +# include +# include +#endif namespace gsi { @@ -162,8 +164,10 @@ public: t_double, t_string, t_stdstring, - t_qstring, +#if defined(HAVE_QT) + t_qstring, t_qbytearray, +#endif t_list, t_array, t_user, @@ -186,6 +190,7 @@ public: */ Variant (const tl::Variant &d); +#if defined(HAVE_QT) /** * @brief Initialize the Variant with a QByteArray */ @@ -196,6 +201,14 @@ public: */ Variant (const QString &s); + /** + * @brief Create from a QVariant + * + * This constructor will convert a QVariant into a tl::Variant as far as possible. + */ + explicit Variant (const QVariant &v); +#endif + /** * @brief Initialize the Variant with "string" */ @@ -291,13 +304,6 @@ public: */ Variant (size_t l, bool /*dummy*/); - /** - * @brief Create from a QVariant - * - * This constructor will convert a QVariant into a tl::Variant as far as possible. - */ - explicit Variant (const QVariant &v); - /** * @brief Initialize with a user type based on void * * @@ -398,10 +404,12 @@ public: return tl::Variant ((void *) new T(t), c, true); } +#if defined(HAVE_QT) /** * @brief Convert to a QVariant */ QVariant to_qvariant () const; +#endif /** * @brief Assignment @@ -413,6 +421,7 @@ public: */ Variant &operator= (const char *v); +#if defined(HAVE_QT) /** * @brief Assignment of a QByteArray */ @@ -422,6 +431,7 @@ public: * @brief Assignment of a QString */ Variant &operator= (const QString &v); +#endif /** * @brief Assignment of a string @@ -588,6 +598,7 @@ public: */ const char *to_string () const; +#if defined(HAVE_QT) /** * @brief Conversion to a QByteArray * @@ -603,6 +614,7 @@ public: * No conversion is provided to user types currently. */ QString to_qstring () const; +#endif /** * @brief Conversion to a std::string @@ -1305,6 +1317,8 @@ public: return m_type == t_id; } +#if defined(HAVE_QT) + /** * @brief Test, if it is a QByteArray */ @@ -1321,6 +1335,8 @@ public: return m_type == t_qstring; } +#endif + /** * @brief Test, if it is a std::string */ @@ -1342,7 +1358,11 @@ public: */ bool is_a_string () const { +#if defined(HAVE_QT) return m_type == t_string || m_type == t_stdstring || m_type == t_qstring || m_type == t_qbytearray; +#else + return m_type == t_string || m_type == t_stdstring; +#endif } /** @@ -1492,8 +1512,10 @@ private: char ptr [sizeof (WeakOrSharedPtr)]; const VariantUserClassBase *cls; } mp_user_ref; +#if defined(HAVE_QT) QString *m_qstring; QByteArray *m_qbytearray; +#endif std::string *m_stdstring; } m_var; @@ -1522,8 +1544,10 @@ template<> inline __int128 Variant::to<__int128> () const template<> inline double Variant::to () const { return to_double (); } template<> inline float Variant::to () const { return to_float (); } template<> inline std::string Variant::to () const { return to_stdstring (); } +#if defined(HAVE_QT) template<> inline QString Variant::to () const { return to_qstring (); } template<> inline QByteArray Variant::to () const { return to_qbytearray (); } +#endif template<> inline const char *Variant::to () const { return to_string (); } // specializations if the is.. methods @@ -1545,8 +1569,10 @@ template<> inline bool Variant::is<__int128> () const { return m_typ template<> inline bool Variant::is () const { return m_type == t_double; } template<> inline bool Variant::is () const { return m_type == t_float; } template<> inline bool Variant::is () const { return m_type == t_stdstring; } +#if defined(HAVE_QT) template<> inline bool Variant::is () const { return m_type == t_qstring; } template<> inline bool Variant::is () const { return m_type == t_qbytearray; } +#endif template<> inline bool Variant::is () const { return m_type == t_string; } // specializations of the can_convert.. methods @@ -1568,8 +1594,10 @@ template<> inline bool Variant::can_convert_to<__int128> () const { template<> inline bool Variant::can_convert_to () const { return can_convert_to_double (); } template<> inline bool Variant::can_convert_to () const { return can_convert_to_float (); } template<> inline bool Variant::can_convert_to () const { return true; } +#if defined(HAVE_QT) template<> inline bool Variant::can_convert_to () const { return true; } template<> inline bool Variant::can_convert_to () const { return true; } +#endif template<> inline bool Variant::can_convert_to () const { return true; } /** diff --git a/src/tl/tl/tlXMLParser.h b/src/tl/tl/tlXMLParser.h index 7f22e01ea..2db932a1d 100644 --- a/src/tl/tl/tlXMLParser.h +++ b/src/tl/tl/tlXMLParser.h @@ -26,6 +26,10 @@ #include "tlCommon.h" +#if !defined(HAVE_XML) +# error tl::XMLParser not available without QtXml +#endif + #include #include #include diff --git a/src/tl/unit_tests/tlAlgorithm.cc b/src/tl/unit_tests/tlAlgorithm.cc index 00b00c53e..12e8e07c2 100644 --- a/src/tl/unit_tests/tlAlgorithm.cc +++ b/src/tl/unit_tests/tlAlgorithm.cc @@ -26,6 +26,7 @@ #include "tlTimer.h" #include "tlUnitTest.h" +#include #include #include #include diff --git a/src/tl/unit_tests/tlDeferredExecution.cc b/src/tl/unit_tests/tlDeferredExecution.cc index e877e1307..71fcfed14 100644 --- a/src/tl/unit_tests/tlDeferredExecution.cc +++ b/src/tl/unit_tests/tlDeferredExecution.cc @@ -20,8 +20,6 @@ */ - - #include "tlDeferredExecution.h" #include "tlUnitTest.h" diff --git a/src/tl/unit_tests/tlHttpStream.cc b/src/tl/unit_tests/tlHttpStream.cc index a5b94df9d..029ffa5a3 100644 --- a/src/tl/unit_tests/tlHttpStream.cc +++ b/src/tl/unit_tests/tlHttpStream.cc @@ -25,7 +25,9 @@ #include "tlUnitTest.h" #include "tlTimer.h" -#include +#if defined(HAVE_QT) +# include +#endif static std::string test_url1 ("http://www.klayout.org/svn-public/klayout-resources/trunk/testdata/text"); static std::string test_url2 ("http://www.klayout.org/svn-public/klayout-resources/trunk/testdata/dir1"); @@ -90,6 +92,8 @@ public: } +#if defined(HAVE_QT) + // async mode TEST(3) { @@ -113,3 +117,5 @@ TEST(3) std::string res (b, n); EXPECT_EQ (res, "hello, world.\n"); } + +#endif diff --git a/src/tl/unit_tests/tlThreadedWorkers.cc b/src/tl/unit_tests/tlThreadedWorkers.cc index 8925125d5..c5e2c5671 100644 --- a/src/tl/unit_tests/tlThreadedWorkers.cc +++ b/src/tl/unit_tests/tlThreadedWorkers.cc @@ -25,6 +25,7 @@ #include "tlThreadedWorkers.h" #include "tlTimer.h" #include "tlUnitTest.h" +#include "tlThreads.h" #include @@ -57,7 +58,7 @@ public: bool flag() const { return m_flag; } private: - QMutex lock; + tl::Mutex lock; int m_sum; volatile bool m_flag; }; diff --git a/src/tl/unit_tests/tlVariant.cc b/src/tl/unit_tests/tlVariant.cc index 5a8b688d7..7112523ca 100644 --- a/src/tl/unit_tests/tlVariant.cc +++ b/src/tl/unit_tests/tlVariant.cc @@ -97,7 +97,9 @@ TEST(1) { tl::Variant v; +#if defined(HAVE_QT) EXPECT_EQ (tl::to_string (v.to_qvariant ().toString ()), ""); +#endif EXPECT_EQ (v.is_nil (), true); EXPECT_EQ (v.is_list (), false); EXPECT_EQ (v.is_cstring (), false); @@ -131,7 +133,9 @@ TEST(1) { tl::Variant v (1ul); +#if defined(HAVE_QT) EXPECT_EQ (tl::Variant (v.to_qvariant ()).to_parsable_string (), "#u1"); +#endif EXPECT_EQ (v.is_nil (), false); EXPECT_EQ (v.is_list (), false); EXPECT_EQ (v.is_cstring (), false); @@ -161,7 +165,9 @@ TEST(1) { tl::Variant v (2u); +#if defined(HAVE_QT) EXPECT_EQ (tl::Variant (v.to_qvariant ()).to_parsable_string (), "#u2"); +#endif EXPECT_EQ (v.is_nil (), false); EXPECT_EQ (v.is_list (), false); EXPECT_EQ (v.is_cstring (), false); @@ -197,7 +203,9 @@ TEST(1) { tl::Variant v (1); +#if defined(HAVE_QT) EXPECT_EQ (tl::Variant (v.to_qvariant ()).to_parsable_string (), "#1"); +#endif EXPECT_EQ (v.is_nil (), false); EXPECT_EQ (v.is_list (), false); EXPECT_EQ (v.is_cstring (), false); @@ -230,7 +238,9 @@ TEST(1) { tl::Variant v (2l); +#if defined(HAVE_QT) EXPECT_EQ (tl::Variant (v.to_qvariant ()).to_parsable_string (), "#2"); +#endif EXPECT_EQ (v.is_nil (), false); EXPECT_EQ (v.is_list (), false); EXPECT_EQ (v.is_cstring (), false); @@ -268,7 +278,9 @@ TEST(1) { tl::Variant v ((float)5.0); +#if defined(HAVE_QT) EXPECT_EQ (tl::Variant (v.to_qvariant ()).to_parsable_string (), "##5"); +#endif EXPECT_EQ (v.is_nil (), false); EXPECT_EQ (v.is_list (), false); EXPECT_EQ (v.is_cstring (), false); @@ -313,7 +325,9 @@ TEST(1) { tl::Variant v (5.0); +#if defined(HAVE_QT) EXPECT_EQ (tl::Variant (v.to_qvariant ()).to_parsable_string (), "##5"); +#endif EXPECT_EQ (v.is_nil (), false); EXPECT_EQ (v.is_list (), false); EXPECT_EQ (v.is_cstring (), false); @@ -373,7 +387,9 @@ TEST(1) { tl::Variant v((short)2); +#if defined(HAVE_QT) EXPECT_EQ (tl::Variant (v.to_qvariant ()).to_parsable_string (), "#2"); +#endif EXPECT_EQ (v.is_nil (), false); EXPECT_EQ (v.is_list (), false); EXPECT_EQ (v.is_cstring (), false); @@ -419,7 +435,9 @@ TEST(1) { tl::Variant v((unsigned short)2); +#if defined(HAVE_QT) EXPECT_EQ (tl::Variant (v.to_qvariant ()).to_parsable_string (), "#u2"); +#endif EXPECT_EQ (v.is_nil (), false); EXPECT_EQ (v.is_list (), false); EXPECT_EQ (v.is_cstring (), false); @@ -460,7 +478,9 @@ TEST(1) { tl::Variant v ("hal'l\"o"); +#if defined(HAVE_QT) EXPECT_EQ (tl::Variant (v.to_qvariant ()).to_parsable_string (), "'hal\\'l\"o'"); +#endif EXPECT_EQ (v.is_nil (), false); EXPECT_EQ (v.is_list (), false); EXPECT_EQ (v.is_cstring (), true); @@ -489,12 +509,13 @@ TEST(1) } { +#if defined(HAVE_QT) tl::Variant v (tl::to_qstring ("hal'l\"o")); EXPECT_EQ (tl::Variant (v.to_qvariant ()).to_parsable_string (), "'hal\\'l\"o'"); + EXPECT_EQ (v.is_qstring (), true); EXPECT_EQ (v.is_nil (), false); EXPECT_EQ (v.is_list (), false); EXPECT_EQ (v.is_cstring (), false); - EXPECT_EQ (v.is_qstring (), true); EXPECT_EQ (v.is_stdstring (), false); EXPECT_EQ (v.is_long (), false); EXPECT_EQ (v.is_ulong (), false); @@ -516,12 +537,15 @@ TEST(1) EXPECT_EQ (v.is_stdstring (), false); EXPECT_EQ (std::string (v.to_string ()), "hal'l\"o"); EXPECT_EQ (std::string ((const char *)v.native_ptr ()), "hal'l\"o"); +#endif } { long a[3] = { 1, 5, 25 }; tl::Variant v (a, a + 3); +#if defined(HAVE_QT) EXPECT_EQ (tl::Variant (v.to_qvariant ()).to_parsable_string (), "(#1,#5,#25)"); +#endif EXPECT_EQ (v.is_nil (), false); EXPECT_EQ (v.is_list (), true); EXPECT_EQ (v.is_cstring (), false); @@ -556,7 +580,9 @@ TEST(1) { tl::Variant v ((long long) 17); +#if defined(HAVE_QT) EXPECT_EQ (tl::Variant (v.to_qvariant ()).to_parsable_string (), "#l17"); +#endif EXPECT_EQ (v.is_nil (), false); EXPECT_EQ (v.is_list (), false); EXPECT_EQ (v.is_cstring (), false); @@ -578,7 +604,9 @@ TEST(1) { tl::Variant v ((unsigned long long) 17); +#if defined(HAVE_QT) EXPECT_EQ (tl::Variant (v.to_qvariant ()).to_parsable_string (), "#lu17"); +#endif EXPECT_EQ (v.is_nil (), false); EXPECT_EQ (v.is_list (), false); EXPECT_EQ (v.is_cstring (), false); @@ -600,7 +628,9 @@ TEST(1) { tl::Variant v (17, true); +#if defined(HAVE_QT) EXPECT_EQ (tl::Variant (v.to_qvariant ()).to_parsable_string (), "#u17"); +#endif EXPECT_EQ (v.is_nil (), false); EXPECT_EQ (v.is_list (), false); EXPECT_EQ (v.is_cstring (), false); @@ -616,7 +646,9 @@ TEST(1) { tl::Variant v = tl::Variant::empty_array (); +#if defined(HAVE_QT) EXPECT_EQ (tl::Variant (v.to_qvariant ()).to_parsable_string (), "{}"); +#endif EXPECT_EQ (v.is_nil (), false); EXPECT_EQ (v.is_list (), false); EXPECT_EQ (v.is_array (), true); @@ -633,7 +665,9 @@ TEST(1) EXPECT_EQ (v.to_parsable_string (), "{#1=>\'A\'}"); v.insert (tl::Variant ("B"), tl::Variant (17)); EXPECT_EQ (v.to_parsable_string (), "{#1=>\'A\',\'B\'=>#17}"); +#if defined(HAVE_QT) EXPECT_EQ (tl::Variant (v.to_qvariant ()).to_parsable_string (), "{\'1\'=>\'A\',\'B\'=>#17}"); +#endif tl::Variant *x; x = v.find (tl::Variant ("B")); EXPECT_EQ (x != 0, true); diff --git a/src/tl/unit_tests/unit_tests.pro b/src/tl/unit_tests/unit_tests.pro index 1984e3fa0..f524db31e 100644 --- a/src/tl/unit_tests/unit_tests.pro +++ b/src/tl/unit_tests/unit_tests.pro @@ -11,14 +11,11 @@ SOURCES = \ tlClassRegistry.cc \ tlCommandLineParser.cc \ tlDataMapping.cc \ - tlDeferredExecution.cc \ tlDeflate.cc \ tlEvents.cc \ tlExpression.cc \ - tlFileSystemWatcher.cc \ tlFileUtils.cc \ tlGlobPattern.cc \ - tlHttpStream.cc \ tlIntervalMap.cc \ tlIntervalSet.cc \ tlKDTree.cc \ @@ -30,9 +27,31 @@ SOURCES = \ tlThreadedWorkers.cc \ tlUtils.cc \ tlVariant.cc \ - tlWebDAV.cc \ - tlXMLParser.cc \ - tlInt128Support.cc + tlInt128Support.cc + +equals(HAVE_QT, "0") { + # nothing +} else { + SOURCES += \ + tlWebDAV.cc \ + tlDeferredExecution.cc \ + tlXMLParser.cc \ + tlFileSystemWatcher.cc \ +} + +equals(HAVE_CURL, "1") { + SOURCES += \ + tlHttpStream.cc \ +} else { + equals(HAVE_QT, "0") { + # no HTTP stream available + } else { + SOURCES += \ + tlHttpStream.cc \ + } +} + + INCLUDEPATH += $$TL_INC DEPENDPATH += $$TL_INC