DriveHQ Start Menu
Cloud Drive Mapping
Folder Sync
Cloud Backup
True Drop Box
FTP/SFTP Hosting
Group Account
DriveHQ Start Menu
Online File Server
My Storage
|
Manage Shares
|
Publishes
|
Drop Boxes
|
Group Account
WebDAV Drive Mapping
Cloud Drive Home
|
WebDAV Guide
|
Drive Mapping Tool
|
Drive Mapping URL
Complete Data Backup
Backup Guide
|
Online Backup Tool
|
Cloud-to-Cloud Backup
FTP, Email & Web Service
FTP Home
|
FTP Hosting FAQ
|
Email Hosting
|
EmailManager
|
Web Hosting
Help & Resources
About
|
Enterprise Service
|
Partnership
|
Comparisons
|
Support
Quick Links
Security and Privacy
Download Software
Service Manual
Use Cases
Group Account
Online Help
Blog
Contact
Cloud Surveillance
Sign Up
Login
Features
Business Features
Online File Server
FTP Hosting
Cloud Drive Mapping
Cloud File Backup
Email Backup & Hosting
Cloud File Sharing
Folder Synchronization
Group Management
True Drop Box
Full-text Search
AD Integration/SSO
Mobile Access
IP Camera & DVR Solution
More...
Personal Features
Personal Cloud Drive
Backup All Devices
Mobile APPs
Personal Web Hosting
Sub-Account (for Kids)
Home/PC/Kids Monitoring
More...
Software
DriveHQ Drive Mapping Tool
DriveHQ FileManager
DriveHQ Online Backup
DriveHQ Mobile Apps
Pricing
Business Plans & Pricing
Personal Plans & Pricing
Price Comparison with Others
Feature Comparison with Others
Install Mobile App
Sign up
Creating account...
Invalid character in username! Only 0-9, a-z, A-Z, _, -, . allowed.
Username is required!
Invalid email address!
E-mail is required!
Password is required!
Password is invalid!
Password and confirmation do not match.
Confirm password is required!
I accept
Membership Agreement
Please read the Membership Agreement and check "I accept"!
Free Quick Sign-up
Sign-up Page
Log in
Signing in...
Username or e-mail address is required!
Password is required!
Keep me logged in
Quick Login
Forgot Password
Up
Upload
Download
Share
Publish
New Folder
New File
Copy
Cut
Delete
Paste
Rate
Upgrade
Rotate
Effect
Edit
Slide
History
/* * * Copyright (c) 2004 * John Maddock * * Use, modification and distribution are subject to the * Boost Software License, Version 1.0. (See accompanying file * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) * */ /* * LOCATION: see http://www.boost.org for most recent version. * FILE object_cache.hpp * VERSION see
* DESCRIPTION: Implements a generic object cache. */ #ifndef BOOST_REGEX_OBJECT_CACHE_HPP #define BOOST_REGEX_OBJECT_CACHE_HPP #include
#include
#include
#include
#include
#include
#ifdef BOOST_HAS_THREADS #include
#endif namespace boost{ template
class object_cache { public: typedef std::pair< ::boost::shared_ptr
, Key const*> value_type; typedef std::list
list_type; typedef typename list_type::iterator list_iterator; typedef std::map
map_type; typedef typename map_type::iterator map_iterator; typedef typename list_type::size_type size_type; static boost::shared_ptr
get(const Key& k, size_type max_cache_size); private: static boost::shared_ptr
do_get(const Key& k, size_type max_cache_size); struct data { list_type cont; map_type index; }; // Needed by compilers not implementing the resolution to DR45. For reference, // see http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#45. friend struct data; }; template
boost::shared_ptr
object_cache
::get(const Key& k, size_type max_cache_size) { #ifdef BOOST_HAS_THREADS static boost::static_mutex mut = BOOST_STATIC_MUTEX_INIT; boost::static_mutex::scoped_lock l(mut); if(l) { return do_get(k, max_cache_size); } // // what do we do if the lock fails? // for now just throw, but we should never really get here... // ::boost::throw_exception(std::runtime_error("Error in thread safety code: could not acquire a lock")); return boost::shared_ptr
(); #else return do_get(k, max_cache_size); #endif } template
boost::shared_ptr
object_cache
::do_get(const Key& k, size_type max_cache_size) { typedef typename object_cache
::data object_data; typedef typename map_type::size_type map_size_type; static object_data s_data; // // see if the object is already in the cache: // map_iterator mpos = s_data.index.find(k); if(mpos != s_data.index.end()) { // // Eureka! // We have a cached item, bump it up the list and return it: // if(--(s_data.cont.end()) != mpos->second) { // splice out the item we want to move: list_type temp; temp.splice(temp.end(), s_data.cont, mpos->second); // and now place it at the end of the list: s_data.cont.splice(s_data.cont.end(), temp, temp.begin()); BOOST_ASSERT(*(s_data.cont.back().second) == k); // update index with new position: mpos->second = --(s_data.cont.end()); BOOST_ASSERT(&(mpos->first) == mpos->second->second); BOOST_ASSERT(&(mpos->first) == s_data.cont.back().second); } return s_data.cont.back().first; } // // if we get here then the item is not in the cache, // so create it: // boost::shared_ptr
result(new Object(k)); // // Add it to the list, and index it: // s_data.cont.push_back(value_type(result, 0)); s_data.index.insert(std::make_pair(k, --(s_data.cont.end()))); s_data.cont.back().second = &(s_data.index.find(k)->first); map_size_type s = s_data.index.size(); BOOST_ASSERT(s_data.index[k]->first.get() == result.get()); BOOST_ASSERT(&(s_data.index.find(k)->first) == s_data.cont.back().second); BOOST_ASSERT(s_data.index.find(k)->first == k); if(s > max_cache_size) { // // We have too many items in the list, so we need to start // popping them off the back of the list, but only if they're // being held uniquely by us: // list_iterator pos = s_data.cont.begin(); list_iterator last = s_data.cont.end(); while((pos != last) && (s > max_cache_size)) { if(pos->first.unique()) { list_iterator condemmed(pos); ++pos; // now remove the items from our containers, // then order has to be as follows: BOOST_ASSERT(s_data.index.find(*(condemmed->second)) != s_data.index.end()); s_data.index.erase(*(condemmed->second)); s_data.cont.erase(condemmed); --s; } else --pos; } BOOST_ASSERT(s_data.index[k]->first.get() == result.get()); BOOST_ASSERT(&(s_data.index.find(k)->first) == s_data.cont.back().second); BOOST_ASSERT(s_data.index.find(k)->first == k); } return result; } } #endif
object_cache.hpp
Page URL
File URL
Prev 1/3
Next
Download
( 5 KB )
Note: The DriveHQ service banners will NOT be displayed if the file owner is a paid member.
Comments
Total ratings:
0
Average rating:
Not Rated
Would you like to comment?
Join DriveHQ
for a free account, or
Logon
if you are already a member.