]> git.sesse.net Git - casparcg/blobdiff - protocol/util/strategy_adapters.h
[decklink] #484 Possible race condition with move-assignment of packaged_task avoided...
[casparcg] / protocol / util / strategy_adapters.h
index 8e6afd9365af02f1a7fcfc83353e11f166f3f23d..56d35fedfc7e442413b4dcfa8790e8e16720d62c 100644 (file)
@@ -22,7 +22,6 @@
 #pragma once\r
 \r
 #include <boost/algorithm/string/split.hpp>\r
-#include <boost/foreach.hpp>\r
 \r
 #include "protocol_strategy.h"\r
 #include "ProtocolStrategy.h"\r
@@ -62,11 +61,11 @@ class delimiter_based_chunking_strategy : public protocol_strategy<CharT>
 {\r
        std::basic_string<CharT> delimiter_;\r
        std::basic_string<CharT> input_;\r
-       protocol_strategy<CharT>::ptr strategy_;\r
+       typename protocol_strategy<CharT>::ptr strategy_;\r
 public:\r
        delimiter_based_chunking_strategy(\r
                        const std::basic_string<CharT>& delimiter, \r
-                       const protocol_strategy<CharT>::ptr& strategy)\r
+                       const typename protocol_strategy<CharT>::ptr& strategy)\r
                : delimiter_(delimiter)\r
                , strategy_(strategy)\r
        {\r
@@ -76,16 +75,15 @@ public:
        {\r
                input_ += data;\r
 \r
-               std::vector<std::basic_string<CharT>> split;\r
-               boost::iter_split(split, input_, boost::algorithm::first_finder(delimiter_));   //TODO: check if this splits on all instances of delimiter_ in the input_\r
+               //boost::iter_split(split, input_, boost::algorithm::first_finder(delimiter_)) was painfully slow in debug-build\r
 \r
-               input_ = std::move(split.back());\r
-               split.pop_back();\r
-\r
-               BOOST_FOREACH(auto cmd, split)\r
+               auto delim_pos = input_.find(delimiter_);\r
+               while(delim_pos != std::string::npos)\r
                {\r
-                       // TODO: perhaps it would be better to not append the delimiter.\r
-                       strategy_->parse(cmd);\r
+                       strategy_->parse(input_.substr(0, delim_pos));\r
+\r
+                       input_ = std::move(input_.substr(delim_pos+delimiter_.size()));\r
+                       delim_pos = input_.find_first_of(delimiter_);\r
                }\r
        }\r
 };\r
@@ -95,11 +93,11 @@ class delimiter_based_chunking_strategy_factory
        : public protocol_strategy_factory<CharT>\r
 {\r
        std::basic_string<CharT> delimiter_;\r
-       protocol_strategy_factory<CharT>::ptr strategy_factory_;\r
+       typename protocol_strategy_factory<CharT>::ptr strategy_factory_;\r
 public:\r
        delimiter_based_chunking_strategy_factory(\r
                        const std::basic_string<CharT>& delimiter, \r
-                       const protocol_strategy_factory<CharT>::ptr& strategy_factory)\r
+                       const typename protocol_strategy_factory<CharT>::ptr& strategy_factory)\r
                : delimiter_(delimiter)\r
                , strategy_factory_(strategy_factory)\r
        {\r