Commit 61847b9d authored by Marko Mäkelä's avatar Marko Mäkelä

Tablespace: Add iterator, const_iterator, begin(), end()

parent 5ad46457
...@@ -39,11 +39,8 @@ bool ...@@ -39,11 +39,8 @@ bool
Tablespace::intersection( Tablespace::intersection(
const Tablespace* other_space) const Tablespace* other_space)
{ {
files_t::const_iterator end = other_space->m_files.end(); for (files_t::const_iterator it(other_space->begin()),
end(other_space->end()); it != end; ++it) {
for (files_t::const_iterator it = other_space->m_files.begin();
it != end;
++it) {
if (find(it->m_filename)) { if (find(it->m_filename)) {
...@@ -58,9 +55,7 @@ Tablespace::intersection( ...@@ -58,9 +55,7 @@ Tablespace::intersection(
void void
Tablespace::shutdown() Tablespace::shutdown()
{ {
files_t::iterator end = m_files.end(); for (iterator it = begin(); it != end(); ++it) {
for (files_t::iterator it = m_files.begin(); it != end; ++it) {
it->shutdown(); it->shutdown();
} }
...@@ -95,10 +90,7 @@ Tablespace::open_or_create(bool is_temp) ...@@ -95,10 +90,7 @@ Tablespace::open_or_create(bool is_temp)
ut_ad(!m_files.empty()); ut_ad(!m_files.empty());
files_t::iterator begin = m_files.begin(); for (iterator it = begin(); it != end(); ++it) {
files_t::iterator end = m_files.end();
for (files_t::iterator it = begin; it != end; ++it) {
if (it->m_exists) { if (it->m_exists) {
err = it->open_or_create( err = it->open_or_create(
...@@ -124,7 +116,7 @@ Tablespace::open_or_create(bool is_temp) ...@@ -124,7 +116,7 @@ Tablespace::open_or_create(bool is_temp)
the proper way. */ the proper way. */
it->close(); it->close();
if (it == begin) { if (it == begin()) {
/* First data file. */ /* First data file. */
/* Create the tablespace entry for the multi-file /* Create the tablespace entry for the multi-file
...@@ -154,11 +146,9 @@ Tablespace::open_or_create(bool is_temp) ...@@ -154,11 +146,9 @@ Tablespace::open_or_create(bool is_temp)
/** Find a filename in the list of Datafiles for a tablespace /** Find a filename in the list of Datafiles for a tablespace
@return true if the filename exists in the data files */ @return true if the filename exists in the data files */
bool bool
Tablespace::find(const char* filename) Tablespace::find(const char* filename) const
{ {
files_t::const_iterator end = m_files.end(); for (const_iterator it = begin(); it != end(); ++it) {
for (files_t::const_iterator it = m_files.begin(); it != end; ++it) {
if (innobase_strcasecmp(filename, it->m_filename) == 0) { if (innobase_strcasecmp(filename, it->m_filename) == 0) {
return(true); return(true);
...@@ -172,9 +162,7 @@ Tablespace::find(const char* filename) ...@@ -172,9 +162,7 @@ Tablespace::find(const char* filename)
void void
Tablespace::delete_files() Tablespace::delete_files()
{ {
files_t::iterator end = m_files.end(); for (iterator it = begin(); it != end(); ++it) {
for (files_t::iterator it = m_files.begin(); it != end; ++it) {
it->close(); it->close();
......
...@@ -44,6 +44,10 @@ class Tablespace { ...@@ -44,6 +44,10 @@ class Tablespace {
/** Data file information - each Datafile can be accessed globally */ /** Data file information - each Datafile can be accessed globally */
files_t m_files; files_t m_files;
/** Data file iterator */
typedef files_t::iterator iterator;
/** Data file iterator */
typedef files_t::const_iterator const_iterator;
Tablespace() Tablespace()
: :
...@@ -68,6 +72,15 @@ class Tablespace { ...@@ -68,6 +72,15 @@ class Tablespace {
Tablespace(const Tablespace&); Tablespace(const Tablespace&);
Tablespace& operator=(const Tablespace&); Tablespace& operator=(const Tablespace&);
/** Data file iterator */
const_iterator begin() const { return m_files.begin(); }
/** Data file iterator */
const_iterator end() const { return m_files.end(); }
/** Data file iterator */
iterator begin() { return m_files.begin(); }
/** Data file iterator */
iterator end() { return m_files.end(); }
void set_name(const char* name) { m_name = name; } void set_name(const char* name) { m_name = name; }
const char* name() const { return m_name; } const char* name() const { return m_name; }
...@@ -156,8 +169,7 @@ class Tablespace { ...@@ -156,8 +169,7 @@ class Tablespace {
{ {
ulint sum = 0; ulint sum = 0;
for (files_t::const_iterator it = m_files.begin(); for (const_iterator it = begin(); it != end(); ++it) {
it != m_files.end(); ++it) {
sum += it->m_size; sum += it->m_size;
} }
...@@ -200,7 +212,7 @@ class Tablespace { ...@@ -200,7 +212,7 @@ class Tablespace {
/** /**
@param[in] filename Name to lookup in the data files. @param[in] filename Name to lookup in the data files.
@return true if the filename exists in the data files */ @return true if the filename exists in the data files */
bool find(const char* filename); bool find(const char* filename) const;
/** Note that the data file was found. /** Note that the data file was found.
@param[in] file data file object */ @param[in] file data file object */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment