Use BStringList in package kit

Replace all instances of BObjectList<BString> by BStringList.
This commit is contained in:
Ingo Weinhold 2011-07-16 16:36:36 +02:00
parent 7de6af25e9
commit 9968845d69
12 changed files with 89 additions and 125 deletions

View File

@ -8,6 +8,7 @@
#include <ObjectList.h>
#include <String.h>
#include <StringList.h>
#include <package/PackageArchitecture.h>
#include <package/PackageFlags.h>
@ -68,10 +69,10 @@ public:
const BPackageVersion& Version() const;
const BObjectList<BString>& CopyrightList() const;
const BObjectList<BString>& LicenseList() const;
const BObjectList<BString>& URLList() const;
const BObjectList<BString>& SourceURLList() const;
const BStringList& CopyrightList() const;
const BStringList& LicenseList() const;
const BStringList& URLList() const;
const BStringList& SourceURLList() const;
const BObjectList<BPackageResolvable>& ProvidesList() const;
const BObjectList<BPackageResolvableExpression>&
@ -82,7 +83,7 @@ public:
ConflictsList() const;
const BObjectList<BPackageResolvableExpression>&
FreshensList() const;
const BObjectList<BString>& ReplacesList() const;
const BStringList& ReplacesList() const;
void SetName(const BString& name);
void SetSummary(const BString& summary);
@ -159,10 +160,10 @@ private:
BPackageVersion fVersion;
BObjectList<BString> fCopyrightList;
BObjectList<BString> fLicenseList;
BObjectList<BString> fURLList;
BObjectList<BString> fSourceURLList;
BStringList fCopyrightList;
BStringList fLicenseList;
BStringList fURLList;
BStringList fSourceURLList;
BObjectList<BPackageResolvable> fProvidesList;
@ -173,7 +174,7 @@ private:
BObjectList<BPackageResolvableExpression> fFreshensList;
BObjectList<BString> fReplacesList;
BStringList fReplacesList;
BString fChecksum;
BString fInstallPath;

View File

@ -11,7 +11,7 @@
#include <Path.h>
template <class T> class BObjectList;
class BStringList;
namespace BPackageKit {
@ -45,7 +45,7 @@ public:
status_t GetUserRepositoryConfigPath(BPath* path,
bool create = false) const;
status_t GetRepositoryNames(BObjectList<BString>& names);
status_t GetRepositoryNames(BStringList& names);
status_t VisitCommonRepositoryConfigs(
BRepositoryConfigVisitor& visitor);

View File

@ -8,7 +8,7 @@
#include <Archivable.h>
#include <Entry.h>
#include <ObjectList.h>
#include <StringList.h>
#include <String.h>
#include <package/PackageArchitecture.h>
@ -38,8 +38,8 @@ public:
const BString& Summary() const;
uint8 Priority() const;
BPackageArchitecture Architecture() const;
const BObjectList<BString>& LicenseNames() const;
const BObjectList<BString>& 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<BString> fLicenseNames;
BObjectList<BString> fLicenseTexts;
BStringList fLicenseNames;
BStringList fLicenseTexts;
};

View File

@ -214,11 +214,11 @@ struct RepositoryContentListHandler : BRepositoryContentHandler {
printf("\tpriority: %u\n", repositoryInfo.Priority());
printf("\tarchitecture: %s\n",
BPackageInfo::kArchitectureNames[repositoryInfo.Architecture()]);
const BObjectList<BString> 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;

View File

@ -82,14 +82,14 @@ command_list_repos(int argc, const char* const* argv)
if (argc != optind)
print_command_usage_and_exit(true);
BObjectList<BString> 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) {

View File

@ -9,7 +9,7 @@
#include <stdlib.h>
#include <Errors.h>
#include <SupportDefs.h>
#include <StringList.h>
#include <package/Context.h>
#include <package/RefreshRepositoryRequest.h>
@ -74,7 +74,7 @@ command_refresh(int argc, const char* const* argv)
JobStateListener listener;
BContext context(decisionProvider, listener);
BObjectList<BString> 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) {

View File

@ -81,7 +81,7 @@ private:
bool releaseIsOptional);
void _ParseList(ListElementParser& elementParser,
bool allowSingleNonListElement);
void _ParseStringList(BObjectList<BString>* 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<BString>* value,
BPackageInfo::Parser::_ParseStringList(BStringList* value,
bool allowQuotedStrings, bool convertToLowerCase)
{
struct StringParser : public ListElementParser {
BObjectList<BString>* value;
BStringList* value;
bool allowQuotedStrings;
bool convertToLowerCase;
StringParser(BObjectList<BString>* value, bool allowQuotedStrings,
StringParser(BStringList* value, bool allowQuotedStrings,
bool convertToLowerCase)
:
value(value),
@ -479,11 +479,11 @@ BPackageInfo::Parser::_ParseStringList(BObjectList<BString>* 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<BString>&
const BStringList&
BPackageInfo::CopyrightList() const
{
return fCopyrightList;
}
const BObjectList<BString>&
const BStringList&
BPackageInfo::LicenseList() const
{
return fLicenseList;
}
const BObjectList<BString>&
const BStringList&
BPackageInfo::URLList() const
{
return fURLList;
}
const BObjectList<BString>&
const BStringList&
BPackageInfo::SourceURLList() const
{
return fSourceURLList;
@ -1052,7 +1052,7 @@ BPackageInfo::FreshensList() const
}
const BObjectList<BString>&
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;
}

View File

@ -14,9 +14,9 @@
#include <Directory.h>
#include <Entry.h>
#include <ObjectList.h>
#include <Path.h>
#include <String.h>
#include <StringList.h>
#include <package/RepositoryCache.h>
#include <package/RepositoryConfig.h>
@ -89,10 +89,10 @@ BPackageRoster::VisitUserRepositoryConfigs(BRepositoryConfigVisitor& visitor)
status_t
BPackageRoster::GetRepositoryNames(BObjectList<BString>& names)
BPackageRoster::GetRepositoryNames(BStringList& names)
{
struct RepositoryNameCollector : public BRepositoryConfigVisitor {
RepositoryNameCollector(BObjectList<BString>& _names)
RepositoryNameCollector(BStringList& _names)
: names(_names)
{
}
@ -102,15 +102,15 @@ BPackageRoster::GetRepositoryNames(BObjectList<BString>& 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<BString>& names;
BStringList& names;
};
RepositoryNameCollector repositoryNameCollector(names);
status_t result = VisitUserRepositoryConfigs(repositoryNameCollector);

View File

@ -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<BString>&
const BStringList&
BRepositoryInfo::LicenseNames() const
{
return fLicenseNames;
}
const BObjectList<BString>&
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;

View File

@ -681,9 +681,9 @@ PackageWriterImpl::_CheckLicenses()
BDirectory systemLicenseDir(systemLicensePath.Path());
const BObjectList<BString>& 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;

View File

@ -119,10 +119,9 @@ struct PackageContentHandler : public BPackageContentHandler {
return B_OK;
// check if license already is in repository
const BObjectList<BString>& 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

View File

@ -417,46 +417,43 @@ WriterImplBase::RegisterPackageInfo(PackageAttributeList& attributeList,
RegisterPackageVersion(attributeList, packageInfo.Version());
// copyright list
const BObjectList<BString>& 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<BString>& 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<BString>& 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<BString>& 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<BString>& 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);
}