inlib  1.2.0
Public Member Functions | Protected Member Functions | Protected Attributes
inlib::file::base_cache Class Reference
Inheritance diagram for inlib::file::base_cache:
Inheritance graph
[legend]
Collaboration diagram for inlib::file::base_cache:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual bool fetch (const std::string &a_what, std::string &a_file)
 base_cache (std::ostream &a_out, bool a_verbose)
virtual ~base_cache ()
void set_tmp_dir (const std::string &a_dir)
void set_tmp_suffix (const std::string &a_suffix)
void clear ()

Protected Member Functions

virtual bool fetch_file (const std::string &a_what, const std::string &a_file)=0
 base_cache (const base_cache &a_from)
base_cacheoperator= (const base_cache &)

Protected Attributes

std::ostream & m_out
bool m_verbose

Detailed Description

Definition at line 24 of file fcache.


Constructor & Destructor Documentation

inlib::file::base_cache::base_cache ( std::ostream &  a_out,
bool  a_verbose 
) [inline]

Definition at line 79 of file fcache.

  :m_out(a_out)
  ,m_verbose(a_verbose)
  {}
virtual inlib::file::base_cache::~base_cache ( ) [inline, virtual]

Definition at line 83 of file fcache.

{clear();}
inlib::file::base_cache::base_cache ( const base_cache a_from) [inline, protected]

Definition at line 85 of file fcache.

  : cache(a_from)
  ,m_out(a_from.m_out)
  ,m_verbose(a_from.m_verbose)
  {}

Member Function Documentation

void inlib::file::base_cache::clear ( ) [inline]

Definition at line 96 of file fcache.

               {
    std::map<std::string,std::string>::iterator it;
    for(it = m_cache.begin();it!=m_cache.end();++it) {
      ::remove((*it).second.c_str());    
    }
    m_cache.clear();
  }
virtual bool inlib::file::base_cache::fetch ( const std::string &  a_what,
std::string &  a_file 
) [inline, virtual]

Implements inlib::file::cache.

Definition at line 26 of file fcache.

                                                               {
    std::map<std::string,std::string>::iterator it = m_cache.find(a_what);
    if(it!=m_cache.end()) { //a_what in the cache.
      if(exists((*it).second)) {
        a_file = (*it).second;
        //std::cout << "inlib::file::base_cache::fetch :"
        //          << " for what " << sout(a_what)
        //          << " file in the cache : " << sout(a_file)
        //          << std::endl;
        return true;
      }
      m_out << "inlib::file::base_cache::fetch :"
            << " WARNING : for " << sout(a_what)
            << ", file in the map no more here. We fetch again the file."
            << std::endl;
      m_cache.erase(it);
    }

    std::string file;
    if(!inlib::tmpname(m_tmp_dir,"inlib_base_cache_",m_tmp_suffix,file)) {
      m_out << "inlib::file::base_cache::fetch :"
            << " can't get a tmpname."
            << std::endl;
      a_file.clear();
      return false;
    }
  
    //std::cout << "inlib::file::base_cache::fetch :"
    //          << " for what " << sout(a_what)
    //          << " fetch ..."
    //          << std::endl;

    if(!fetch_file(a_what,file)) {
      m_out << "inlib::file::base_cache::fetch :"
            << " failed to fetch " << sout(a_what)
            << std::endl;
      ::remove(file.c_str());
      a_file.clear();
      return false;
    }
    m_cache[a_what] = file;
    a_file = file;

    //std::cout << "inlib::file::base_cache::fetch :"
    //          << " for what " << sout(a_what)
    //          << " fetch done."
    //          << std::endl;

    return true;
  }
virtual bool inlib::file::base_cache::fetch_file ( const std::string &  a_what,
const std::string &  a_file 
) [protected, pure virtual]

Implemented in inlib::web::cache.

base_cache& inlib::file::base_cache::operator= ( const base_cache ) [inline, protected]

Definition at line 90 of file fcache.

{return *this;}
void inlib::file::base_cache::set_tmp_dir ( const std::string &  a_dir) [inline]

Definition at line 92 of file fcache.

{m_tmp_dir = a_dir;}
void inlib::file::base_cache::set_tmp_suffix ( const std::string &  a_suffix) [inline]

Definition at line 93 of file fcache.

                                                 {
    m_tmp_suffix = a_suffix;
  }

Member Data Documentation

std::ostream& inlib::file::base_cache::m_out [protected]

Definition at line 115 of file fcache.

Definition at line 116 of file fcache.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines