]> git.sesse.net Git - casparcg/blobdiff - protocol/util/strategy_adapters.h
* Merged RESUME command.
[casparcg] / protocol / util / strategy_adapters.h
index 02cb721c24b32c322ac0bcb5ed204be71c1fb95f..22aad3d6f3405f006bffa750683e34d8a322761b 100644 (file)
@@ -61,30 +61,29 @@ 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
        }\r
 \r
-       virtual void parse(const std::basic_string<char>& data)\r
+       virtual void parse(const std::basic_string<CharT>& data)\r
        {\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_first_of(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
@@ -94,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