format.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* DEPRECATED! - use code/TinyFormatter.h instead.
  2. *
  3. *
  4. * */
  5. #ifndef AI_BOOST_FORMAT_DUMMY_INCLUDED
  6. #define AI_BOOST_FORMAT_DUMMY_INCLUDED
  7. #if (!defined BOOST_FORMAT_HPP) || (defined ASSIMP_FORCE_NOBOOST)
  8. #include <string>
  9. #include <vector>
  10. #include <sstream>
  11. namespace boost
  12. {
  13. class format
  14. {
  15. public:
  16. format (const std::string& _d)
  17. : d(_d)
  18. {
  19. }
  20. template <typename T>
  21. format& operator % (T in)
  22. {
  23. // XXX add replacement for boost::lexical_cast?
  24. std::ostringstream ss;
  25. ss << in; // note: ss cannot be an rvalue, or the global operator << (const char*) is not called for T == const char*.
  26. chunks.push_back( ss.str());
  27. return *this;
  28. }
  29. operator std::string () const {
  30. std::string res; // pray for NRVO to kick in
  31. size_t start = 0, last = 0;
  32. std::vector<std::string>::const_iterator chunkin = chunks.begin();
  33. for ( start = d.find('%');start != std::string::npos; start = d.find('%',last)) {
  34. res += d.substr(last,start-last);
  35. last = start+2;
  36. if (d[start+1] == '%') {
  37. res += "%";
  38. continue;
  39. }
  40. if (chunkin == chunks.end()) {
  41. break;
  42. }
  43. res += *chunkin++;
  44. }
  45. res += d.substr(last);
  46. return res;
  47. }
  48. private:
  49. std::string d;
  50. std::vector<std::string> chunks;
  51. };
  52. inline std::string str(const std::string& s) {
  53. return s;
  54. }
  55. }
  56. #else
  57. # error "format.h was already included"
  58. #endif //
  59. #endif // !! AI_BOOST_FORMAT_DUMMY_INCLUDED