As a convenience we also accept strings in place of paths when calling from python. We deliberately don't do the same in c++ to force people to use the faster form.
| 213 | // calling from python. We deliberately don't do the same in c++ to force |
| 214 | // people to use the faster form. |
| 215 | struct PathFromString |
| 216 | { |
| 217 | |
| 218 | PathFromString() |
| 219 | { |
| 220 | boost::python::converter::registry::push_back( |
| 221 | &convertible, |
| 222 | &construct, |
| 223 | boost::python::type_id<std::vector<InternedString>>() |
| 224 | ); |
| 225 | } |
| 226 | |
| 227 | static void *convertible( PyObject *obj ) |
| 228 | { |
| 229 | extract<std::string> e( obj ); |
| 230 | if( e.check() ) |
| 231 | { |
| 232 | return obj; |
| 233 | } |
| 234 | return nullptr; |
| 235 | } |
| 236 | |
| 237 | static void construct( PyObject *obj, boost::python::converter::rvalue_from_python_stage1_data *data ) |
| 238 | { |
| 239 | void *storage = (( converter::rvalue_from_python_storage<std::vector<InternedString>>* ) data )->storage.bytes; |
| 240 | std::vector<InternedString> *path = new( storage ) std::vector<InternedString>(); |
| 241 | data->convertible = storage; |
| 242 | |
| 243 | std::string s = extract<std::string>( obj ); |
| 244 | typedef boost::tokenizer<boost::char_separator<char> > Tokenizer; |
| 245 | Tokenizer t( s, boost::char_separator<char>( "/" ) ); |
| 246 | for( Tokenizer::const_iterator it = t.begin(), eIt = t.end(); it != eIt; it++ ) |
| 247 | { |
| 248 | path->push_back( *it ); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | }; |
| 253 | |
| 254 | // we don't actually wrap the existing init, but rather reimplement it |
| 255 | // here using clear() and addPath(), so that we can support a mixture |