Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot use removeMember because it has only string parameters, not ArrayIndex #28

Closed
cdunn2001 opened this issue Aug 13, 2014 · 1 comment

Comments

@cdunn2001
Copy link
Contributor

From Itzik S (privately):

The following is simple solution.

void Value::remove(ArrayIndex index)
{
    if (type_ == arrayValue){
#ifndef JSON_VALUE_USE_INTERNAL_MAP
        CZString key(index);
        ObjectValues::iterator it = value_.map_->find(key);
        if (it != value_.map_->end()){
            ArrayIndex oldSize = size();
            // shift left all items left, into the place of the "removed"
            for (ArrayIndex i=index; i<oldSize-1; i++){
                CZString key(i);
                (*value_.map_)[key] = (*this)[i+1];
            }
            // erase the last one ("leftover")
            CZString keyLast(oldSize-1);
            ObjectValues::iterator itLast = value_.map_->find(keyLast);
            value_.map_->erase(itLast);
        }
#else
        NOT SUPPORTED
#endif
    }
}
@cdunn2001
Copy link
Contributor Author

Not super efficient, but convenient.

cdunn2001 added a commit to cdunn2001/jsoncpp that referenced this issue Jan 20, 2015
@cdunn2001 cdunn2001 mentioned this issue Jan 20, 2015
cdunn2001 added a commit that referenced this issue Jan 21, 2015
`Value::removeIndex()`

See issue #28.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant