LibPkg
env_packages_table.h
Go to the documentation of this file.
1 // This file is part of LibPkg.
2 //
3 // Copyright 2003-2020 Graham Shaw
4 // Copyright 2018-2020 Alan Buckley.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 
18 #ifndef LIBPKG_ENV_PACKAGES_TABLE
19 #define LIBPKG_ENV_PACKAGES_TABLE
20 
21 #include "libpkg/version.h"
23 #include "libpkg/env_checker.h"
24 #include <map>
25 
26 namespace pkg {
27 
35  public table,
36  private table::watcher,
37  private env_checker::watcher
38 {
39 public:
40  struct best
41  {
45  string pkgenv;
46 
47  best() {}
52  best(const version& _pkgvrsn, const string &_pkgenv) : pkgvrsn(_pkgvrsn), pkgenv(_pkgenv) {}
53  };
54  typedef std::string key_type;
55  typedef best mapped_type;
56  typedef std::map<key_type,mapped_type>::const_iterator const_iterator;
57 
58 private:
60  binary_control_table *_control;
62  std::map<key_type,mapped_type> _data;
63 
64 public:
66  virtual ~env_packages_table();
67 
71  const_iterator begin() const
72  { return _data.begin(); }
73 
77  const_iterator end() const
78  { return _data.end(); }
79 
84  const_iterator find(const std::string &pkgname) const
85  { return _data.find(pkgname);}
86 
90  const binary_control &control(const std::string &pkgname) const;
91 
95  const best &operator[](const std::string &pkgname) const;
96 
97 private:
98  virtual void handle_change(table& t);
99  virtual void handle_change(env_checker& e);
100  void rebuild();
101 };
102 
103 } /* namespace pkg */
104 
105 #endif /* LIBPKG_LIBPKG_LATEST_CONTROL_TABLE */
const binary_control & control(const std::string &pkgname) const
Get the control record for the "best" package for the environment.
Definition: env_packages_table.cc:36
Class to check environment and convert a string environment specification into a pkg_env There is onl...
Definition: env_checker.h:156
env_packages_table(binary_control_table *control)
Definition: env_packages_table.cc:23
best()
Definition: env_packages_table.h:47
const_iterator begin() const
Get const iterator for start of table.
Definition: env_packages_table.h:71
The namespace used to hold the package management library.
Definition: auto_dir.cc:23
A class that filters the binary control table to create a list of the packages available in the curre...
Definition: env_packages_table.h:34
A mixin class to allow an object to watch one or more tables.
Definition: table.h:62
best mapped_type
Definition: env_packages_table.h:55
version pkgvrsn
The package version.
Definition: env_packages_table.h:43
string pkgenv
The package environment id.
Definition: env_packages_table.h:45
virtual ~env_packages_table()
Definition: env_packages_table.cc:31
A mixin class to allow an object to watch the environment checker.
Definition: env_checker.h:219
best(const version &_pkgvrsn, const string &_pkgenv)
Contruct best type from package name and version.
Definition: env_packages_table.h:52
std::string key_type
Definition: env_packages_table.h:54
Definition: env_packages_table.h:40
A class to represent the content of a RiscPkg control file.
Definition: control.h:35
A class for mapping package name and version to binary control record.
Definition: binary_control_table.h:32
A class to represent a package version.
Definition: version.h:32
std::map< key_type, mapped_type >::const_iterator const_iterator
Definition: env_packages_table.h:56
A class to represent the content of a RiscPkg binary control file.
Definition: binary_control.h:35
const_iterator find(const std::string &pkgname) const
Find a package in the list.
Definition: env_packages_table.h:84
const best & operator[](const std::string &pkgname) const
Get information on the "best" package for the environment.
Definition: env_packages_table.cc:48
const_iterator end() const
Get const iterator for end of table.
Definition: env_packages_table.h:77
A base class to represent a data table.
Definition: table.h:29

Reference Manual LibPkg Version 0.9.0 (4 Sep 2020)