Пример #1
0
//---------------------------------------------------------------------------//
index_t
Schema::child_index(const std::string &path) const
{
    index_t res=0;

    // find p_curr with an iterator
    std::map<std::string, index_t>::const_iterator itr;
    itr = object_map().find(path);

    // error if child does not exist. 
    if(itr == object_map().end())
    {
        ///
        /// TODO: Full path errors would be nice here. 
        ///
        CONDUIT_ERROR("<Schema::child_index[OBJECT_ID]>"
                    << "Attempt to access invalid child:" << path);
    }
    else
    {
        res = itr->second;
    }

    return res;
}
Пример #2
0
//---------------------------------------------------------------------------//
void    
Schema::remove(const std::string &path)
{
    if(m_dtype.id() != DataType::OBJECT_ID)
        CONDUIT_ERROR("<Schema::remove[OBJECT_ID]> Schema is not OBJECT_ID");

    std::string p_curr;
    std::string p_next;
    utils::split_path(path,p_curr,p_next);
    index_t idx = child_index(p_curr);
    Schema *child = children()[idx];

    if(!p_next.empty())
    {
        child->remove(p_next);
    }
    else
    {
        // any index above the current needs to shift down by one
        for (index_t i = idx; i < (index_t) object_order().size(); i++)
        {
            object_map()[object_order()[i]]--;
        }
        object_map().erase(p_curr);
        object_order().erase(object_order().begin() + idx);
        children().erase(children().begin() + idx);
        delete child;
    }    
}
Пример #3
0
//---------------------------------------------------------------------------//
void    
Schema::remove(index_t idx)
{
    index_t dtype_id = m_dtype.id();
    if(! (dtype_id == DataType::LIST_ID || dtype_id == DataType::OBJECT_ID))
    {
        CONDUIT_ERROR("<Schema::remove> Schema is not LIST_ID or OBJECT_ID, dtype is" 
                      << m_dtype.name());
    }
    
    std::vector<Schema*>  &chldrn = children();
    if(idx > (index_t) chldrn.size())
    {
        CONDUIT_ERROR("<Schema::remove> Invalid index:" 
                    << idx << ">" << chldrn.size() <<  "(list_size)");
    }

    if(dtype_id == DataType::OBJECT_ID)
    {
        // any index above the current needs to shift down by one
        for (index_t i = idx; i < (index_t) object_order().size(); i++)
        {
            object_map()[object_order()[i]]--;
        }
        
        object_map().erase(object_order()[idx]);
        object_order().erase(object_order().begin() + idx);
    }

    Schema* child = chldrn[idx];
    delete child;
    chldrn.erase(chldrn.begin() + idx);
}
Пример #4
0
//---------------------------------------------------------------------------//
void
Schema::object_order_print() const
{
    std::map<std::string, index_t>::const_iterator itr; 
        
    for(itr = object_map().begin(); itr != object_map().end();itr++)
    {
       std::cout << itr->first << ":" << itr->second << " ";
    }
    std::cout << std::endl;
}
Пример #5
0
void sobject_raw_move(Object o, mapVec amt) {
  ObjectInfo oi = object_context(o);
  Object o2 = objectinfo_attached_object(oi);
  AttachMode mode = objectinfo_attach_mode(oi);
  if(o2) {
    if(mode == AttachCarry) {
      map_move_object(object_map(o), object_id(o), amt);
      map_move_object(object_map(o), object_id(o2), amt);
    } else if(mode == AttachLatch) {
      TUG(o, o2, x, <, left);
      TUG(o, o2, x, >, right);
      TUG(o, o2, y, <, back);
      TUG(o, o2, y, >, forward);
    }
  } else {
Пример #6
0
//---------------------------------------------------------------------------//
bool           
Schema::has_path(const std::string &path) const
{
    if(m_dtype.id() == DataType::EMPTY_ID)
        return false;
    if(m_dtype.id() != DataType::OBJECT_ID)
        CONDUIT_ERROR("<Schema::has_path[OBJECT_ID]> Schema is not OBJECT_ID");

    std::string p_curr;
    std::string p_next;
    utils::split_path(path,p_curr,p_next);
    
    // handle parent case (..)
    
    const std::map<std::string,index_t> &ents = object_map();

    if(ents.find(p_curr) == ents.end())
    {
        return false;
    }

    if(!p_next.empty())
    {
        index_t idx = ents.find(p_curr)->second;
        return children()[idx]->has_path(p_next);
    }
    else
    {
        return true;
    }
}
Пример #7
0
//---------------------------------------------------------------------------//
Schema &
Schema::fetch(const std::string &path)
{
    // fetch w/ path forces OBJECT_ID
    init_object();
        
    std::string p_curr;
    std::string p_next;
    utils::split_path(path,p_curr,p_next);

    // handle parent 
    // check for parent
    if(p_curr == "..")
    {
        if(m_parent != NULL) // TODO: check for error (no parent)
           return m_parent->fetch(p_next);
    }
    
    if (!has_path(p_curr)) 
    {
        Schema* my_schema = new Schema();
        my_schema->m_parent = this;
        children().push_back(my_schema);
        object_map()[p_curr] = children().size() - 1;
        object_order().push_back(p_curr);
    }

    index_t idx = child_index(p_curr);
    if(p_next.empty())
    {
        return *children()[idx];
    }
    else
    {
        return children()[idx]->fetch(p_next);
    }

}
Пример #8
0
//---------------------------------------------------------------------------//
void 
Schema::set(const Schema &schema)
{
    bool init_children = false;
    index_t dt_id = schema.m_dtype.id();
    if (dt_id == DataType::OBJECT_ID)
    {
       init_object();
       init_children = true;

       object_map() = schema.object_map();
       object_order() = schema.object_order();
    } 
    else if (dt_id == DataType::LIST_ID)
    {
       init_list();
       init_children = true;
    }
    else 
    {
        m_dtype = schema.m_dtype;
    }

    
    if (init_children) 
    {
       std::vector<Schema*> &my_children = children();
       const std::vector<Schema*> &their_children = schema.children();
       for (index_t i = 0; i < (index_t)their_children.size(); i++) 
       {
           Schema *child_schema = new Schema(*their_children[i]);
           child_schema->m_parent = this;
           my_children.push_back(child_schema);
       }
    }
}
Пример #9
0
//---------------------------------------------------------------------------//
bool
Schema::equals(const Schema &s) const
{
    index_t dt_id   = m_dtype.id();
    index_t s_dt_id = s.dtype().id();

    if(dt_id != s_dt_id)
        return false;
    
    bool res = true;
    
    if(dt_id == DataType::OBJECT_ID)
    {
        // all entries must be equal
        
        std::map<std::string, index_t>::const_iterator itr;
        
        for(itr  = s.object_map().begin(); 
            itr != s.object_map().end() && res;
            itr++)
        {
            if(has_path(itr->first))
            {
                index_t s_idx = itr->second;
                res = s.children()[s_idx]->equals(fetch_child(itr->first));
            }
            else
            {
                res = false;
            }
        }
        
        for(itr  = object_map().begin(); 
            itr != object_map().end() && res;
            itr++)
        {
            if(s.has_path(itr->first))
            {
                index_t idx = itr->second;
                res = children()[idx]->equals(s.fetch_child(itr->first));
            }
            else
            {
                res = false;
            }
        }
        
    }
    else if(dt_id == DataType::LIST_ID) 
    {
        // all entries must be equal
        index_t s_n_chd = s.number_of_children();
        
        // can't be compatible in this case
        if(number_of_children() != s_n_chd)
            return false;

        const std::vector<Schema*> &s_lst = s.children();
        const std::vector<Schema*> &lst   = children();

        for(index_t i = 0; i < s_n_chd && res; i++)
        {
            res = lst[i]->equals(*s_lst[i]);
        }
    }
    else
    {
        res = m_dtype.equals(s.dtype());
    }
    return res;
}