Menu

Tk::Point to std::string conversion

2006-04-27
2013-04-15
  • Mateusz Loskot

    Mateusz Loskot - 2006-04-27

    Hi Maciej,

    Could comment my proposal in Feature Requests submited as "[1471099] Tk::Point to std::string conversion" ?

    Mateusz

     
    • Maciej Sobczak

      Maciej Sobczak - 2006-05-12

      Basically, the interface of C++/Tk with regard to Point is self-contained in the sense that no conversions should be necessary - some functions return Points, other accept them (if there is any inconsistency, let me know). This means that the only needs for such conversions can only arise in user code. The problem is that such conversions can be performed in many ways (for example - should it be "(x, y)" or "[x, y]", etc.) and C++/Tk is in no position to define what is the "right" way. Note that Tk::Point is a simple struct with members x and y, so that defining any additional logic should be rather straightforward.

       
    • Mateusz Loskot

      Mateusz Loskot - 2006-05-14

      I understand those arguments. They seem to be clear.
      Nevertheless it's clear, I think it could be nice to   be able to e.g. draw line in following way:

      std::vector<Tk::Point> pts;
      // fill points
      ".c" << Tk::create(Tk::line, pts.begin(), pts.end());

      So, is this still possible without having stream operator?

       
      • Maciej Sobczak

        Maciej Sobczak - 2006-05-16

        Indeed, interesting example. :)
        No, this is not supported at the moment.
        The possible solution (for today) is to write custom iterator that will "translate" the sequence of points into the sequence of their coordinates. The resulting sequence will have twice as much elements and the usage might be something like:

        ".c" << create(line, Point2PairIterator(pts.begin()), Point2PairIterator());

        Internally, the iterator with each dereference will get x and y components of subsequent Points.
        Just an idea.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.