[haiku-commits] haiku: hrev45912 - src/apps/haiku-depot

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 28 Jul 2013 11:58:16 +0200 (CEST)

hrev45912 adds 3 changesets to branch 'master'
old head: 8add07a8e1f76b3ebb178e9b0d6d20165b341c98
new head: 82bdec56d40be5b37d18e42a74651a79cabd6c10
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=82bdec5+%5E8add07a

----------------------------------------------------------------------------

e9e74b7: List class which stores objects (not pointers) or plain old data.

10ad135: HaikuDepot: Removed unneeded includes.

82bdec5: HaikuDepot: Implementation of model classes for package info 
representation

                                      [ Stephan Aßmus <superstippi@xxxxxx> ]

----------------------------------------------------------------------------

5 files changed, 487 insertions(+), 2 deletions(-)
src/apps/haiku-depot/App.h           |   2 -
src/apps/haiku-depot/Jamfile         |   1 +
src/apps/haiku-depot/List.h          | 196 +++++++++++++++++++++++++++++++
src/apps/haiku-depot/PackageInfo.cpp | 191 ++++++++++++++++++++++++++++++
src/apps/haiku-depot/PackageInfo.h   |  99 ++++++++++++++++

############################################################################

Commit:      e9e74b7bab18f9de5916964ad0c34a7d23c8186c
URL:         http://cgit.haiku-os.org/haiku/commit/?id=e9e74b7
Author:      Stephan Aßmus <superstippi@xxxxxx>
Date:        Sun Jul 28 09:55:13 2013 UTC

List class which stores objects (not pointers) or plain old data.

----------------------------------------------------------------------------

diff --git a/src/apps/haiku-depot/List.h b/src/apps/haiku-depot/List.h
new file mode 100644
index 0000000..be46c2a
--- /dev/null
+++ b/src/apps/haiku-depot/List.h
@@ -0,0 +1,196 @@
+/*
+ * Copyright 2009-2012, Stephan Aßmus <superstippi@xxxxxx>
+ * All rights reserved. Distributed under the terms of the MIT License.
+ */
+#ifndef LIST_H
+#define LIST_H
+
+
+#include <new>
+#include <stdlib.h>
+
+#include <SupportDefs.h>
+
+
+template <typename ItemType, bool PlainOldData, uint32 BlockSize = 8>
+class List {
+       typedef List<ItemType, PlainOldData, BlockSize> SelfType;
+public:
+       List()
+               :
+               fItems(NULL),
+               fCount(0),
+               fAllocatedCount(0)
+       {
+       }
+
+       List(const SelfType& other)
+               :
+               fItems(NULL),
+               fCount(0),
+               fAllocatedCount(0)
+       {
+               *this = other;
+       }
+
+       virtual ~List()
+       {
+               if (!PlainOldData) {
+                       // Make sure to call destructors of old objects.
+                       _Resize(0);
+               }
+               free(fItems);
+       }
+
+       SelfType& operator=(const SelfType& other)
+       {
+               if (this == &other)
+                       return *this;
+
+               if (PlainOldData) {
+                       if (_Resize(other.fCount))
+                               memcpy(fItems, other.fItems, fCount * 
sizeof(ItemType));
+               } else {
+                       // Make sure to call destructors of old objects.
+                       // NOTE: Another option would be to use
+                       // ItemType::operator=(const ItemType& other), but then
+                       // we would need to be carefull which objects are 
already
+                       // initialized. Also the ItemType requires to implement 
the
+                       // operator, while doing it this way requires only a 
copy
+                       // constructor.
+                       _Resize(0);
+                       for (uint32 i = 0; i < other.fCount; i++) {
+                               if (!Add(other.ItemAtFast(i)))
+                                       break;
+                       }
+               }
+               return *this;
+       }
+
+       bool operator==(const SelfType& other) const
+       {
+               if (this == &other)
+                       return true;
+
+               if (fCount != other.fCount)
+                       return false;
+               if (fCount == 0)
+                       return true;
+
+               if (PlainOldData) {
+                       return memcmp(fItems, other.fItems,
+                               fCount * sizeof(ItemType)) == 0;
+               } else {
+                       for (uint32 i = 0; i < other.fCount; i++) {
+                               if (ItemAtFast(i) != other.ItemAtFast(i))
+                                       return false;
+                       }
+               }
+               return true;
+       }
+
+       bool operator!=(const SelfType& other) const
+       {
+               return !(*this == other);
+       }
+
+       inline void Clear()
+       {
+               _Resize(0);
+       }
+
+       inline int32 CountItems() const
+       {
+               return fCount;
+       }
+
+       inline bool Add(const ItemType& copyFrom)
+       {
+               if (_Resize(fCount + 1)) {
+                       ItemType* item = fItems + fCount - 1;
+                       // Initialize the new object from the original.
+                       if (!PlainOldData)
+                               new (item) ItemType(copyFrom);
+                       else
+                               *item = copyFrom;
+                       return true;
+               }
+               return false;
+       }
+
+       inline void Remove()
+       {
+               if (fCount > 0)
+                       _Resize(fCount - 1);
+       }
+       
+       inline void Remove(int32 index)
+       {
+               if (index < 0 || index >= (int32)fCount)
+                       return;
+
+               if (!PlainOldData) {
+                       ItemType* object = fItems + index;
+                       object->~ItemType();
+               }
+
+               int32 nextIndex = index + 1;
+               if ((int32)fCount > nextIndex)
+                       memcpy(fItems + index, fItems + nextIndex,
+                               (fCount - nextIndex) * sizeof(ItemType));
+               
+               fCount--;
+       }
+
+       inline const ItemType& ItemAt(int32 index) const
+       {
+               if (index >= (int32)fCount)
+                       return fNullItem;
+               return ItemAtFast(index);
+       }
+
+       inline const ItemType& ItemAtFast(int32 index) const
+       {
+               return *(fItems + index);
+       }
+
+       inline const ItemType& LastItem() const
+       {
+               return ItemAt((int32)fCount - 1);
+       }
+
+private:
+       inline bool _Resize(uint32 count)
+       {
+               if (count > fAllocatedCount) {
+                       uint32 allocationCount = (count + BlockSize - 1)
+                               / BlockSize * BlockSize;
+                       ItemType* items = reinterpret_cast<ItemType*>(
+                               realloc(fItems, allocationCount * 
sizeof(ItemType)));
+                       if (items == NULL)
+                               return false;
+                       fItems = items;
+
+                       fAllocatedCount = allocationCount;
+               } else if (count < fCount) {
+                       if (!PlainOldData) {
+                               // Uninit old objects so that we can re-use 
them when
+                               // appending objects without the need to 
re-allocate.
+                               for (uint32 i = count; i < fCount; i++) {
+                                       ItemType* object = fItems + i;
+                                       object->~ItemType();
+                               }
+                       }
+               }
+               fCount = count;
+               return true;
+       }
+
+       ItemType*               fItems;
+       ItemType                fNullItem;
+       uint32                  fCount;
+       uint32                  fAllocatedCount;
+};
+
+
+#endif // LIST_H

############################################################################

Commit:      10ad1350c53ce8da71cd96a20f02d094ab809b95
URL:         http://cgit.haiku-os.org/haiku/commit/?id=10ad135
Author:      Stephan Aßmus <superstippi@xxxxxx>
Date:        Sun Jul 28 09:56:06 2013 UTC

HaikuDepot: Removed unneeded includes.

----------------------------------------------------------------------------

diff --git a/src/apps/haiku-depot/App.h b/src/apps/haiku-depot/App.h
index e48e61c..b4ff240 100644
--- a/src/apps/haiku-depot/App.h
+++ b/src/apps/haiku-depot/App.h
@@ -7,8 +7,6 @@
 
 
 #include <Application.h>
-#include <List.h>
-#include <Size.h>
 
 
 class MainWindow;

############################################################################

Revision:    hrev45912
Commit:      82bdec56d40be5b37d18e42a74651a79cabd6c10
URL:         http://cgit.haiku-os.org/haiku/commit/?id=82bdec5
Author:      Stephan Aßmus <superstippi@xxxxxx>
Date:        Sun Jul 28 09:56:45 2013 UTC

HaikuDepot: Implementation of model classes for package info representation

----------------------------------------------------------------------------

diff --git a/src/apps/haiku-depot/Jamfile b/src/apps/haiku-depot/Jamfile
index cb532f3..d9e2907 100644
--- a/src/apps/haiku-depot/Jamfile
+++ b/src/apps/haiku-depot/Jamfile
@@ -8,6 +8,7 @@ Application HaikuDepot :
        main.cpp
        MainWindow.cpp
        PackageActionsView.cpp
+       PackageInfo.cpp
        PackageInfoView.cpp
        PackageListView.cpp
        support.cpp
diff --git a/src/apps/haiku-depot/PackageInfo.cpp 
b/src/apps/haiku-depot/PackageInfo.cpp
new file mode 100644
index 0000000..78a617d
--- /dev/null
+++ b/src/apps/haiku-depot/PackageInfo.cpp
@@ -0,0 +1,191 @@
+/*
+ * Copyright 2013, Stephan Aßmus <superstippi@xxxxxx>.
+ * All rights reserved. Distributed under the terms of the MIT License.
+ */
+
+#include "PackageInfo.h"
+
+#include <stdio.h>
+
+
+// #pragma mark - UserInfo
+
+
+UserInfo::UserInfo()
+       :
+       fNickName()
+{
+}
+
+
+UserInfo::UserInfo(const BString& fNickName)
+       :
+       fNickName(fNickName)
+{
+}
+
+
+UserInfo::UserInfo(const UserInfo& other)
+       :
+       fNickName(other.fNickName)
+{
+}
+
+
+UserInfo&
+UserInfo::operator=(const UserInfo& other)
+{
+       fNickName = other.fNickName;
+       return *this;
+}
+
+
+bool
+UserInfo::operator==(const UserInfo& other) const
+{
+       return fNickName == other.fNickName;
+}
+
+
+bool
+UserInfo::operator!=(const UserInfo& other) const
+{
+       return !(*this == other);
+}
+
+
+// #pragma mark - UserRating
+
+
+UserRating::UserRating()
+       :
+       fUserInfo(),
+       fComment(),
+       fRating(0.0f),
+       fPackageVersion()
+{
+}
+
+
+UserRating::UserRating(const UserInfo& userInfo, const BString& comment,
+               float rating, const BString& packageVersion)
+       :
+       fUserInfo(userInfo),
+       fComment(comment),
+       fRating(rating),
+       fPackageVersion(packageVersion)
+       
+{
+}
+
+
+UserRating::UserRating(const UserRating& other)
+       :
+       fUserInfo(other.fUserInfo),
+       fComment(other.fComment),
+       fRating(other.fRating),
+       fPackageVersion(other.fPackageVersion)
+{
+}
+
+
+UserRating&
+UserRating::operator=(const UserRating& other)
+{
+       fUserInfo = other.fUserInfo;
+       fComment = other.fComment;
+       fRating = other.fRating;
+       fPackageVersion = other.fPackageVersion;
+       return *this;
+}
+
+
+bool
+UserRating::operator==(const UserRating& other) const
+{
+       return fUserInfo == other.fUserInfo
+               && fComment == other.fComment
+               && fRating == other.fRating
+               && fPackageVersion == other.fPackageVersion;
+}
+
+
+bool
+UserRating::operator!=(const UserRating& other) const
+{
+       return !(*this == other);
+}
+
+
+// #pragma mark - PackageInfo
+
+
+PackageInfo::PackageInfo()
+       :
+       fTitle(),
+       fVersion(),
+       fDescription(),
+       fChangelog(),
+       fUserRatings()
+{
+}
+
+
+PackageInfo::PackageInfo(const BString& title, const BString& version,
+               const BString& description, const BString& changelog)
+       :
+       fTitle(title),
+       fVersion(version),
+       fDescription(description),
+       fChangelog(changelog),
+       fUserRatings()
+{
+}
+
+
+PackageInfo::PackageInfo(const PackageInfo& other)
+       :
+       fTitle(other.fTitle),
+       fVersion(other.fVersion),
+       fDescription(other.fDescription),
+       fChangelog(other.fChangelog),
+       fUserRatings(other.fUserRatings)
+{
+}
+
+
+PackageInfo&
+PackageInfo::operator=(const PackageInfo& other)
+{
+       fTitle = other.fTitle;
+       fVersion = other.fVersion;
+       fDescription = other.fDescription;
+       fChangelog = other.fChangelog;
+       fUserRatings = other.fUserRatings;
+       return *this;
+}
+
+
+bool
+PackageInfo::operator==(const PackageInfo& other) const
+{
+       return fTitle == other.fTitle
+               && fVersion == other.fVersion
+               && fDescription == other.fDescription
+               && fChangelog == other.fChangelog
+               && fUserRatings == other.fUserRatings;
+}
+
+
+bool
+PackageInfo::operator!=(const PackageInfo& other) const
+{
+       return !(*this == other);
+}
+
+
+bool
+PackageInfo::AddUserRating(const UserRating& rating)
+{
+       return fUserRatings.Add(rating);
+}
diff --git a/src/apps/haiku-depot/PackageInfo.h 
b/src/apps/haiku-depot/PackageInfo.h
new file mode 100644
index 0000000..24d4c8e
--- /dev/null
+++ b/src/apps/haiku-depot/PackageInfo.h
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2013, Stephan Aßmus <superstippi@xxxxxx>.
+ * All rights reserved. Distributed under the terms of the MIT License.
+ */
+#ifndef PACKAGE_INFO_H
+#define PACKAGE_INFO_H
+
+
+#include <String.h>
+
+#include "List.h"
+
+
+class UserInfo {
+public:
+                                                               UserInfo();
+                                                               UserInfo(const 
BString& nickName);
+                                                               UserInfo(const 
UserInfo& other);
+
+                       UserInfo&                       operator=(const 
UserInfo& other);
+                       bool                            operator==(const 
UserInfo& other) const;
+                       bool                            operator!=(const 
UserInfo& other) const;
+
+                       const BString&          NickName() const;
+
+private:
+                       BString                         fNickName;
+};
+
+
+class UserRating {
+public:
+                                                               UserRating();
+                                                               
UserRating(const UserInfo& userInfo,
+                                                                       const 
BString& comment, float rating,
+                                                                       const 
BString& packageVersion);
+                                                               
UserRating(const UserRating& other);
+
+                       UserRating&                     operator=(const 
UserRating& other);
+                       bool                            operator==(const 
UserRating& other) const;
+                       bool                            operator!=(const 
UserRating& other) const;
+
+                       const UserInfo&         User() const
+                                                                       { 
return fUserInfo; }
+                       const BString&          Comment() const
+                                                                       { 
return fComment; }
+                       const float                     Rating() const
+                                                                       { 
return fRating; }
+                       const BString&          PackageVersion() const
+                                                                       { 
return fPackageVersion; }
+
+private:
+                       UserInfo                        fUserInfo;
+                       BString                         fComment;
+                       float                           fRating;
+                       BString                         fPackageVersion;
+};
+
+
+typedef List<UserRating, false> UserRatingList;
+
+
+class PackageInfo {
+public:
+                                                               PackageInfo();
+                                                               
PackageInfo(const BString& title,
+                                                                       const 
BString& version,
+                                                                       const 
BString& description,
+                                                                       const 
BString& changelog);
+                                                               
PackageInfo(const PackageInfo& other);
+
+                       PackageInfo&            operator=(const PackageInfo& 
other);
+                       bool                            operator==(const 
PackageInfo& other) const;
+                       bool                            operator!=(const 
PackageInfo& other) const;
+
+                       const BString&          Title() const
+                                                                       { 
return fTitle; }
+                       const BString&          Version() const
+                                                                       { 
return fVersion; }
+                       const BString&          Description() const
+                                                                       { 
return fDescription; }
+                       const BString&          Changelog() const
+                                                                       { 
return fChangelog; }
+
+                       bool                            AddUserRating(const 
UserRating& rating);
+
+private:
+                       BString                         fTitle;
+                       BString                         fVersion;
+                       BString                         fDescription;
+                       BString                         fChangelog;
+                       UserRatingList          fUserRatings;
+};
+
+
+typedef List<PackageInfo, false> PackageInfoList;
+
+
+#endif // PACKAGE_INFO_H


Other related posts: