Exemple #1
0
	int Reader::push(Configure * cfg, const char * buf, size_t length) {
		const char *p = buf;
		while(*p != 0 && isspace(*p)){
			++p;
		}
		try{
			if(*p == '#' || *p == 0){ //is comment or blank line
				return 0;
			} else if (*p == '['){ //must be section
				str_t str;
				if( sectionParser(p, length, &str) != 0 ){
					return -1;
				}
				cfg->changeSection(str);
			} else { // is config key-value pair
				struct pair_t pair;
				if( keyParser(p, length, &pair) != 0 ){
					return -1;
				}
				cfg->pushPair(pair.key, pair.value);
			}
		} catch(std::runtime_error){
			return -1;
		}
		return 0;
	}
         bool CAbstractRegistryDriver::Write( const std::string& aKey, const CVariant& aValue )
         {
            TRACE_FUN( Frequently, "CAbstractRegistryDriver::Write" );

            CMutexLocker locker( synchronization().mutex() );
            
            bool ret( false );

            CCategoryKeyParser keyParser( aKey );
            
            if( ret = category()->Write( keyParser, aValue ) )
            {
               _isModified = true;
            }
            
            return ret;
         }
         TKeyListIterator CAbstractRegistryDriver::VariableList( const std::string& aKey, TKeyList& aList )const
         {
            CMutexLocker locker( synchronization().mutex() );

            TKeyListIterator ret( aList.end() );

            do
            {
               CCategoryKeyParser keyParser( aKey );

               ret = category()->VariableList( keyParser, aList );
               
               synchronization().continueRead();
            }
            while( ret == aList.end() && isRun() );

            return ret;
         }
         bool CAbstractRegistryDriver::Read( const std::string& aKey, CVariant& aValue )const
         {
            TRACE_FUN( Frequently, "CAbstractRegistryDriver::Read" );

            CMutexLocker locker( synchronization().mutex() );

            bool ret( false );

            do
            {
               CCategoryKeyParser keyParser( aKey );

               ret = category()->Read( keyParser, aValue );
               
               synchronization().continueRead();
            }
            while( !ret && isRun() );

            return ret;
         }