xc
LabelContainer.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. PĂ©rez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //LabelContainer.h
22 
23 #ifndef LABELCONTAINER_H
24 #define LABELCONTAINER_H
25 
26 #include <string>
27 #include <set>
28 #include "bimap.h"
29 #include <iostream>
30 #include "boost/python.hpp"
31 
34  {
35  friend class LabelContainer;
36  private:
38  bm_type bm;
39 
40  int get_indice_etiqueta(const std::string &e) const;
41  const std::string &get_etiqueta_indice(const int &i) const;
42  int insert(const std::string &e);
43  public:
44  size_t getNumLabels(void) const;
45 
46  const std::string &operator()(const int &) const;
47  int operator()(const std::string &) const;
48 
49  void Print(std::ostream &os) const;
50 
51  boost::python::dict getPyDict(void) const;
52  void setPyDict(const boost::python::dict &);
53  };
54 
55 std::ostream &operator<<(std::ostream &os,const LabelDictionary &lc);
56 
59  {
60  static LabelDictionary dic;
61  std::set<int> labels;
62  bool hasLabel(const int &i) const;
63 
64  public:
65  LabelContainer(void);
66  LabelContainer &operator+=(const LabelContainer &);
67  LabelContainer &operator-=(const LabelContainer &);
68  LabelContainer &operator*=(const LabelContainer &);
69  bool operator==(const LabelContainer &) const;
70 
71  void extend(const LabelContainer &);
72 
73  const std::set<int> &getIdsLabels(void) const;
74 
75  static const LabelDictionary &getDictionary(void);
76  size_t getNumLabels(void) const;
77  int addLabel(const std::string &e);
78  int removeLabel(const std::string &e);
79  bool hasLabel(const std::string &e) const;
80  void clear(void);
81 
82  void Print(std::ostream &os) const;
83  friend LabelContainer operator+(const LabelContainer &,const LabelContainer &);
84  friend LabelContainer operator-(const LabelContainer &,const LabelContainer &);
85  friend LabelContainer operator*(const LabelContainer &,const LabelContainer &);
86 
87  boost::python::dict getPyDict(void) const;
88  void setPyDict(const boost::python::dict &);
89  };
90 
91 std::ostream &operator<<(std::ostream &os,const LabelContainer &lc);
92 LabelContainer operator+(const LabelContainer &,const LabelContainer &);
93 LabelContainer operator-(const LabelContainer &,const LabelContainer &);
94 LabelContainer operator*(const LabelContainer &,const LabelContainer &);
95 
96 #endif
Label container.
Definition: LabelContainer.h:58
Label dictionary.
Definition: LabelContainer.h:33
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: LabelContainer.cc:93
size_t getNumLabels(void) const
Return the number of labels in this object.
Definition: LabelContainer.cc:158
Definition: bimap.h:41
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: LabelContainer.cc:83