/* */ #include "ValueBaseStructParserStateMachine.h" #include #include "XmlRpcRequestParserController.h" #include "ValueBaseStructParserStateImpl.h" #include "ValueBase.h" namespace aria2 { namespace { ValueValueBaseStructParserState* valueState = new ValueValueBaseStructParserState(); DictValueBaseStructParserState* dictState = new DictValueBaseStructParserState(); DictKeyValueBaseStructParserState* dictKeyState = new DictKeyValueBaseStructParserState(); DictDataValueBaseStructParserState* dictDataState = new DictDataValueBaseStructParserState(); ArrayValueBaseStructParserState* arrayState = new ArrayValueBaseStructParserState(); ArrayDataValueBaseStructParserState* arrayDataState = new ArrayDataValueBaseStructParserState(); StringValueBaseStructParserState* stringState = new StringValueBaseStructParserState(); NumberValueBaseStructParserState* numberState = new NumberValueBaseStructParserState(); BoolValueBaseStructParserState* boolState = new BoolValueBaseStructParserState(); NullValueBaseStructParserState* nullState = new NullValueBaseStructParserState(); } // namespace const SharedHandle ValueBaseStructParserStateMachine::noResult = ValueBase::none; ValueBaseStructParserStateMachine::ValueBaseStructParserStateMachine() : ctrl_(new rpc::XmlRpcRequestParserController()) { stateStack_.push(valueState); } ValueBaseStructParserStateMachine::~ValueBaseStructParserStateMachine() { delete ctrl_; } void ValueBaseStructParserStateMachine::reset() { while(!stateStack_.empty()) { stateStack_.pop(); } stateStack_.push(valueState); ctrl_->reset(); } void ValueBaseStructParserStateMachine::beginElement(int elementType) { stateStack_.top()->beginElement(this, elementType); } void ValueBaseStructParserStateMachine::endElement(int elementType) { stateStack_.top()->endElement(this, elementType); stateStack_.pop(); } SharedHandle ValueBaseStructParserStateMachine::getResult() const { return getCurrentFrameValue(); } void ValueBaseStructParserStateMachine::charactersCallback (const char* data, size_t len) { sessionData_.str.append(data, len); } void ValueBaseStructParserStateMachine::numberCallback (int64_t number, int frac, int exp) { sessionData_.number.number = number; sessionData_.number.frac = frac; sessionData_.number.exp = exp; } void ValueBaseStructParserStateMachine::boolCallback(bool bval) { sessionData_.bval = bval; } const std::string& ValueBaseStructParserStateMachine::getCharacters() const { return sessionData_.str; } const ValueBaseStructParserStateMachine::NumberData& ValueBaseStructParserStateMachine::getNumber() const { return sessionData_.number; } bool ValueBaseStructParserStateMachine::getBool() const { return sessionData_.bval; } void ValueBaseStructParserStateMachine::popArrayFrame() { ctrl_->popArrayFrame(); } void ValueBaseStructParserStateMachine::popDictFrame() { ctrl_->popStructFrame(); } void ValueBaseStructParserStateMachine::pushFrame() { ctrl_->pushFrame(); } void ValueBaseStructParserStateMachine::setCurrentFrameValue (const SharedHandle& value) { ctrl_->setCurrentFrameValue(value); } const SharedHandle& ValueBaseStructParserStateMachine::getCurrentFrameValue() const { return ctrl_->getCurrentFrameValue(); } void ValueBaseStructParserStateMachine::setCurrentFrameName (const std::string& name) { ctrl_->setCurrentFrameName(name); } void ValueBaseStructParserStateMachine::pushDictState() { stateStack_.push(dictState); } void ValueBaseStructParserStateMachine::pushDictKeyState() { sessionData_.str.clear(); stateStack_.push(dictKeyState); } void ValueBaseStructParserStateMachine::pushDictDataState() { stateStack_.push(dictDataState); } void ValueBaseStructParserStateMachine::pushArrayState() { stateStack_.push(arrayState); } void ValueBaseStructParserStateMachine::pushArrayDataState() { stateStack_.push(arrayDataState); } void ValueBaseStructParserStateMachine::pushStringState() { sessionData_.str.clear(); stateStack_.push(stringState); } void ValueBaseStructParserStateMachine::pushNumberState() { memset(&sessionData_.number, 0, sizeof(sessionData_.number)); stateStack_.push(numberState); } void ValueBaseStructParserStateMachine::pushBoolState() { sessionData_.bval = false; stateStack_.push(boolState); } void ValueBaseStructParserStateMachine::pushNullState() { stateStack_.push(nullState); } } // namespace aria2