Пример #1
0
// =-=-=-=-=-=-=-
// public - accessor for parent pointer.  return value based on validity of the pointer
    error resource::get_parent( resource_ptr& _resc ) {
        _resc = parent_;
        if ( _resc.get() ) {
            return SUCCESS();
        }
        else {
            return ERROR( SYS_INVALID_INPUT_PARAM, "null parent pointer" );
        }

    } // get_parent
Пример #2
0
// =-=-=-=-=-=-=-
// public - add a child resource to this resource.  this is virtual in case a developer wants to
//          do something fancier.
    error resource::add_child( const std::string& _name, const std::string& _data, resource_ptr _resc ) {
        // =-=-=-=-=-=-=-
        // check params
        if ( _name.empty() ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "empty name" );
        }

        if ( 0 == _resc.get() ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "null resource pointer" );
        }

        // =-=-=-=-=-=-=-
        // add resource and data to the table
        children_[ _name ] = std::pair< std::string, resource_ptr >( _data, _resc );

        return SUCCESS();

    } // add_child
        error resolve_from_property( std::string   _prop,    // property key
                                     value_type    _value,   // property value
                                     resource_ptr& _resc ) { // outgoing resource variable
            // =-=-=-=-=-=-=-
            // simple flag to state a resource matching the prop and value is found
            bool found = false;

            // =-=-=-=-=-=-=-
            // quick check on the resource table
            if ( resources_.empty() ) {
                return ERROR( SYS_INVALID_INPUT_PARAM, "empty resource table" );
            }

            // =-=-=-=-=-=-=-
            // iterate through the map and search for our path
            lookup_table< resource_ptr >::iterator itr = resources_.begin();
            for ( ; itr != resources_.end(); ++itr ) {
                // =-=-=-=-=-=-=-
                // query resource for the property value
                value_type value = NULL;
                error ret = itr->second->get_property< value_type >( _prop, value );

                // =-=-=-=-=-=-=-
                // if we get a good parameter
                if ( ret.ok() ) {
                    // =-=-=-=-=-=-=-
                    // compare incoming value and stored value, assumes that the
                    // values support the comparison operator
                    if ( _value == value ) {
                        // =-=-=-=-=-=-=-
                        // if we get a match, cache the resource pointer
                        // in the given out variable and bail
                        found = true;
                        _resc = itr->second;
                        break;
                    }
                }
                else {
                    std::stringstream msg;
                    msg << "resource_manager::resolve_from_property - ";
                    msg << "failed to get vault parameter from resource";
                    irods::error err = PASSMSG( msg.str(), ret );

                }

            } // for itr

            // =-=-=-=-=-=-=-
            // did we find a resource and is the ptr valid?
            if ( true == found && _resc.get() ) {
                return SUCCESS();
            }
            else {
                std::stringstream msg;
                msg << "failed to find resource for property [";
                msg << _prop;
                msg << "] and value [";
                msg << _value;
                msg << "]";
                return ERROR( SYS_RESC_DOES_NOT_EXIST, msg.str() );
            }

        } // resolve_from_property