remove macro STR

This commit is contained in:
Jinhao
2015-11-29 22:38:22 +08:00
parent 12358a5dc0
commit c86a00bea5
31 changed files with 410 additions and 331 deletions

View File

@@ -89,14 +89,12 @@ namespace nana
typedef char char_t;
typedef std::string string; ///< An alias of std::wstring or std::string, depending on the macro NANA_UNICODE
}
#define STR(string) string
#else
namespace nana
{
typedef wchar_t char_t;
typedef std::wstring string; ///< An alias of std::wstring or std::string, depending on the macro NANA_UNICODE
}
#define STR(string) L##string
#endif
namespace nana

View File

@@ -39,9 +39,9 @@ namespace filesystem
#ifdef NANA_WINDOWS
fileinfo(const WIN32_FIND_DATA& wfd);
#elif NANA_LINUX or NANA_MACOS
fileinfo(const nana::string& filename, const struct stat &);
fileinfo(const ::std::string& filename, const struct stat &);
#endif
nana::string name;
::std::string name;
unsigned long size;
bool directory;
@@ -56,7 +56,7 @@ namespace filesystem
basic_file_iterator():end_(true), handle_(nullptr){}
basic_file_iterator(const nana::string& file_path)
basic_file_iterator(const std::string& file_path)
:end_(false), handle_(nullptr)
{
_m_prepare(file_path);
@@ -92,14 +92,13 @@ namespace filesystem
return (*p == 0);
}
void _m_prepare(const nana::string& file_path)
void _m_prepare(const std::string& file_path)
{
#if defined(NANA_WINDOWS)
path_ = file_path;
auto pat = file_path;
auto pat = utf8_cast(file_path);
DWORD attr = ::GetFileAttributes(pat.data());
if((attr != INVALID_FILE_ATTRIBUTES) && (attr & FILE_ATTRIBUTE_DIRECTORY))
pat += STR("\\*");
pat += L"\\*";
::HANDLE handle = ::FindFirstFile(pat.data(), &wfd_);
@@ -120,10 +119,11 @@ namespace filesystem
}
value_ = value_type(wfd_);
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
path_ = nana::charset(file_path);
if(path_.size() && (path_[path_.size() - 1] != '/'))
path_ += '/';
find_handle_t handle = opendir(path_.c_str());
auto path = file_path;
if(path.size() && path.back() != '/')
path += '/';
auto handle = opendir(path.c_str());
end_ = true;
if(handle)
{
@@ -141,7 +141,7 @@ namespace filesystem
}
struct stat fst;
if(stat((path_ + dnt->d_name).c_str(), &fst) == 0)
if(stat((path + dnt->d_name).c_str(), &fst) == 0)
{
value_ = value_type(nana::charset(dnt->d_name), fst);
}
@@ -226,9 +226,6 @@ namespace filesystem
#if defined(NANA_WINDOWS)
WIN32_FIND_DATA wfd_;
nana::string path_;
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
std::string path_;
#endif
std::shared_ptr<find_handle_t> find_ptr_;

View File

@@ -136,29 +136,41 @@ namespace filesystem
class path
{
public:
#if defined(NANA_WINDOWS)
using value_type = wchar_t;
const static value_type preferred_separator = '\\';
#else
using value_type = char;
const static value_type preferred_separator = '/';
#endif
using string_type = std::basic_string<value_type>;
path();
path(const nana::string&);
path(const value_type* source);
path(const string_type& source);
int compare(const path& other) const;
bool empty() const;
path root() const;
path parent_path() const;
file_type what() const;
nana::string filename() const;
#if defined(NANA_WINDOWS)
public:
nana::string to_string() const { return text_; }
operator nana::string() const { return text_; }
path filename() const;
const value_type*c_str() const;
const string_type& native() const;
operator string_type() const;
private:
nana::string text_;
#else
public:
std::string to_string() const { return text_; }
operator std::string() const { return text_; }
private:
std::string text_;
#endif
string_type pathstr_;
};
bool operator==(const path& lhs, const path& rhs);
bool operator!=(const path& lhs, const path& rhs);
bool operator<(const path& lhs, const path& rhs);
bool operator>(const path& lhs, const path& rhs);
struct directory_entry
{
using path_type = filesystem::path;
@@ -193,9 +205,7 @@ namespace filesystem
typedef std::input_iterator_tag iterator_category;
directory_iterator():end_(true), handle_(nullptr){}
directory_iterator(const nana::string& file_path) { _m_prepare(file_path); }
directory_iterator(const path& file_path) { _m_prepare(file_path.filename()); }
directory_iterator(const path& file_path) { _m_prepare(file_path); }
const value_type&
operator*() const { return value_; }
@@ -233,14 +243,14 @@ namespace filesystem
return (*p == 0);
}
void _m_prepare(const nana::string& file_path)
void _m_prepare(const path& file_path)
{
auto path_ = file_path.native();
#if defined(NANA_WINDOWS)
path_ = file_path;
auto pat = file_path;
auto pat = path_;
DWORD attr = ::GetFileAttributes(pat.data());
if((attr != INVALID_FILE_ATTRIBUTES) && (attr & FILE_ATTRIBUTE_DIRECTORY))
pat += STR("\\*");
pat += L"\\*";
::HANDLE handle = ::FindFirstFile(pat.data(), &wfd_);
@@ -265,7 +275,6 @@ namespace filesystem
wfd_.nFileSizeLow);
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
path_ = nana::charset(file_path);
if(path_.size() && (path_[path_.size() - 1] != '/'))
path_ += '/';
find_handle_t handle = opendir(path_.c_str());
@@ -373,10 +382,9 @@ namespace filesystem
#if defined(NANA_WINDOWS)
WIN32_FIND_DATA wfd_;
nana::string path_;
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
std::string path_;
#endif
path::string_type path_;
std::shared_ptr<find_handle_t> find_ptr_;
find_handle_t handle_{nullptr};
value_type value_;
@@ -453,12 +461,39 @@ namespace filesystem
//bool remove(const path& p);
//bool remove(const path& p, error_code& ec) noexcept;
bool rmfile(const nana::char_t* file);
bool rmfile(const char* file);
//uintmax_t remove_all(const path& p);
//uintmax_t remove_all(const path& p, error_code& ec) noexcept;
bool rmdir(const nana::char_t* dir, bool fails_if_not_empty);
nana::string root(const nana::string& path);
bool rmdir(const char* dir, bool fails_if_not_empty);
bool rmdir(const wchar_t* dir, bool fails_if_not_empty);
template<typename CharType>
std::basic_string<CharType> parent_path(const std::basic_string<CharType>& path)
{
auto index = path.size();
if (index)
{
auto str = path.c_str();
for (--index; index > 0; --index)
{
auto c = str[index];
if (c != '\\' && c != '/')
break;
}
for (--index; index > 0; --index)
{
auto c = str[index];
if (c == '\\' || c == '/')
break;
}
}
return index ? path.substr(0, index + 1) : std::basic_string<CharType>();
}
}//end namespace filesystem

View File

@@ -27,14 +27,14 @@ namespace filesystem
bool file_attrib(const ::std::string& file, attribute&);
long long filesize(const nana::string& file);
bool mkdir(const nana::string& dir, bool & if_exist);
bool mkdir(const ::std::string& dir, bool & if_exist);
bool modified_file_time(const nana::string& file, struct tm&);
nana::string path_user();
nana::string path_current();
bool rmfile(const nana::char_t* file);
bool rmdir(const nana::char_t* dir, bool fails_if_not_empty);
bool rmfile(const char* file_utf8);
bool rmdir(const char* dir, bool fails_if_not_empty);
nana::string root(const nana::string& path);
class path

View File

@@ -1,7 +1,7 @@
/*
* Forward Declarations
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at

View File

@@ -460,7 +460,7 @@ namespace nana
{
::nana::window window_handle; ///< A handle to the event window
::nana::point pos; ///< cursor position in the event window
std::vector<nana::string> files; ///< external filenames
std::vector<std::string> files; ///< external filenames
};
struct arg_expose : public event_arg
@@ -480,7 +480,7 @@ namespace nana
{
event_code evt_code; ///< it is event_code::key_press in current event
::nana::window window_handle; ///< A handle to the event window
mutable nana::char_t key; ///< the key corresponding to the key pressed
mutable wchar_t key; ///< the key corresponding to the key pressed
mutable bool ignore; ///< this member is not used
bool ctrl; ///< keyboard Ctrl is pressed?
bool shift; ///< keyboard Shift is pressed

View File

@@ -94,7 +94,7 @@ namespace nana
virtual ~renderer() = 0;
virtual void background(graph_reference, window wd, const nana::rectangle&, const ui_element&) = 0;
virtual void root_arrow(graph_reference, const nana::rectangle&, mouse_action) = 0;
virtual void item(graph_reference, const nana::rectangle&, std::size_t index, const nana::string& name, unsigned textheight, bool has_child, mouse_action) = 0;
virtual void item(graph_reference, const nana::rectangle&, std::size_t index, const ::std::string& name, unsigned textheight, bool has_child, mouse_action) = 0;
virtual void border(graph_reference) = 0;
};
@@ -115,8 +115,8 @@ namespace nana
//splitstr
//@brief: Sets the splitstr. If the parameter will be ingored if it is an empty string.
void splitstr(const nana::string&);
const nana::string& splitstr() const;
void splitstr(const ::std::string&);
const ::std::string& splitstr() const;
void path(const ::std::string&);
::std::string path() const;

View File

@@ -22,7 +22,7 @@ namespace detail
template<typename T>
struct tree_node
{
typedef std::pair<nana::string, T> value_type;
typedef std::pair<std::string, T> value_type;
value_type value;
@@ -108,7 +108,7 @@ namespace detail
return (verify(node) && (node->owner != &root_) ? node->owner : nullptr);
}
node_type * node(node_type* node, const nana::string& key)
node_type * node(node_type* node, const std::string& key)
{
if(node)
{
@@ -121,7 +121,7 @@ namespace detail
return nullptr;
}
node_type* insert(node_type* node, const nana::string& key, const element_type& elem)
node_type* insert(node_type* node, const std::string& key, const element_type& elem)
{
if(nullptr == node)
return insert(key, elem);
@@ -159,7 +159,7 @@ namespace detail
return nullptr;
}
node_type* insert(const nana::string& key, const element_type& elem)
node_type* insert(const std::string& key, const element_type& elem)
{
auto node = _m_locate<true>(key);
if(node)
@@ -173,12 +173,12 @@ namespace detail
delete node;
}
node_type* find(const nana::string& path) const
node_type* find(const std::string& path) const
{
return _m_locate(path);
}
node_type* ref(const nana::string& path)
node_type* ref(const std::string& path)
{
return _m_locate<true>(path);
}
@@ -303,7 +303,7 @@ namespace detail
}
template<typename PredAllowChild>
unsigned child_size_if(const nana::string& key, PredAllowChild pac) const
unsigned child_size_if(const ::std::string& key, PredAllowChild pac) const
{
auto node = _m_locate(key);
return (node ? child_size_if<PredAllowChild>(*node, pac) : 0);
@@ -392,7 +392,7 @@ namespace detail
:node(&(self.root_))
{}
bool operator()(const nana::string& key_node)
bool operator()(const ::std::string& key_node)
{
node_type *child = node->child;
node_type *tail = nullptr;
@@ -428,7 +428,7 @@ namespace detail
:node(&self.root_)
{}
bool operator()(const nana::string& key_node)
bool operator()(const ::std::string& key_node)
{
return ((node = _m_find(node->child, key_node)) != nullptr);
}
@@ -436,7 +436,7 @@ namespace detail
node_type *node;
};
private:
static node_type* _m_find(node_type* node, const nana::string& key_node)
static node_type* _m_find(node_type* node, const ::std::string& key_node)
{
while(node)
{
@@ -449,14 +449,14 @@ namespace detail
}
template<typename Function>
void _m_for_each(const nana::string& key, Function function) const
void _m_for_each(const ::std::string& key, Function function) const
{
if(key.size())
{
nana::string::size_type beg = 0;
auto end = key.find_first_of(STR("\\/"));
::std::string::size_type beg = 0;
auto end = key.find_first_of("\\/");
while(end != nana::string::npos)
while(end != ::std::string::npos)
{
if(beg != end)
{
@@ -464,11 +464,11 @@ namespace detail
return;
}
auto next = key.find_first_not_of(STR("\\/"), end);
if(next != nana::string::npos)
auto next = key.find_first_not_of("\\/", end);
if(next != ::std::string::npos)
{
beg = next;
end = key.find_first_of(STR("\\/"), beg);
end = key.find_first_of("\\/", beg);
}
else
return;
@@ -479,7 +479,7 @@ namespace detail
}
template<bool CreateIfNotExists>
node_type* _m_locate(const nana::string& key)
node_type* _m_locate(const ::std::string& key)
{
if(key.size())
{
@@ -499,7 +499,7 @@ namespace detail
return &root_;
}
node_type* _m_locate(const nana::string& key) const
node_type* _m_locate(const std::string& key) const
{
if(key.size())
{

View File

@@ -449,8 +449,8 @@ namespace nana
struct export_options
{
nana::string sep = nana::string {STR("\t" )},
endl= nana::string {STR("\n")};
nana::string sep = nana::string {L"\t"},
endl= nana::string {L"\n"};
bool only_selected_items{true},
only_checked_items {false},
only_visible_columns{true};

View File

@@ -281,45 +281,45 @@ namespace nana{ namespace widgets{ namespace skeletons
//Here is a identifier
_m_read_idstr();
if(STR("font") == idstr_)
if(L"font" == idstr_)
return token::font;
else if(STR("bold") == idstr_)
else if(L"bold" == idstr_)
return token::bold;
else if(STR("size") == idstr_)
else if(L"size" == idstr_)
return token::size;
else if(STR("baseline") == idstr_)
else if(L"baseline" == idstr_)
return token::baseline;
else if(STR("top") == idstr_)
else if(L"top" == idstr_)
return token::top;
else if(STR("center") == idstr_)
else if(L"center" == idstr_)
return token::center;
else if(STR("bottom") == idstr_)
else if(L"bottom" == idstr_)
return token::bottom;
else if(STR("color") == idstr_)
else if(L"color" == idstr_)
return token::color;
else if(STR("image") == idstr_)
else if(L"image" == idstr_)
return token::image;
else if(STR("true") == idstr_)
else if(L"true" == idstr_)
return token::_true;
else if(STR("url") == idstr_)
else if(L"url" == idstr_)
return token::url;
else if(STR("target") == idstr_)
else if(L"target" == idstr_)
return token::target;
else if(STR("false") == idstr_)
else if(L"false" == idstr_)
return token::_false;
else if(STR("red") == idstr_)
else if(L"red" == idstr_)
return token::red;
else if(STR("green") == idstr_)
else if(L"green" == idstr_)
return token::green;
else if(STR("blue") == idstr_)
else if(L"blue" == idstr_)
return token::blue;
else if(STR("white") == idstr_)
else if(L"white" == idstr_)
return token::white;
else if(STR("black") == idstr_)
else if(L"black" == idstr_)
return token::black;
else if(STR("min_limited") == idstr_)
else if(L"min_limited" == idstr_)
return token::min_limited;
else if(STR("max_limited") == idstr_)
else if(L"max_limited" == idstr_)
return token::max_limited;
return token::string;

View File

@@ -140,8 +140,6 @@ namespace nana
: public drawer_trigger
{
public:
//enum toolbox_button_t{ButtonAdd, ButtonScroll, ButtonList, ButtonClose}; //deprecated
enum class kits
{
add,

View File

@@ -55,7 +55,7 @@ namespace nana
nana::paint::image icon_normal;
nana::paint::image icon_hover;
nana::paint::image icon_expanded;
nana::string text;
::std::string text;
};
typedef widgets::detail::compset<component, node_attribute> compset_interface;
@@ -98,14 +98,14 @@ namespace nana
struct treebox_node_type
{
treebox_node_type();
treebox_node_type(nana::string);
treebox_node_type(std::string);
treebox_node_type& operator=(const treebox_node_type&);
nana::string text;
::std::string text;
nana::any value;
bool expanded;
checkstate checked;
nana::string img_idstr;
::std::string img_idstr;
};
struct pseudo_node_type{};
@@ -133,8 +133,8 @@ namespace nana
const ::nana::pat::cloneable<compset_placer_interface>& placer() const;
nana::any & value(node_type*) const;
node_type* insert(node_type*, const nana::string& key, nana::string&&);
node_type* insert(const nana::string& path, nana::string&&);
node_type* insert(node_type*, const std::string& key, std::string&&);
node_type* insert(const std::string& path, std::string&&);
bool verify(const void*) const;
bool verify_kinship(node_type* parent, node_type* child) const;
@@ -143,16 +143,15 @@ namespace nana
node_type * selected() const;
void selected(node_type*);
void set_expand(node_type*, bool);
void set_expand(const nana::string& path, bool);
void set_expand(const ::std::string& path, bool);
//void image(const nana::string& id, const node_image_tag&);
node_image_tag& icon(const nana::string&) const;
void icon_erase(const nana::string&);
void node_icon(node_type*, const nana::string& id);
node_image_tag& icon(const ::std::string&) const;
void icon_erase(const ::std::string&);
void node_icon(node_type*, const ::std::string& id);
unsigned node_width(const node_type*) const;
bool rename(node_type*, const nana::char_t* key, const nana::char_t* name);
bool rename(node_type*, const char* key, const char* name);
private:
//Overrides drawer_trigger methods
void attached(widget_reference, graph_reference) override;
@@ -182,11 +181,11 @@ namespace nana
item_proxy(trigger*, trigger::node_type*);
/// Append a child.
item_proxy append(const nana::string& key, nana::string name);
item_proxy append(const ::std::string& key, ::std::string name);
/// Append a child with a specified value (user object.).
template<typename T>
item_proxy append(const nana::string& key, nana::string name, const T&t)
item_proxy append(const ::std::string& key, ::std::string name, const T&t)
{
item_proxy ip = append(key, std::move(name));
if(false == ip.empty())
@@ -220,22 +219,22 @@ namespace nana
item_proxy& select(bool);
/// Return the icon.
const nana::string& icon() const;
const ::std::string& icon() const;
/// Set the icon, and returns itself..
item_proxy& icon(const nana::string& id);
item_proxy& icon(const ::std::string& id);
/// Return the text.
const nana::string& text() const;
/// Set a new key, and returns itself..
item_proxy& key(const nana::string& s);
/// Return the key.
const nana::string& key() const;
const ::std::string& text() const;
/// Set the text, and returns itself.
item_proxy& text(const nana::string&);
item_proxy& text(const ::std::string&);
/// Set a new key, and returns itself..
item_proxy& key(const ::std::string& s);
/// Return the key.
const ::std::string& key() const;
std::size_t size() const; ///< Returns the number of child nodes.
@@ -257,7 +256,7 @@ namespace nana
/// Makes an action for each sub item recursively, returns the item that stops the action where action returns false.
item_proxy visit_recursively(std::function<bool(item_proxy)> action);
bool operator==(const nana::string& s) const; ///< Compare the text of node with s.
bool operator==(const ::std::string& s) const; ///< Compare the text of node with s.
bool operator==(const char* s ) const; ///< Compare the text of node with s.
bool operator==(const wchar_t* s ) const; ///< Compare the text of node with s.
@@ -428,28 +427,28 @@ namespace nana
/// These states are 'normal', 'hovered' and 'expanded'.
/// If 'hovered' or 'expanded' are not set, it uses 'normal' state image for these 2 states.
/// See also in [documentation](http://nanapro.org/en-us/help/widgets/treebox.htm)
node_image_type& icon(const nana::string& id ///< the name of an icon scheme. If the name is not existing, it creates a new scheme for the name.
node_image_type& icon(const ::std::string& id ///< the name of an icon scheme. If the name is not existing, it creates a new scheme for the name.
) const;
void icon_erase(const nana::string& id);
void icon_erase(const ::std::string& id);
item_proxy find(const nana::string& keypath); ///< Find an item though a specified keypath.
item_proxy find(const ::std::string& keypath); ///< Find an item though a specified keypath.
/// Inserts a new node to treebox, but if the keypath exists returns the existing node.
item_proxy insert(const nana::string& path_key, ///< specifies the node hierarchy
nana::string title ///< used for displaying
item_proxy insert(const ::std::string& path_key, ///< specifies the node hierarchy
::std::string title ///< used for displaying
);
/// Inserts a new node to treebox, but if the keypath exists returns the existing node.
item_proxy insert( item_proxy pos, ///< the parent item node
const nana::string& key, ///< specifies the new node
nana::string title ///< title used for displaying in the new node.
const ::std::string& key, ///< specifies the new node
::std::string title ///< title used for displaying in the new node.
);
item_proxy erase(item_proxy i); ///< Removes the node at pos and return the Item proxy following the removed node
void erase(const nana::string& keypath); ///< Removes the node by the key path.
void erase(const ::std::string& keypath); ///< Removes the node by the key path.
nana::string make_key_path(item_proxy i, const nana::string& splitter) const;///<returns the key path
::std::string make_key_path(item_proxy i, const ::std::string& splitter) const;///<returns the key path
item_proxy selected() const; ///< returns the selected node
};//end class treebox
}//end namespace nana

View File

@@ -151,7 +151,9 @@ namespace nana
void set_pixel(int x, int y, const ::nana::color&);
void set_pixel(int x, int y);
void string(const point&, const std::string&);
void string(const point&, const std::string& text_utf8);
void string(const point&, const std::string& text_utf8, const color&);
void string(point, const char_t*, std::size_t len);
void string(const point&, const char_t*);
void string(const point&, const ::nana::string&);