/* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once #include #include #include #include #include #include #include #include #include namespace Swift { /** * XEP-0004 Data form. * For the relevant Fields, the parsers and serialisers protect the API user against * the strange multi-value instead of newline thing by transforming them. */ class SWIFTEN_API Form : public Payload { public: typedef std::shared_ptr
ref; typedef std::vector FormItem; enum Type { FormType, SubmitType, CancelType, ResultType }; public: Form(Type type = FormType) : type_(type) {} void addPage(std::shared_ptr page) { assert(page); pages_.push_back(page); } const std::vector >& getPages() const { return pages_; } void addField(std::shared_ptr field) { assert(field); fields_.push_back(field); } const std::vector >& getFields() const { return fields_; } void clearFields() { fields_.clear(); } void addTextElement(std::shared_ptr text) { assert(text); textElements_.push_back(text); } const std::vector >& getTextElements() const { return textElements_; } void addReportedRef(std::shared_ptr reportedRef) { assert(reportedRef); reportedRefs_.push_back(reportedRef); } const std::vector >& getReportedRefs() const { return reportedRefs_; } void setTitle(const std::string& title) { title_ = title; } const std::string& getTitle() const { return title_; } void setInstructions(const std::string& instructions) { instructions_ = instructions; } const std::string& getInstructions() const { return instructions_; } /** Returns the Form::Type enum (ie. ResultType, CancelType etc.). * NOT to be confused with Form::getFormType(). */ Type getType() const { return type_; } void setType(Type type) { type_ = type; } /** Returns the value of the field FORM_TYPE * NOT to be confused with Form::getType(). */ std::string getFormType() const; FormField::ref getField(const std::string& name) const; void addItem(const FormItem& item); const std::vector& getItems() const; void clearItems() { items_.clear(); } void clearEmptyTextFields(); void addReportedField(FormField::ref field); const std::vector & getReportedFields() const; void clearReportedFields() { reportedFields_.clear(); } private: std::vector >reportedRefs_; std::vector > textElements_; std::vector > pages_; std::vector > fields_; std::vector > reportedFields_; std::vector items_; std::shared_ptr reportedRef_; std::string title_; std::string instructions_; Type type_; }; }