Added convenience conversion methods in Contacts Input model. 27/71827/2
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Tue, 19 Apr 2016 14:22:24 +0000 (17:22 +0300)
committerAleksandr Sapozhnik <a.sapozhnik@samsung.com>
Mon, 30 May 2016 12:17:29 +0000 (05:17 -0700)
Removed redundant explicit instantiations.

Change-Id: I3ef73ddb94edc9b72e553710d158dce7fa4e6820
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
16 files changed:
lib-contacts/inc/Contacts/Input/ContactCompoundFieldControl.h
lib-contacts/inc/Contacts/Input/ContactDateFieldControl.h
lib-contacts/inc/Contacts/Input/ContactImageFieldControl.h
lib-contacts/inc/Contacts/Input/ContactTextFieldControl.h
lib-contacts/inc/Contacts/Input/ContactTypedFieldControl.h
lib-contacts/inc/Contacts/Model/ContactField.h
lib-contacts/inc/Contacts/Model/ContactFieldContainer.h
lib-contacts/inc/Contacts/Model/ContactObject.h
lib-contacts/src/Contacts/Details/BasicInfoItem.cpp
lib-contacts/src/Contacts/Input/ContactCompoundFieldControl.cpp
lib-contacts/src/Contacts/Input/ContactCompoundFieldItem.cpp
lib-contacts/src/Contacts/Input/InputView.cpp
lib-contacts/src/Contacts/Model/ContactCompoundObject.cpp
lib-contacts/src/Contacts/Model/ContactField.cpp
lib-contacts/src/Contacts/Model/ContactName.cpp
lib-contacts/src/Contacts/Model/ContactObject.cpp

index f2d266d..03afceb 100644 (file)
 #define CONTACTS_INPUT_CONTACT_COMPOUND_FIELD_CONTROL_H
 
 #include "Contacts/Input/ContactTextFieldControl.h"
+#include "Contacts/Model/ContactCompoundObject.h"
 
 namespace Contacts
 {
-       namespace Model
-       {
-               class ContactCompoundObject;
-       }
-
        namespace Input
        {
                /**
index 19d293e..7c415d4 100644 (file)
 #ifndef CONTACTS_INPUT_CONTACT_DATE_FIELD_CONTROL_H
 #define CONTACTS_INPUT_CONTACT_DATE_FIELD_CONTROL_H
 
+#include "Contacts/Model/ContactDateField.h"
 #include "Ui/Control.h"
 
 namespace Contacts
 {
-       namespace Model
-       {
-               class ContactDateField;
-       }
-
        namespace Input
        {
                /**
index 0092917..ce66eec 100644 (file)
 #ifndef CONTACTS_INPUT_CONTACT_IMAGE_FIELD_CONTROL_H
 #define CONTACTS_INPUT_CONTACT_IMAGE_FIELD_CONTROL_H
 
+#include "Contacts/Model/ContactTextField.h"
 #include "App/AppControl.h"
 #include "Ui/Thumbnail.h"
 
 namespace Contacts
 {
-       namespace Model
-       {
-               class ContactTextField;
-       }
-
        namespace Input
        {
                /**
index 11e9097..a637831 100644 (file)
@@ -18,6 +18,7 @@
 #ifndef CONTACTS_INPUT_CONTACT_TEXT_FIELD_CONTROL_H
 #define CONTACTS_INPUT_CONTACT_TEXT_FIELD_CONTROL_H
 
+#include "Contacts/Model/ContactTextField.h"
 #include "Ui/Editfield.h"
 #include <string>
 
@@ -28,11 +29,6 @@ namespace Ui
 
 namespace Contacts
 {
-       namespace Model
-       {
-               class ContactTextField;
-       }
-
        namespace Input
        {
                /**
index 6c8bfb3..e044f29 100644 (file)
 #ifndef CONTACTS_INPUT_CONTACT_TYPED_FIELD_CONTROL_H
 #define CONTACTS_INPUT_CONTACT_TYPED_FIELD_CONTROL_H
 
+#include "Contacts/Model/ContactEnumField.h"
+#include "Contacts/Model/ContactTextField.h"
 #include "Ui/Hoversel.h"
 
 namespace Contacts
 {
-       namespace Model
-       {
-               class ContactEnumField;
-               class ContactTextField;
-       }
-
        namespace Input
        {
                /**
index 642706a..7d0ad66 100644 (file)
@@ -205,6 +205,18 @@ namespace Contacts
                        UpdateCallback m_OnUpdated;
                };
 
+               template <typename FieldType>
+               FieldType &ContactField::cast()
+               {
+                       return static_cast<FieldType &>(*this);
+               }
+
+               template <typename FieldType>
+               const FieldType &ContactField::cast() const
+               {
+                       return static_cast<const FieldType &>(*this);
+               }
+
                typedef std::unique_ptr<ContactField> ContactFieldPtr;
                typedef std::vector<ContactFieldPtr> ContactFields;
        }
index 5629eb6..bb42a37 100644 (file)
@@ -68,6 +68,8 @@ namespace Contacts
                         * @param[in]   index   Child field index
                         * @return Child field.
                         */
+                       template <typename FieldType>
+                       FieldType *getField(unsigned index) const;
                        ContactField *getField(unsigned index) const;
 
                        /**
@@ -88,6 +90,12 @@ namespace Contacts
                        ContactFields m_Fields;
                        size_t m_FilledCount = 0;
                };
+
+               template <typename FieldType>
+               FieldType *ContactFieldContainer::getField(unsigned index) const
+               {
+                       return static_cast<FieldType *>(getField(index));
+               }
        }
 }
 
index ee449c2..4b0f2f1 100644 (file)
@@ -45,6 +45,8 @@ namespace Contacts
                         * @param[in]   id      Child field id
                         * @return Child field.
                         */
+                       template <typename FieldType>
+                       FieldType *getFieldById(unsigned id) const;
                        ContactField *getFieldById(unsigned id) const;
 
                        /**
@@ -59,11 +61,6 @@ namespace Contacts
 
                protected:
                        /**
-                        * @return Record ID.
-                        */
-                       int getRecordId(contacts_record_h record) const;
-
-                       /**
                         * @return Object type metadata.
                         */
                        const ContactObjectMetadata &getObjectMetadata() const;
@@ -82,6 +79,12 @@ namespace Contacts
                        static contacts_record_h getChildRecord(contacts_record_h record,
                                        const ContactFieldMetadata &metadata);
                };
+
+               template <typename FieldType>
+               FieldType *ContactObject::getFieldById(unsigned id) const
+               {
+                       return static_cast<FieldType *>(getFieldById(id));
+               }
        }
 }
 
index 970725c..d1e76f9 100644 (file)
@@ -33,17 +33,17 @@ using namespace std::placeholders;
 
 BasicInfoItem::BasicInfoItem(Contact &contact)
        : m_Contact     (contact),
-         m_Favorite    (&contact.getFieldById(FieldFavorite)->cast<ContactBoolField>()),
+         m_Favorite    (contact.getFieldById<ContactBoolField>(FieldFavorite)),
 
-         m_Image       (contact.getFieldById(FieldImage)->cast<ContactObject>()),
-         m_ImagePath   (m_Image.getField(0)->cast<ContactTextField>()),
+         m_Image       (*contact.getFieldById<ContactObject>(FieldImage)),
+         m_ImagePath   (*m_Image.getField<ContactTextField>(0)),
 
-         m_Name        (contact.getFieldById(FieldDisplayName)->cast<ContactTextField>()),
-         m_PhoneticName(contact.getFieldById(FieldPhoneticName)->cast<ContactCompoundObject>()),
+         m_Name        (*contact.getFieldById<ContactTextField>(FieldDisplayName)),
+         m_PhoneticName(*contact.getFieldById<ContactCompoundObject>(FieldPhoneticName)),
 
-         m_Company     (contact.getFieldById(FieldCompany)->cast<ContactObject>()),
-         m_CompanyName (m_Company.getFieldById(CompanyFieldName)->cast<ContactTextField>()),
-         m_JobTitle    (m_Company.getFieldById(CompanyFieldJobTitle)->cast<ContactTextField>()),
+         m_Company     (*contact.getFieldById<ContactObject>(FieldCompany)),
+         m_CompanyName (*m_Company.getFieldById<ContactTextField>(CompanyFieldName)),
+         m_JobTitle    (*m_Company.getFieldById<ContactTextField>(CompanyFieldJobTitle)),
 
          m_SelectMode(Ux::SelectNone)
 {
index c400346..597f923 100644 (file)
@@ -24,7 +24,7 @@ using namespace Contacts::Model;
 
 ContactCompoundFieldControl::ContactCompoundFieldControl(Ui::GenlistItem *parent,
                ContactCompoundObject &object)
-       : ContactTextFieldControl(parent, object.getField(0)->cast<ContactTextField>()),
+       : ContactTextFieldControl(parent, *object.getField<ContactTextField>(0)),
          m_Object(object), m_IsCompoundMode(true)
 {
 }
index 9ff2cff..63d1364 100644 (file)
@@ -18,6 +18,7 @@
 #include "Contacts/Input/ContactCompoundFieldItem.h"
 #include "Contacts/Input/ContactCompoundFieldControl.h"
 #include "Contacts/Model/ContactObject.h"
+#include "Contacts/Model/ContactCompoundObject.h"
 
 #include "App/Path.h"
 #include "Utils/Callback.h"
index 3c16ef6..574634a 100644 (file)
@@ -84,9 +84,9 @@ void InputView::addField(Model::ContactFieldId fieldId, const char *value)
        if (field.getInterfaces() & InterfaceCompoundObject) {
                field.cast<ContactCompoundObject>().setValue(value);
        } else {
-               ContactField *subField = field.getField(0);
+               ContactTextField *subField = field.getField<ContactTextField>(0);
                if (subField && subField->getType() == TypeText) {
-                       subField->cast<ContactTextField>().setValue(value);
+                       subField->setValue(value);
                } else {
                        removeField(field);
                        return;
index acda2c2..f4bb5af 100644 (file)
@@ -32,8 +32,8 @@ std::string ContactCompoundObject::getValues(Utils::Range<const unsigned *> fiel
 {
        std::vector<const char *> values;
        for (auto &&fieldId : fieldIds) {
-               auto field = getFieldById(fieldId);
-               const char *value = field->cast<ContactTextField>().getValue();
+               auto field = getFieldById<ContactTextField>(fieldId);
+               const char *value = field->getValue();
                values.push_back(value);
        }
 
@@ -43,9 +43,9 @@ std::string ContactCompoundObject::getValues(Utils::Range<const unsigned *> fiel
 void ContactCompoundObject::setValues(Utils::Range<const char **> values)
 {
        for (size_t i = 0; i < values.count(); ++i) {
-               auto field = getField(i);
+               ContactTextField *field = getField<ContactTextField>(i);
                if (values[i]) {
-                       field->cast<ContactTextField>().setValue(values[i]);
+                       field->setValue(values[i]);
                } else {
                        field->reset();
                }
index e71855b..a381fec 100644 (file)
  */
 
 #include "Contacts/Model/ContactField.h"
-#include "Contacts/Model/ContactArray.h"
-#include "Contacts/Model/ContactBoolField.h"
-#include "Contacts/Model/ContactDateField.h"
-#include "Contacts/Model/ContactEnumField.h"
-#include "Contacts/Model/ContactTypedObject.h"
-#include "Contacts/Model/ContactCompoundObject.h"
+#include "Contacts/Model/ContactFieldContainer.h"
 #include "Contacts/Model/ContactFieldMetadata.h"
 
 using namespace Contacts::Model;
@@ -63,36 +58,6 @@ void ContactField::update(contacts_record_h record)
        }
 }
 
-template <typename FieldType>
-FieldType &ContactField::cast()
-{
-       return static_cast<FieldType &>(*this);
-}
-
-template <typename FieldType>
-const FieldType &ContactField::cast() const
-{
-       return static_cast<const FieldType &>(*this);
-}
-
-template ContactArray &ContactField::cast();
-template ContactBoolField &ContactField::cast();
-template ContactDateField &ContactField::cast();
-template ContactEnumField &ContactField::cast();
-template ContactTextField &ContactField::cast();
-template ContactObject &ContactField::cast();
-template ContactTypedObject &ContactField::cast();
-template ContactCompoundObject &ContactField::cast();
-
-template const ContactArray &ContactField::cast() const;
-template const ContactBoolField &ContactField::cast() const;
-template const ContactDateField &ContactField::cast() const;
-template const ContactEnumField &ContactField::cast() const;
-template const ContactTextField &ContactField::cast() const;
-template const ContactObject &ContactField::cast() const;
-template const ContactTypedObject &ContactField::cast() const;
-template const ContactCompoundObject &ContactField::cast() const;
-
 bool ContactField::isRequired() const
 {
        return m_Metadata.isRequired;
index 2bc56da..a37bffe 100644 (file)
@@ -28,8 +28,8 @@ std::string ContactName::getValue() const
        unsigned fieldIds[] = { NameFieldTitle, NameFieldFirst, NameFieldMiddle, NameFieldLast };
        std::string value = getValues(fieldIds);
 
-       auto suffixField = getFieldById(NameFieldSuffix);
-       const char *suffix = suffixField->cast<ContactTextField>().getValue();
+       auto suffixField = getFieldById<ContactTextField>(NameFieldSuffix);
+       const char *suffix = suffixField->getValue();
        if (suffix) {
                if (!value.empty()) {
                        value += ", ";
index 0af8e0a..c39d5f3 100644 (file)
@@ -17,7 +17,9 @@
 
 #include "Contacts/Model/ContactObject.h"
 #include "Contacts/Model/ContactFieldMetadata.h"
+#include "Common/Database/RecordUtils.h"
 
+using namespace Common::Database;
 using namespace Contacts::Model;
 
 ContactField *ContactObject::getFieldById(unsigned id) const
@@ -38,19 +40,12 @@ unsigned ContactObject::getInterfaces() const
 
 int ContactObject::getRecordId() const
 {
-       return getRecordId(getRecord());
+       return getRecordInt(getRecord(), getObjectMetadata().idPropId);
 }
 
 bool ContactObject::operator==(contacts_record_h record) const
 {
-       return getRecordId() == getRecordId(record);
-}
-
-int ContactObject::getRecordId(contacts_record_h record) const
-{
-       int id = 0;
-       contacts_record_get_int(record, getObjectMetadata().idPropId, &id);
-       return id;
+       return compareRecordsInt(getRecord(), record, getObjectMetadata().idPropId);
 }
 
 const ContactObjectMetadata &ContactObject::getObjectMetadata() const