dataformfield.h
/*
Copyright (c) 2005-2023 by Jakob Schröter <js@camaya.net>
This file is part of the gloox library. http://camaya.net/gloox
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#ifndef DATAFORMFIELD_H__
#define DATAFORMFIELD_H__
#include "gloox.h"
#include <utility>
#include <string>
namespace gloox
{
class Tag;
class GLOOX_API DataFormField
{
public:
enum FieldType
{
TypeBoolean,
TypeFixed,
TypeHidden,
TypeJidMulti,
TypeJidSingle,
TypeListMulti,
TypeListSingle,
TypeTextMulti,
TypeTextPrivate,
TypeTextSingle,
TypeNone,
TypeInvalid
};
public:
DataFormField( FieldType type = TypeTextSingle );
DataFormField( const std::string& name, const std::string& value = EmptyString,
const std::string& label = EmptyString, FieldType type = TypeTextSingle );
DataFormField( const Tag* tag );
virtual ~DataFormField();
const StringMultiMap& options() const { return m_options; }
virtual Tag* tag() const;
const std::string& name() const { return m_name; }
void setName( const std::string& name ) { m_name = name; }
void setOptions( const StringMultiMap& options ) { m_options = options; }
void addOption( const std::string& label, const std::string& value )
{ m_options.insert( std::make_pair( label, value ) ); }
bool required() const { return m_required; }
void setRequired( bool required ) { m_required = required; }
const std::string& label() const { return m_label; }
void setLabel( const std::string& label ) { m_label = label; }
const std::string& description() const { return m_desc; }
void setDescription( const std::string& desc ) { m_desc = desc; }
const std::string& value() const { return ( m_values.size() > 0 ) ? m_values.front() : EmptyString; }
void setValue( const std::string& value ) { m_values.clear(); addValue( value ); }
const StringList& values() const { return m_values; }
void setValues( const StringList& values ) { m_values = values; }
void addValue( const std::string& value ) { m_values.push_back( value ); }
FieldType type() const { return m_type; }
operator bool() const { return m_type != TypeInvalid; }
private:
FieldType m_type;
StringMultiMap m_options;
StringList m_values;
std::string m_name;
std::string m_desc;
std::string m_label;
bool m_required;
};
}
#endif // DATAFORMFIELD_H__
gloox::DataFormField
An abstraction of a single field in a XEP-0004 Data Form.
Definition dataformfield.h:34
gloox::DataFormField::DataFormField
DataFormField(FieldType type=TypeTextSingle)
Definition dataformfield.cpp:26
gloox::DataFormField::setDescription
void setDescription(const std::string &desc)
Definition dataformfield.h:183
gloox::DataFormField::name
const std::string & name() const
Definition dataformfield.h:122
gloox::DataFormField::type
FieldType type() const
Definition dataformfield.h:220
gloox::DataFormField::setOptions
void setOptions(const StringMultiMap &options)
Definition dataformfield.h:138
gloox::DataFormField::options
const StringMultiMap & options() const
Definition dataformfield.h:108
gloox::DataFormField::addOption
void addOption(const std::string &label, const std::string &value)
Definition dataformfield.h:146
gloox::DataFormField::label
const std::string & label() const
Definition dataformfield.h:165
gloox::DataFormField::addValue
void addValue(const std::string &value)
Definition dataformfield.h:214
gloox::DataFormField::value
const std::string & value() const
Definition dataformfield.h:189
gloox::DataFormField::setRequired
void setRequired(bool required)
Definition dataformfield.h:159
gloox::DataFormField::setLabel
void setLabel(const std::string &label)
Definition dataformfield.h:171
gloox::DataFormField::setName
void setName(const std::string &name)
Definition dataformfield.h:130
gloox::DataFormField::FieldType
FieldType
Definition dataformfield.h:41
gloox::DataFormField::TypeHidden
@ TypeHidden
Definition dataformfield.h:49
gloox::DataFormField::TypeListSingle
@ TypeListSingle
Definition dataformfield.h:57
gloox::DataFormField::TypeListMulti
@ TypeListMulti
Definition dataformfield.h:55
gloox::DataFormField::TypeJidMulti
@ TypeJidMulti
Definition dataformfield.h:51
gloox::DataFormField::TypeInvalid
@ TypeInvalid
Definition dataformfield.h:70
gloox::DataFormField::TypeTextMulti
@ TypeTextMulti
Definition dataformfield.h:59
gloox::DataFormField::TypeBoolean
@ TypeBoolean
Definition dataformfield.h:42
gloox::DataFormField::TypeJidSingle
@ TypeJidSingle
Definition dataformfield.h:53
gloox::DataFormField::TypeTextPrivate
@ TypeTextPrivate
Definition dataformfield.h:61
gloox::DataFormField::TypeNone
@ TypeNone
Definition dataformfield.h:68
gloox::DataFormField::TypeTextSingle
@ TypeTextSingle
Definition dataformfield.h:64
gloox::DataFormField::TypeFixed
@ TypeFixed
Definition dataformfield.h:44
gloox::DataFormField::description
const std::string & description() const
Definition dataformfield.h:177
gloox::DataFormField::setValues
void setValues(const StringList &values)
Definition dataformfield.h:208
gloox::DataFormField::setValue
void setValue(const std::string &value)
Definition dataformfield.h:195
gloox::DataFormField::values
const StringList & values() const
Definition dataformfield.h:201
gloox::DataFormField::required
bool required() const
Definition dataformfield.h:153
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::StringMultiMap
std::multimap< std::string, std::string > StringMultiMap
Definition gloox.h:1266
gloox::StringList
std::list< std::string > StringList
Definition gloox.h:1251
gloox::EmptyString
const std::string EmptyString
Definition gloox.cpp:124