libzypp  10.5.0
RequestedLocalesFile.h
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_TARGET_REQUESTEDLOCALESFILE_H
00013 #define ZYPP_TARGET_REQUESTEDLOCALESFILE_H
00014 
00015 #include <iosfwd>
00016 
00017 #include "zypp/base/PtrTypes.h"
00018 
00019 #include "zypp/Pathname.h"
00020 #include "zypp/Locale.h"
00021 
00023 namespace zypp
00024 { 
00025 
00026   namespace target
00027   { 
00028 
00030     //
00031     //  CLASS NAME : RequestedLocalesFile
00032     //
00035     class RequestedLocalesFile
00036     {
00037       friend std::ostream & operator<<( std::ostream & str, const RequestedLocalesFile & obj );
00038 
00039       public:
00041         RequestedLocalesFile( const Pathname & file_r )
00042         : _file( file_r )
00043         {}
00044 
00046         const Pathname & file() const
00047         { return _file; }
00048 
00053         const LocaleSet & locales() const
00054         {
00055           if ( !_localesPtr )
00056           {
00057             _localesPtr.reset( new LocaleSet );
00058             LocaleSet & ls( *_localesPtr );
00059             load( _file, ls );
00060           }
00061           return *_localesPtr;
00062         }
00063 
00068         void setLocales( const LocaleSet & locales_r )
00069         {
00070           if ( !_localesPtr )
00071             _localesPtr.reset( new LocaleSet );
00072 
00073           if ( differs( *_localesPtr, locales_r ) )
00074           {
00075             store( _file, locales_r );
00076             *_localesPtr = locales_r;
00077           }
00078         }
00079 
00080       private:
00082         bool differs( const LocaleSet & lhs, const LocaleSet & rhs ) const
00083         {
00084           if ( lhs.size() != rhs.size() )
00085             return true;
00086           for_( it, lhs.begin(), lhs.end() )
00087           {
00088             if ( rhs.find( *it ) == rhs.end() )
00089               return true;
00090           }
00091           return false;
00092         }
00094         static void load( const Pathname & file_r, LocaleSet & locales_r );
00096         static void store( const Pathname & file_r, const LocaleSet & locales_r );
00097 
00098       private:
00099         Pathname                      _file;
00100         mutable scoped_ptr<LocaleSet> _localesPtr;
00101     };
00103 
00105     std::ostream & operator<<( std::ostream & str, const RequestedLocalesFile & obj );
00106 
00108   } // namespace target
00111 } // namespace zypp
00113 #endif // ZYPP_TARGET_REQUESTEDLOCALESFILE_H