Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: a3c0e3844c
Fetching contributors…

Cannot retrieve contributors at this time

file 171 lines (136 sloc) 5.271 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
/*
Copyright (c) 2007 Cyrus Daboo. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/*
CVCardProperty.h

Author:
Description: <describe the CVCardProperty class here>
*/

#ifndef CVCardProperty_H
#define CVCardProperty_H

#include "CVCardAttribute.h"
#include "CVCardValue.h"

#include <stdint.h>
#include <map>
#include <set>

#include "cdstring.h"


namespace vCard {

typedef uint32_t CVCardRef; // Unique reference to object

class CVCardAddressValue;
class CVCardDateTimeValue;
class CVCardMultiValue;
class CVCardNValue;
class CVCardPlainTextValue;
class CVCardURIValue;
class CVCardUTCOffsetValue;

class CVCardAddress;
class CVCardDateTime;
typedef std::vector<CVCardDateTime> CVCardDateTimeList;
class CVCardN;

class CVCardProperty
{
public:
CVCardProperty()
{ _init_CVCardProperty(); }
CVCardProperty(const cdstring& name, const cdstring& text_value, CVCardValue::EVCardValueType value_type = CVCardValue::eValueType_Text)
{ mName = name; _init_attr_value(text_value, value_type); }
CVCardProperty(const cdstring& name, const CVCardAddress& addr)
{ mName = name; _init_attr_value(addr); }
CVCardProperty(const cdstring& name, const CVCardDateTime& dt)
{ mName = name; _init_attr_value(dt); }
CVCardProperty(const cdstring& name, const CVCardDateTimeList& dtl)
{ mName = name; _init_attr_value(dtl); }
CVCardProperty(const cdstring& name, const CVCardN& n)
{ mName = name; _init_attr_value(n); }
CVCardProperty(const CVCardProperty& copy)
{ _init_CVCardProperty(); _copy_CVCardProperty(copy); }
virtual ~CVCardProperty()
{ _tidy_CVCardProperty(); }

CVCardProperty& operator=(const CVCardProperty& copy)
{ if (this != &copy) _copy_CVCardProperty(copy); return *this; }

cdstring& GetGroup()
{ return mGroup; }
const cdstring& GetGroup() const
{ return mGroup; }
void SetGroup(const cdstring& group)
{ mGroup = group; }

cdstring& GetName()
{ return mName; }
const cdstring& GetName() const
{ return mName; }
void SetName(const cdstring& name)
{ mName = name; }

CVCardAttributeMap& GetAttributes()
{ return mAttributes; }
const CVCardAttributeMap& GetAttributes() const
{ return mAttributes; }
void SetAttributes(const CVCardAttributeMap& attributes)
{ mAttributes = attributes; }
bool HasAttribute(const cdstring& attr) const
{
return mAttributes.count(attr) != 0;
}
bool HasAttributeValue(const cdstring& attr, const cdstring& value, bool casei = false) const;
const cdstring& GetAttributeValue(const cdstring& attr) const
{
return (*mAttributes.find(attr)).second.GetFirstValue();
}

void AddAttribute(const CVCardAttribute& attr);
void RemoveAttributes(const cdstring& attr);

CVCardValue* GetValue()
{ return mValue; }
const CVCardValue* GetValue() const
{ return mValue; }

const CVCardAddressValue* GetAddressValue() const;
const CVCardDateTimeValue* GetDateTimeValue() const;
const CVCardMultiValue* GetMultiValue() const;
const CVCardNValue* GetNValue() const;
const CVCardPlainTextValue* GetTextValue() const;
const CVCardURIValue* GetURIValue() const;
const CVCardUTCOffsetValue* GetUTCOffsetValue() const;

bool Parse(cdstring& data);
void Generate(std::ostream& os) const;

protected:
cdstring mGroup;
cdstring mName;
CVCardAttributeMap mAttributes;
CVCardValue* mValue;

typedef std::map<cdstring, CVCardValue::EVCardValueType> CValueTypeMap;
static CValueTypeMap sDefaultValueTypeMap;
static CValueTypeMap sValueTypeMap;

typedef std::map<CVCardValue::EVCardValueType, cdstring> CTypeValueMap;
static CTypeValueMap sTypeValueMap;

typedef std::map<CVCardValue::EVCardValueType, CVCardValue::EVCardValueType> CEquivalentTypeMap;
static CEquivalentTypeMap sEquivalentTypeMap;

typedef cdstrset CMultiValues;
static CMultiValues sMultiValues;

private:
void _init_CVCardProperty()
{ mValue = NULL; }
void _copy_CVCardProperty(const CVCardProperty& copy)
{ _tidy_CVCardProperty(); mGroup = copy.mGroup; mName = copy.mName; mAttributes = copy.mAttributes; mValue = copy.mValue->clone(); }
void _tidy_CVCardProperty()
{ delete mValue; mValue = NULL; }
void _init_map();

void CreateValue(const char* data);
void SetupValueAttribute();


// Creation
void _init_attr_value(const cdstring& txt, CVCardValue::EVCardValueType value_type = CVCardValue::eValueType_Text);
void _init_attr_value(const CVCardAddress& addr);
void _init_attr_value(const CVCardDateTime& dt);
void _init_attr_value(const CVCardDateTimeList& dtl);
void _init_attr_value(const CVCardN& n);
};

typedef std::multimap<cdstring, CVCardProperty, case_insensitive_cdstring> CVCardPropertyMap;
typedef std::vector<CVCardProperty> CVCardPropertyList;

} // namespace vCard

#endif // CVCardProperty_H
Something went wrong with that request. Please try again.