btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / servers / package / VolumeState.cpp
blob2d3cc69f8cec172d958474bdd7580ee15958d36f
1 /*
2 * Copyright 2013-2014, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
7 */
10 #include "VolumeState.h"
12 #include <AutoDeleter.h>
13 #include <AutoLocker.h>
16 VolumeState::VolumeState()
18 fPackagesByFileName(),
19 fPackagesByNodeRef()
24 VolumeState::~VolumeState()
26 fPackagesByFileName.Clear();
28 Package* package = fPackagesByNodeRef.Clear(true);
29 while (package != NULL) {
30 Package* next = package->NodeRefHashTableNext();
31 delete package;
32 package = next;
37 bool
38 VolumeState::Init()
40 return fPackagesByFileName.Init() == B_OK
41 && fPackagesByNodeRef.Init() == B_OK;
45 void
46 VolumeState::AddPackage(Package* package)
48 fPackagesByFileName.Insert(package);
49 fPackagesByNodeRef.Insert(package);
53 void
54 VolumeState::RemovePackage(Package* package)
56 fPackagesByFileName.Remove(package);
57 fPackagesByNodeRef.Remove(package);
61 void
62 VolumeState::SetPackageActive(Package* package, bool active)
64 package->SetActive(active);
68 void
69 VolumeState::ActivationChanged(const PackageSet& activatedPackage,
70 const PackageSet& deactivatePackages)
72 for (PackageSet::iterator it = activatedPackage.begin();
73 it != activatedPackage.end(); ++it) {
74 (*it)->SetActive(true);
77 for (PackageSet::iterator it = deactivatePackages.begin();
78 it != deactivatePackages.end(); ++it) {
79 Package* package = *it;
80 RemovePackage(package);
81 delete package;
86 VolumeState*
87 VolumeState::Clone() const
89 VolumeState* clone = new(std::nothrow) VolumeState;
90 if (clone == NULL)
91 return NULL;
92 ObjectDeleter<VolumeState> cloneDeleter(clone);
94 for (PackageFileNameHashTable::Iterator it
95 = fPackagesByFileName.GetIterator();
96 Package* package = it.Next();) {
97 Package* clonedPackage = package->Clone();
98 if (clonedPackage == NULL)
99 return NULL;
100 clone->AddPackage(clonedPackage);
103 return cloneDeleter.Detach();