~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/cached_directory.cc

  • Committer: Lee Bieber
  • Date: 2011-03-13 16:37:38 UTC
  • mfrom: (2227.4.18 session2)
  • Revision ID: kalebral@gmail.com-20110313163738-7ti21zk40o2xi3ew
Merge Olaf - Refactor Session

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
25
25
 *   Implementation of CachedDirectory class.
26
26
 */
27
27
 
28
 
#include "config.h"
 
28
#include <config.h>
29
29
 
30
 
#include "drizzled/definitions.h"
 
30
#include <drizzled/definitions.h>
31
31
 
32
32
#include <sys/types.h>
33
33
#include <sys/stat.h>
36
36
#include <strings.h>
37
37
#include <limits.h>
38
38
 
39
 
#include "drizzled/cached_directory.h"
 
39
#include <drizzled/cached_directory.h>
 
40
#include <drizzled/util/find_ptr.h>
40
41
 
41
42
using namespace std;
42
43
 
50
51
 
51
52
 
52
53
CachedDirectory::CachedDirectory(const string &in_path) :
53
 
  error(0)
 
54
  error(0),
 
55
  use_full_path(false)
54
56
{
55
57
  // TODO: Toss future exception
56
58
  (void) open(in_path);
58
60
 
59
61
 
60
62
CachedDirectory::CachedDirectory(const string& in_path, set<string>& allowed_exts) :
61
 
  error(0)
 
63
  error(0),
 
64
  use_full_path(false)
62
65
{
63
66
  // TODO: Toss future exception
64
67
  (void) open(in_path, allowed_exts);
65
68
}
66
69
 
67
 
CachedDirectory::CachedDirectory(const string& in_path, enum CachedDirectory::FILTER filter) :
68
 
  error(0)
 
70
CachedDirectory::CachedDirectory(const string& in_path, enum CachedDirectory::FILTER filter, bool use_full_path_arg) :
 
71
  error(0),
 
72
  use_full_path(use_full_path_arg)
69
73
{
70
74
  set<string> empty;
71
75
  // TODO: Toss future exception
75
79
 
76
80
CachedDirectory::~CachedDirectory()
77
81
{
78
 
  for (Entries::iterator p= entries.begin(); p != entries.end(); ++p)
 
82
  for (Entries::iterator iter= entries.begin(); iter != entries.end(); ++iter)
79
83
  {
80
 
    if (*p)
81
 
      delete *p;
 
84
    delete *iter;
82
85
  }
83
86
  entries.clear();
84
87
}
128
131
         result != NULL)
129
132
  {
130
133
    std::string buffered_fullpath;
131
 
    if (! allowed_exts.empty())
 
134
    if (not allowed_exts.empty())
132
135
    {
133
136
      char *ptr= rindex(result->d_name, '.');
134
 
 
135
 
      if (ptr)
 
137
      if (ptr && allowed_exts.count(ptr))
136
138
      {
137
 
        set<string>::iterator it;
138
 
        it= allowed_exts.find(ptr);
139
 
 
140
 
        if (it != allowed_exts.end())
141
 
        {
142
 
          entries.push_back(new Entry(result->d_name));
143
 
        }
 
139
        entries.push_back(new Entry(result->d_name));
144
140
      }
145
141
    }
146
142
    else
154
150
          if (result->d_name[0] == '.') // We don't pass back anything hidden at the moment.
155
151
            continue;
156
152
 
157
 
          buffered_fullpath.append(in_path);
158
 
          if (buffered_fullpath[buffered_fullpath.length()] != '/')
159
 
            buffered_fullpath.append(1, FN_LIBCHAR);
 
153
          if (use_full_path)
 
154
          {
 
155
            buffered_fullpath.append(in_path);
 
156
            if (buffered_fullpath[buffered_fullpath.length()] != '/')
 
157
              buffered_fullpath.append(1, FN_LIBCHAR);
 
158
          }
160
159
 
161
 
          buffered_fullpath.assign(result->d_name);
 
160
          buffered_fullpath.append(result->d_name);
162
161
 
163
162
          stat(buffered_fullpath.c_str(), &entrystat);
164
163