📄 searchspec_sequence.hpp
字号:
}
#if defined(STLSOFT_COMPILER_IS_MSVC) && \
_MSC_VER < 1300
friend class const_iterator;
#endif /* compiler */
public:
static search_state *create(char_type const* rootDir, char_type const* searchSpec, char_type delimiter, ss_int_t flags)
{
search_state *ss = new search_state(rootDir, searchSpec, delimiter, flags);
if(ss->m_tokensNext == ss->m_tokensEnd)
{
delete ss;
ss = NULL;
}
return ss;
}
public:
bool next()
{
if(m_tokensNext == m_tokensEnd)
{
return false;
}
STLSOFT_ASSERT(m_tokensNext != m_tokensEnd);
STLSOFT_ASSERT(NULL != m_entries || m_tokensNext == m_tokensEnd);
// We are doing two enumerations here.
//
// The outer enumeration is over the tokens, the
// inner is over the file entries.
++m_entriesNext;
while(m_entriesNext == m_entriesEnd)
{
++m_tokensNext;
if(m_tokensNext == m_tokensEnd)
{
return false;
}
else
{
STLSOFT_ASSERT(NULL != m_entries);
stlsoft_destroy_instance_fn(m_entries);
#if defined(STLSOFT_COMPILER_IS_VECTORC)
m_entries = new(m_entries) find_sequence_type(m_rootDir.c_str(), (*m_tokensNext).c_str(), m_flags);
#else /* ? compiler */
m_entries = new(m_entries) find_sequence_type(c_str_ptr(m_rootDir), c_str_ptr(*m_tokensNext), m_flags);
#endif /* compiler */
m_entriesEnd = m_entries->end();
m_entriesNext = m_entries->begin();
}
}
return true;
}
void Release()
{
if(0 == --m_cRefs)
{
delete this;
}
}
#if defined(STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR)
protected:
#else /* ? STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR */
private:
#endif /* STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR */
~search_state() stlsoft_throw_0()
{
delete m_entries;
}
};
/// @}
/// \name Iteration
/// @{
public:
/// The const_iterator type for the searchspec_sequence
class const_iterator
{
private:
typedef const_iterator class_type;
private:
friend class searchspec_sequence<S>;
const_iterator(char_type const* rootDir, char_type const* searchSpec, char_type delimiter, ss_int_t flags)
: m_searchState(search_state::create(rootDir, searchSpec, delimiter, flags))
{}
public:
/// Default constructor
const_iterator()
: m_searchState(NULL)
{}
/// Destructor
~const_iterator() stlsoft_throw_0()
{
if(NULL != m_searchState)
{
m_searchState->Release();
}
}
/// Copy constructor
const_iterator(class_type const& rhs)
: m_searchState(rhs.m_searchState)
{
if(NULL != m_searchState)
{
++m_searchState->m_cRefs;
}
}
class_type& operator =(class_type const& rhs)
{
if(NULL != m_searchState)
{
m_searchState->Release();
}
m_searchState = rhs.m_searchState;
if(NULL != m_searchState)
{
++m_searchState->m_cRefs;
}
return *this;
}
public:
class_type& operator ++()
{
STLSOFT_ASSERT(NULL != m_searchState);
if(!m_searchState->next())
{
#if defined(STLSOFT_COMPILER_IS_MSVC) && \
_MSC_VER < 1300
m_searchState->Release();
m_searchState = NULL;
#else /* ? compiler */
call_set_null(m_searchState, &search_state::Release);
#endif /* compiler */
}
return *this;
}
class_type operator ++(int)
{
class_type ret(*this);
operator ++();
return ret;
}
/// Dereference to return the value at the current position
const value_type operator *() const
{
STLSOFT_ASSERT(NULL != m_searchState);
return *m_searchState->m_entriesNext;
}
ss_bool_t operator ==(class_type const& rhs) const
{
// Only evaluate the same when both are at their ends
return (NULL == m_searchState) && (NULL == rhs.m_searchState);
}
ss_bool_t operator !=(class_type const& rhs) const
{
return !operator ==(rhs);
}
private:
search_state *m_searchState;
};
/// @}
/// \name Iteration
/// @{
public:
/// Begins the iteration
///
/// \return An iterator representing the start of the sequence
const_iterator begin() const
{
#if defined(STLSOFT_COMPILER_IS_VECTORC)
return const_iterator(m_rootDir.c_str(), (m_searchSpec).c_str(), m_delimiter, m_flags);
#else /* ? compiler */
return const_iterator(c_str_ptr(m_rootDir), c_str_ptr(m_searchSpec), m_delimiter, m_flags);
#endif /* compiler */
}
/// Ends the iteration
///
/// \return An iterator representing the end of the sequence
const_iterator end() const
{
return const_iterator();
}
/// @}
/// \name Attributes
/// @{
public:
/// \brief Indicates whether the sequence is empty
ss_bool_t empty() const
{
return begin() == end();
}
/// @}
/// \name Implementation
/// @{
private:
static char_type const* get_root_dir()
{
static char_type s_rootDir[2] = { '.', '\0' };
return s_rootDir;
}
/// @}
/// \name Members
/// @{
private:
string_type m_rootDir;
string_type m_searchSpec;
char_type m_delimiter;
ss_int_t m_flags;
/// @}
};
////////////////////////////////////////////////////////////////////////////
// Unit-testing
#ifdef STLSOFT_UNITTEST
# include "./unittest/searchspec_sequence_unittest_.h"
#endif /* STLSOFT_UNITTEST */
////////////////////////////////////////////////////////////////////////////
// Implementation
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* ////////////////////////////////////////////////////////////////////// */
#ifndef _STLSOFT_NO_NAMESPACE
} // namespace stlsoft
#endif /* _STLSOFT_NO_NAMESPACE */
/* ////////////////////////////////////////////////////////////////////// */
#endif /* STLSOFT_INCL_STLSOFT_FILESYSTEM_HPP_SEARCHSPEC_SEQUENCE */
/* ////////////////////////////////////////////////////////////////////// */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -