Resources JSONFormatter::parse( const Bytes& value ) { auto json = json::parse( String::to_string( value ) ); if ( json.count( "data" ) == 0 ) { throw domain_error( "Root property must be named 'data'." ); } auto data = json[ "data" ]; Resources resources; if ( data.is_array( ) ) { for ( const auto object : data ) { if ( not object.is_object( ) ) { throw domain_error( "Root array child elements must be objects." ); } resources.push_back( parse_object( object ) ); } } else if ( data.is_object( ) ) { resources.push_back( parse_object( data ) ); } else { throw domain_error( "Root property must be unordered set or object." ); } return resources; }
void STLRepository::include( const Bytes& relationship, Resources& values ) { if ( relationship.empty( ) ) { return; } Resources relationships; unique_lock< mutex> lock( m_resources_lock ); if ( relationship == restq::SUBSCRIPTION ) { for ( const auto& resource : m_resources ) { if ( resource.lower_bound( "type" )->second == restq::SUBSCRIPTION ) { auto iterators = resource.equal_range( "queues" ); for ( const auto& queue : values ) { auto key = String::lowercase( String::to_string( queue.lower_bound( "key" )->second ) ); for ( auto iterator = iterators.first; iterator not_eq iterators.second; iterator++ ) { if ( key == String::lowercase( String::to_string( iterator->second ) ) ) { relationships.push_back( resource ); break; } } } } } } else { for ( const auto& value : values ) { const auto key = String::lowercase( String::to_string( value.lower_bound( "key" )->second ) ); const auto type = value.lower_bound( "type" )->second; const auto foreign_key = String::to_string( type ) + "-key"; for ( const auto& resource : m_resources ) { if ( resource.lower_bound( "type" )->second == relationship ) { if ( resource.count( foreign_key ) and key == String::lowercase( String::to_string( resource.lower_bound( foreign_key )->second ) ) ) { relationships.push_back( resource ); } } } } } lock.unlock( ); values.insert( values.end( ), relationships.begin( ), relationships.end( ) ); }
Resources* assign(int n) { Resources* r = new Resources; for(int i = 0; i < n; ++i) { r->push_back(mResources->back()); mResources->pop_back(); } return r; }
Resources* Activity::releasedResources() const { if (end()) { return mAllocatedResources; } else { Resources* resources = new Resources; for (Resources::const_iterator it = mAllocatedResources->begin(); it != mAllocatedResources->end(); ++it) { if (not (*mStepIterator)->needAgain((*it)->type())) { resources->push_back(*it); } } return resources; } }
void STLRepository::read( const shared_ptr< Query > query, const function< void ( const shared_ptr< Query > ) >& callback ) { Resources values; Resources resources; const auto keys = query->get_keys( ); unique_lock< mutex> lock( m_resources_lock ); if ( not keys.empty( ) ) { for ( const auto& key : keys ) { auto resource = find_if( m_resources.begin( ), m_resources.end( ), [ &key ]( const Resource & resource ) { if ( resource.count( "key" ) == 0 ) { return false; } return String::lowercase( key ) == String::lowercase( String::to_string( resource.lower_bound( "key" )->second ) ); } ); if ( resource == m_resources.end( ) ) { query->set_error_code( 40004 ); return callback( query ); } resources.push_back( *resource ); } } else { resources = m_resources; } lock.unlock( ); filter( resources, query->get_inclusive_filters( ), query->get_exclusive_filters( ) ); //just pass query const auto& index = query->get_index( ); const auto& limit = query->get_limit( ); if ( index < resources.size( ) and limit not_eq 0 ) { auto start = resources.begin( ); advance( start, index ); while ( start not_eq resources.end( ) and limit not_eq values.size( ) ) { values.push_back( *start ); start++; } } include( query->get_include( ), values ); auto results = fields( values, query ); query->set_resultset( results ); callback( query ); }