various updates to path and error substitution

This commit is contained in:
Daniel Larimer 2013-01-25 13:19:23 -05:00
parent cc44e8bbe0
commit 9858e553bf
6 changed files with 26 additions and 52 deletions

View file

@ -28,6 +28,7 @@ namespace fc {
friend path operator /( const fc::path& p, const fc::path& );
friend bool operator ==( const fc::path& p, const fc::path& );
friend bool operator !=( const fc::path& p, const fc::path& );
friend bool operator < ( const fc::path& p, const fc::path& );
operator boost::filesystem::path& ();
operator const boost::filesystem::path& ()const;
@ -69,6 +70,9 @@ namespace fc {
fc::path operator*()const;
recursive_directory_iterator& operator++(int);
recursive_directory_iterator& operator++();
void pop();
int level();
friend bool operator==( const recursive_directory_iterator&, const recursive_directory_iterator& );
friend bool operator!=( const recursive_directory_iterator&, const recursive_directory_iterator& );

View file

@ -24,12 +24,18 @@ namespace std {
namespace fc {
// typedef std::string string;
/**
* @brief wrapper on std::string
*
* Including <string> results in 4000 lines of code
* that must be included to build your header. This
* class hides all of those details while maintaining
* compatability with std::string. Using fc::string
* instead of std::string can accelerate compile times
* 10x.
*
* The implementation of this class is std::string, this header simply
* accelerates compile times. fc::string is automatically convertable to / from
* std::string.
*/
class string {
public:

View file

@ -347,6 +347,15 @@ namespace fc {
};
}
/**
* @brief provides a light-weight vector similar to std::vector except that
* it prevents needing to include <vector> which requires many more headers
* and increases compile times.
*
* This class should have the same API as std::vector and can be expanded as
* additional features of std::vector are required.
*
*/
template<typename T>
class vector : public detail::vector_impl<T, typename fc::is_class<T>::type> {
public:

View file

@ -84,56 +84,6 @@ fc::string error_frame::to_detail_string()const {
fc::string error_frame::to_string()const {
return substitute( desc, meta ? *meta : fc::value() );
}
#if 0
fc::stringstream ss;
size_t prev = 0;
auto next = desc.find( '$' );
while( prev != size_t(fc::string::npos) && prev < size_t(desc.size()) ) {
// slog( "prev: %d next %d %s", prev, next, desc.substr(prev,next).c_str() );
// print everything from the last pos until the first '$'
ss << desc.substr( prev, size_t(next-prev) );
// if we got to the end, return it.
if( next == string::npos ) { return ss.str(); }
// if we are not at the end, then update the start
prev = next + 1;
if( desc[prev] == '{' ) {
// if the next char is a open, then find close
next = desc.find( '}', prev );
// if we found close...
if( next != fc::string::npos ) {
// the key is between prev and next
fc::string key = desc.substr( prev+1, (next-prev-1) );
//slog( "key '%s'", key.c_str() );
if( meta ) {
auto itr = meta->find( key.c_str() );
if( itr != meta->end() ) {
if( itr->val.is_string() ) {
ss<<itr->val.cast<fc::string>();
} else {
ss << fc::json::to_string( itr->val );
}
} else {
ss << "???";
}
}
prev = next + 1;
// find the next $
next = desc.find( '$', prev );
} else {
// we didn't find it.. continue to while...
}
} else {
ss << desc[prev];
++prev;
next = desc.find( '$', prev );
}
}
return ss.str();
}
#endif
fc::string substitute( const fc::string& format, const fc::value& keys ) {
fc::stringstream ss;
@ -164,10 +114,10 @@ fc::string substitute( const fc::string& format, const fc::value& keys ) {
if( itr->val.is_string() ) {
ss<<itr->val.cast<fc::string>();
} else {
ss << fc::json::to_string( itr->val );
ss << fc::json::to_string( itr->val );
}
} else {
ss << "???";
ss << "${"<<key<<"}";
}
// }
prev = next + 1;

View file

@ -40,6 +40,7 @@ namespace fc {
return *this;
}
bool operator <( const fc::path& l, const fc::path& r ) { return *l._p < *r._p; }
bool operator ==( const fc::path& l, const fc::path& r ) { return *l._p == *r._p; }
bool operator !=( const fc::path& l, const fc::path& r ) { return *l._p != *r._p; }
@ -112,6 +113,9 @@ namespace fc {
recursive_directory_iterator& recursive_directory_iterator::operator++(int) { (*_p)++; return *this; }
recursive_directory_iterator& recursive_directory_iterator::operator++() { (*_p)++; return *this; }
void recursive_directory_iterator::pop() { (*_p).pop(); }
int recursive_directory_iterator::level() { return _p->level(); }
bool operator==( const recursive_directory_iterator& r, const recursive_directory_iterator& l) {
return *r._p == *l._p;
}

View file

@ -1,3 +1,4 @@
#include <fc/value_cast.hpp>
#include <boost/chrono/system_clocks.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <fc/time.hpp>