From 2021c9842e1e61a3bf0f6550725ec3baf53d44b1 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 16 Jul 2011 16:36:36 +0200 Subject: [PATCH] Use BStringList in package kit Replace all instances of BObjectList by BStringList. --- headers/os/package/PackageInfo.h | 21 +++--- headers/os/package/PackageRoster.h | 4 +- headers/os/package/RepositoryInfo.h | 10 +-- src/bin/package_repo/command_list.cpp | 6 +- src/bin/pkgman/command_list_repos.cpp | 6 +- src/bin/pkgman/command_refresh.cpp | 12 ++-- src/kits/package/PackageInfo.cpp | 65 +++++++------------ src/kits/package/PackageRoster.cpp | 14 ++-- src/kits/package/RepositoryInfo.cpp | 27 +++----- src/kits/package/hpkg/PackageWriterImpl.cpp | 6 +- .../package/hpkg/RepositoryWriterImpl.cpp | 9 ++- src/kits/package/hpkg/WriterImplBase.cpp | 34 +++++----- 12 files changed, 89 insertions(+), 125 deletions(-) diff --git a/headers/os/package/PackageInfo.h b/headers/os/package/PackageInfo.h index e62136dd9d..9554a209f9 100644 --- a/headers/os/package/PackageInfo.h +++ b/headers/os/package/PackageInfo.h @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -68,10 +69,10 @@ public: const BPackageVersion& Version() const; - const BObjectList& CopyrightList() const; - const BObjectList& LicenseList() const; - const BObjectList& URLList() const; - const BObjectList& SourceURLList() const; + const BStringList& CopyrightList() const; + const BStringList& LicenseList() const; + const BStringList& URLList() const; + const BStringList& SourceURLList() const; const BObjectList& ProvidesList() const; const BObjectList& @@ -82,7 +83,7 @@ public: ConflictsList() const; const BObjectList& FreshensList() const; - const BObjectList& ReplacesList() const; + const BStringList& ReplacesList() const; void SetName(const BString& name); void SetSummary(const BString& summary); @@ -159,10 +160,10 @@ private: BPackageVersion fVersion; - BObjectList fCopyrightList; - BObjectList fLicenseList; - BObjectList fURLList; - BObjectList fSourceURLList; + BStringList fCopyrightList; + BStringList fLicenseList; + BStringList fURLList; + BStringList fSourceURLList; BObjectList fProvidesList; @@ -173,7 +174,7 @@ private: BObjectList fFreshensList; - BObjectList fReplacesList; + BStringList fReplacesList; BString fChecksum; BString fInstallPath; diff --git a/headers/os/package/PackageRoster.h b/headers/os/package/PackageRoster.h index 1bb452468e..9178b50cf9 100644 --- a/headers/os/package/PackageRoster.h +++ b/headers/os/package/PackageRoster.h @@ -11,7 +11,7 @@ #include -template class BObjectList; +class BStringList; namespace BPackageKit { @@ -45,7 +45,7 @@ public: status_t GetUserRepositoryConfigPath(BPath* path, bool create = false) const; - status_t GetRepositoryNames(BObjectList& names); + status_t GetRepositoryNames(BStringList& names); status_t VisitCommonRepositoryConfigs( BRepositoryConfigVisitor& visitor); diff --git a/headers/os/package/RepositoryInfo.h b/headers/os/package/RepositoryInfo.h index f84a815ff4..b74f01780b 100644 --- a/headers/os/package/RepositoryInfo.h +++ b/headers/os/package/RepositoryInfo.h @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include @@ -38,8 +38,8 @@ public: const BString& Summary() const; uint8 Priority() const; BPackageArchitecture Architecture() const; - const BObjectList& LicenseNames() const; - const BObjectList& LicenseTexts() const; + const BStringList& LicenseNames() const; + const BStringList& LicenseTexts() const; void SetName(const BString& name); void SetOriginalBaseURL(const BString& url); @@ -75,8 +75,8 @@ private: BString fSummary; uint8 fPriority; BPackageArchitecture fArchitecture; - BObjectList fLicenseNames; - BObjectList fLicenseTexts; + BStringList fLicenseNames; + BStringList fLicenseTexts; }; diff --git a/src/bin/package_repo/command_list.cpp b/src/bin/package_repo/command_list.cpp index c1ff03b683..0745b59fe2 100644 --- a/src/bin/package_repo/command_list.cpp +++ b/src/bin/package_repo/command_list.cpp @@ -214,11 +214,11 @@ struct RepositoryContentListHandler : BRepositoryContentHandler { printf("\tpriority: %u\n", repositoryInfo.Priority()); printf("\tarchitecture: %s\n", BPackageInfo::kArchitectureNames[repositoryInfo.Architecture()]); - const BObjectList licenseNames = repositoryInfo.LicenseNames(); + const BStringList licenseNames = repositoryInfo.LicenseNames(); if (!licenseNames.IsEmpty()) { printf("\tlicenses:\n"); - for (int i = 0; i < licenseNames.CountItems(); ++i) - printf("\t\t%s\n", licenseNames.ItemAt(i)->String()); + for (int i = 0; i < licenseNames.CountStrings(); ++i) + printf("\t\t%s\n", licenseNames.StringAt(i).String()); } return B_OK; diff --git a/src/bin/pkgman/command_list_repos.cpp b/src/bin/pkgman/command_list_repos.cpp index 7df6012571..244404dca2 100644 --- a/src/bin/pkgman/command_list_repos.cpp +++ b/src/bin/pkgman/command_list_repos.cpp @@ -82,14 +82,14 @@ command_list_repos(int argc, const char* const* argv) if (argc != optind) print_command_usage_and_exit(true); - BObjectList repositoryNames(20, true); + BStringList repositoryNames(20); BPackageRoster roster; status_t result = roster.GetRepositoryNames(repositoryNames); if (result != B_OK) DIE(result, "can't collect repository names"); - for (int i = 0; i < repositoryNames.CountItems(); ++i) { - const BString& repoName = *(repositoryNames.ItemAt(i)); + for (int i = 0; i < repositoryNames.CountStrings(); ++i) { + const BString& repoName = repositoryNames.StringAt(i); BRepositoryConfig repoConfig; result = roster.GetRepositoryConfig(repoName, &repoConfig); if (result != B_OK) { diff --git a/src/bin/pkgman/command_refresh.cpp b/src/bin/pkgman/command_refresh.cpp index 7118fa9f8d..176f5d2878 100644 --- a/src/bin/pkgman/command_refresh.cpp +++ b/src/bin/pkgman/command_refresh.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include @@ -74,7 +74,7 @@ command_refresh(int argc, const char* const* argv) JobStateListener listener; BContext context(decisionProvider, listener); - BObjectList repositoryNames(20, true); + BStringList repositoryNames(20); BPackageRoster roster; if (nameCount == 0) { @@ -83,16 +83,14 @@ command_refresh(int argc, const char* const* argv) DIE(result, "can't collect repository names"); } else { for (int i = 0; i < nameCount; ++i) { - BString* repoName = new (std::nothrow) BString(repoArgs[i]); - if (repoName == NULL) + if (!repositoryNames.Add(repoArgs[i])) DIE(B_NO_MEMORY, "can't allocate repository name"); - repositoryNames.AddItem(repoName); } } status_t result; - for (int i = 0; i < repositoryNames.CountItems(); ++i) { - const BString& repoName = *(repositoryNames.ItemAt(i)); + for (int i = 0; i < repositoryNames.CountStrings(); ++i) { + const BString& repoName = repositoryNames.StringAt(i); BRepositoryConfig repoConfig; result = roster.GetRepositoryConfig(repoName, &repoConfig); if (result != B_OK) { diff --git a/src/kits/package/PackageInfo.cpp b/src/kits/package/PackageInfo.cpp index 024a411fd8..f24bd9201f 100644 --- a/src/kits/package/PackageInfo.cpp +++ b/src/kits/package/PackageInfo.cpp @@ -81,7 +81,7 @@ private: bool releaseIsOptional); void _ParseList(ListElementParser& elementParser, bool allowSingleNonListElement); - void _ParseStringList(BObjectList* value, + void _ParseStringList(BStringList* value, bool allowQuotedStrings = true, bool convertToLowerCase = false); void _ParseResolvableList( @@ -449,15 +449,15 @@ BPackageInfo::Parser::_ParseList(ListElementParser& elementParser, void -BPackageInfo::Parser::_ParseStringList(BObjectList* value, +BPackageInfo::Parser::_ParseStringList(BStringList* value, bool allowQuotedStrings, bool convertToLowerCase) { struct StringParser : public ListElementParser { - BObjectList* value; + BStringList* value; bool allowQuotedStrings; bool convertToLowerCase; - StringParser(BObjectList* value, bool allowQuotedStrings, + StringParser(BStringList* value, bool allowQuotedStrings, bool convertToLowerCase) : value(value), @@ -479,11 +479,11 @@ BPackageInfo::Parser::_ParseStringList(BObjectList* value, throw ParseError("expected word", token.pos); } - BString* element = new BString(token.text); + BString element(token.text); if (convertToLowerCase) - element->ToLower(); + element.ToLower(); - value->AddItem(element); + value->Add(element); } } stringParser(value, allowQuotedStrings, convertToLowerCase); @@ -831,16 +831,16 @@ BPackageInfo::BPackageInfo() : fFlags(0), fArchitecture(B_PACKAGE_ARCHITECTURE_ENUM_COUNT), - fCopyrightList(5, true), - fLicenseList(5, true), - fURLList(5, true), - fSourceURLList(5, true), + fCopyrightList(5), + fLicenseList(5), + fURLList(5), + fSourceURLList(5), fProvidesList(20, true), fRequiresList(20, true), fSupplementsList(20, true), fConflictsList(5, true), fFreshensList(5, true), - fReplacesList(5, true) + fReplacesList(5) { } @@ -989,28 +989,28 @@ BPackageInfo::Version() const } -const BObjectList& +const BStringList& BPackageInfo::CopyrightList() const { return fCopyrightList; } -const BObjectList& +const BStringList& BPackageInfo::LicenseList() const { return fLicenseList; } -const BObjectList& +const BStringList& BPackageInfo::URLList() const { return fURLList; } -const BObjectList& +const BStringList& BPackageInfo::SourceURLList() const { return fSourceURLList; @@ -1052,7 +1052,7 @@ BPackageInfo::FreshensList() const } -const BObjectList& +const BStringList& BPackageInfo::ReplacesList() const { return fReplacesList; @@ -1140,11 +1140,7 @@ BPackageInfo::ClearCopyrightList() status_t BPackageInfo::AddCopyright(const BString& copyright) { - BString* newCopyright = new (std::nothrow) BString(copyright); - if (newCopyright == NULL) - return B_NO_MEMORY; - - return fCopyrightList.AddItem(newCopyright) ? B_OK : B_ERROR; + return fCopyrightList.Add(copyright) ? B_OK : B_ERROR; } @@ -1158,11 +1154,7 @@ BPackageInfo::ClearLicenseList() status_t BPackageInfo::AddLicense(const BString& license) { - BString* newLicense = new (std::nothrow) BString(license); - if (newLicense == NULL) - return B_NO_MEMORY; - - return fLicenseList.AddItem(newLicense) ? B_OK : B_ERROR; + return fLicenseList.Add(license) ? B_OK : B_ERROR; } @@ -1176,11 +1168,7 @@ BPackageInfo::ClearURLList() status_t BPackageInfo::AddURL(const BString& url) { - BString* newURL = new (std::nothrow) BString(url); - if (newURL == NULL) - return B_NO_MEMORY; - - return fURLList.AddItem(newURL) ? B_OK : B_NO_MEMORY; + return fURLList.Add(url) ? B_OK : B_NO_MEMORY; } @@ -1194,11 +1182,7 @@ BPackageInfo::ClearSourceURLList() status_t BPackageInfo::AddSourceURL(const BString& url) { - BString* newURL = new (std::nothrow) BString(url); - if (newURL == NULL) - return B_NO_MEMORY; - - return fSourceURLList.AddItem(newURL) ? B_OK : B_NO_MEMORY; + return fSourceURLList.Add(url) ? B_OK : B_NO_MEMORY; } @@ -1307,12 +1291,7 @@ BPackageInfo::ClearReplacesList() status_t BPackageInfo::AddReplaces(const BString& replaces) { - BString* newReplaces = new (std::nothrow) BString(replaces); - if (newReplaces == NULL) - return B_NO_MEMORY; - - newReplaces->ToLower(); - return fReplacesList.AddItem(newReplaces) ? B_OK : B_ERROR; + return fReplacesList.Add(BString(replaces).ToLower()) ? B_OK : B_ERROR; } diff --git a/src/kits/package/PackageRoster.cpp b/src/kits/package/PackageRoster.cpp index ce6edc9fc9..0fb31b535f 100644 --- a/src/kits/package/PackageRoster.cpp +++ b/src/kits/package/PackageRoster.cpp @@ -14,9 +14,9 @@ #include #include -#include #include #include +#include #include #include @@ -89,10 +89,10 @@ BPackageRoster::VisitUserRepositoryConfigs(BRepositoryConfigVisitor& visitor) status_t -BPackageRoster::GetRepositoryNames(BObjectList& names) +BPackageRoster::GetRepositoryNames(BStringList& names) { struct RepositoryNameCollector : public BRepositoryConfigVisitor { - RepositoryNameCollector(BObjectList& _names) + RepositoryNameCollector(BStringList& _names) : names(_names) { } @@ -102,15 +102,15 @@ BPackageRoster::GetRepositoryNames(BObjectList& names) status_t result = entry.GetName(name); if (result != B_OK) return result; - int32 count = names.CountItems(); + int32 count = names.CountStrings(); for (int i = 0; i < count; ++i) { - if (names.ItemAt(i)->Compare(name) == 0) + if (names.StringAt(i).Compare(name) == 0) return B_OK; } - names.AddItem(new (std::nothrow) BString(name)); + names.Add(name); return B_OK; } - BObjectList& names; + BStringList& names; }; RepositoryNameCollector repositoryNameCollector(names); status_t result = VisitUserRepositoryConfigs(repositoryNameCollector); diff --git a/src/kits/package/RepositoryInfo.cpp b/src/kits/package/RepositoryInfo.cpp index 94065c0016..1ef4d40c4a 100644 --- a/src/kits/package/RepositoryInfo.cpp +++ b/src/kits/package/RepositoryInfo.cpp @@ -47,7 +47,7 @@ BRepositoryInfo::BRepositoryInfo() BRepositoryInfo::BRepositoryInfo(BMessage* data) : inherited(data), - fLicenseTexts(5, true) + fLicenseTexts(5) { fInitStatus = SetTo(data); } @@ -94,13 +94,13 @@ BRepositoryInfo::Archive(BMessage* data, bool deep) const return result; if ((result = data->AddUInt8(kArchitectureField, fArchitecture)) != B_OK) return result; - for (int i = 0; i < fLicenseNames.CountItems(); ++i) { - result = data->AddString(kLicenseNameField, *fLicenseNames.ItemAt(i)); + for (int i = 0; i < fLicenseNames.CountStrings(); ++i) { + result = data->AddString(kLicenseNameField, fLicenseNames.StringAt(i)); if (result != B_OK) return result; } - for (int i = 0; i < fLicenseTexts.CountItems(); ++i) { - result = data->AddString(kLicenseTextField, *fLicenseTexts.ItemAt(i)); + for (int i = 0; i < fLicenseTexts.CountStrings(); ++i) { + result = data->AddString(kLicenseTextField, fLicenseTexts.StringAt(i)); if (result != B_OK) return result; } @@ -146,11 +146,7 @@ BRepositoryInfo::SetTo(const BMessage* data) data->FindString(kLicenseNameField, i, &licenseName) == B_OK && data->FindString(kLicenseTextField, i, &licenseText) == B_OK; ++i) { - BString* newLicenseName = new (std::nothrow) BString(licenseName); - if (newLicenseName == NULL || !fLicenseNames.AddItem(newLicenseName)) - return B_NO_MEMORY; - BString* newLicenseText = new (std::nothrow) BString(licenseText); - if (newLicenseText == NULL || !fLicenseTexts.AddItem(newLicenseText)) + if (!fLicenseNames.Add(licenseName) || !fLicenseTexts.Add(licenseText)) return B_NO_MEMORY; } @@ -269,14 +265,14 @@ BRepositoryInfo::Architecture() const } -const BObjectList& +const BStringList& BRepositoryInfo::LicenseNames() const { return fLicenseNames; } -const BObjectList& +const BStringList& BRepositoryInfo::LicenseTexts() const { return fLicenseTexts; @@ -329,12 +325,7 @@ status_t BRepositoryInfo::AddLicense(const BString& licenseName, const BString& licenseText) { - BString* newLicenseName = new (std::nothrow) BString(licenseName); - if (newLicenseName == NULL || !fLicenseNames.AddItem(newLicenseName)) - return B_NO_MEMORY; - - BString* newLicenseText = new (std::nothrow) BString(licenseText); - if (newLicenseText == NULL || !fLicenseTexts.AddItem(newLicenseText)) + if (!fLicenseNames.Add(licenseName) || !fLicenseTexts.Add(licenseText)) return B_NO_MEMORY; return B_OK; diff --git a/src/kits/package/hpkg/PackageWriterImpl.cpp b/src/kits/package/hpkg/PackageWriterImpl.cpp index 06710867a3..b838e18ff7 100644 --- a/src/kits/package/hpkg/PackageWriterImpl.cpp +++ b/src/kits/package/hpkg/PackageWriterImpl.cpp @@ -681,9 +681,9 @@ PackageWriterImpl::_CheckLicenses() BDirectory systemLicenseDir(systemLicensePath.Path()); - const BObjectList& licenseList = fPackageInfo.LicenseList(); - for (int i = 0; i < licenseList.CountItems(); ++i) { - const BString& licenseName = *licenseList.ItemAt(i); + const BStringList& licenseList = fPackageInfo.LicenseList(); + for (int i = 0; i < licenseList.CountStrings(); ++i) { + const BString& licenseName = licenseList.StringAt(i); if (licenseName == kPublicDomainLicenseName) continue; diff --git a/src/kits/package/hpkg/RepositoryWriterImpl.cpp b/src/kits/package/hpkg/RepositoryWriterImpl.cpp index 7e9ba2499c..f6e28e7d7f 100644 --- a/src/kits/package/hpkg/RepositoryWriterImpl.cpp +++ b/src/kits/package/hpkg/RepositoryWriterImpl.cpp @@ -119,10 +119,9 @@ struct PackageContentHandler : public BPackageContentHandler { return B_OK; // check if license already is in repository - const BObjectList& licenseNames - = fRepositoryInfo->LicenseNames(); - for (int i = 0; i < licenseNames.CountItems(); ++i) { - if (licenseNames.ItemAt(i)->ICompare(entry->Name()) == 0) { + const BStringList& licenseNames = fRepositoryInfo->LicenseNames(); + for (int i = 0; i < licenseNames.CountStrings(); ++i) { + if (licenseNames.StringAt(i).ICompare(entry->Name()) == 0) { // license already exists return B_OK; } @@ -365,7 +364,7 @@ RepositoryWriterImpl::_Finish() sizeof(header) + infoLengthCompressed, packagesLengthCompressed); fListener->OnRepositoryDone(sizeof(header), infoLengthCompressed, - fRepositoryInfo->LicenseNames().CountItems(), fPackageCount, + fRepositoryInfo->LicenseNames().CountStrings(), fPackageCount, packagesLengthCompressed, totalSize); // general diff --git a/src/kits/package/hpkg/WriterImplBase.cpp b/src/kits/package/hpkg/WriterImplBase.cpp index e308190f8c..b5b01840a7 100644 --- a/src/kits/package/hpkg/WriterImplBase.cpp +++ b/src/kits/package/hpkg/WriterImplBase.cpp @@ -417,46 +417,43 @@ WriterImplBase::RegisterPackageInfo(PackageAttributeList& attributeList, RegisterPackageVersion(attributeList, packageInfo.Version()); // copyright list - const BObjectList& copyrightList = packageInfo.CopyrightList(); - for (int i = 0; i < copyrightList.CountItems(); ++i) { + const BStringList& copyrightList = packageInfo.CopyrightList(); + for (int i = 0; i < copyrightList.CountStrings(); ++i) { PackageAttribute* copyright = new PackageAttribute( B_HPKG_ATTRIBUTE_ID_PACKAGE_COPYRIGHT, B_HPKG_ATTRIBUTE_TYPE_STRING, B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE); - copyright->string - = fPackageStringCache.Get(copyrightList.ItemAt(i)->String()); + copyright->string = fPackageStringCache.Get(copyrightList.StringAt(i)); attributeList.Add(copyright); } // license list - const BObjectList& licenseList = packageInfo.LicenseList(); - for (int i = 0; i < licenseList.CountItems(); ++i) { + const BStringList& licenseList = packageInfo.LicenseList(); + for (int i = 0; i < licenseList.CountStrings(); ++i) { PackageAttribute* license = new PackageAttribute( B_HPKG_ATTRIBUTE_ID_PACKAGE_LICENSE, B_HPKG_ATTRIBUTE_TYPE_STRING, B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE); - license->string - = fPackageStringCache.Get(licenseList.ItemAt(i)->String()); + license->string = fPackageStringCache.Get(licenseList.StringAt(i)); attributeList.Add(license); } // URL list - const BObjectList& urlList = packageInfo.URLList(); - for (int i = 0; i < urlList.CountItems(); ++i) { + const BStringList& urlList = packageInfo.URLList(); + for (int i = 0; i < urlList.CountStrings(); ++i) { PackageAttribute* url = new PackageAttribute( B_HPKG_ATTRIBUTE_ID_PACKAGE_URL, B_HPKG_ATTRIBUTE_TYPE_STRING, B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE); - url->string = fPackageStringCache.Get(urlList.ItemAt(i)->String()); + url->string = fPackageStringCache.Get(urlList.StringAt(i)); attributeList.Add(url); } // source URL list - const BObjectList& sourceURLList = packageInfo.SourceURLList(); - for (int i = 0; i < sourceURLList.CountItems(); ++i) { + const BStringList& sourceURLList = packageInfo.SourceURLList(); + for (int i = 0; i < sourceURLList.CountStrings(); ++i) { PackageAttribute* url = new PackageAttribute( B_HPKG_ATTRIBUTE_ID_PACKAGE_SOURCE_URL, B_HPKG_ATTRIBUTE_TYPE_STRING, B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE); - url->string = fPackageStringCache.Get( - sourceURLList.ItemAt(i)->String()); + url->string = fPackageStringCache.Get(sourceURLList.StringAt(i)); attributeList.Add(url); } @@ -508,13 +505,12 @@ WriterImplBase::RegisterPackageInfo(PackageAttributeList& attributeList, packageInfo.FreshensList(), B_HPKG_ATTRIBUTE_ID_PACKAGE_FRESHENS); // replaces list - const BObjectList& replacesList = packageInfo.ReplacesList(); - for (int i = 0; i < replacesList.CountItems(); ++i) { + const BStringList& replacesList = packageInfo.ReplacesList(); + for (int i = 0; i < replacesList.CountStrings(); ++i) { PackageAttribute* replaces = new PackageAttribute( B_HPKG_ATTRIBUTE_ID_PACKAGE_REPLACES, B_HPKG_ATTRIBUTE_TYPE_STRING, B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE); - replaces->string - = fPackageStringCache.Get(replacesList.ItemAt(i)->String()); + replaces->string = fPackageStringCache.Get(replacesList.StringAt(i)); attributeList.Add(replaces); }