scire
Sadh's C++ Impromptu Routines Ensemble
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
container.hpp
Go to the documentation of this file.
1 // scire/struct/container
2 
3 // Copyright (c) 2014, Khan 'Sadh' Mostafa (http://nafSadh.com/Khan)
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying text at http://www.boost.org/LICENSE_1_0.txt)
6 
7 /*
8  scire/struct/container.hpp
9 
10  scire container abstraction :
11  - Container : contains many elements
12 
13  scire container interfaces :
14  - Crate : elements contained in array
15 
16  other required scire files:
17  none
18 
19  author:
20  ~nafSadh
21  */
22 #ifndef SCIRE_struct_container_HPP
23 #define SCIRE_struct_container_HPP
24 
25 namespace scire
26 {
27 
29 #define SCIRE_Container_ABSTR
30  /**
31  * Container Inferface.
32  *
33  * Size() function is necessary to all containers;
34  * Each container shall also implement Add(), Deduce() and Peek() function
35  * eventually allowing programs to switch between completely different
36  * containers (e.g. List, Queue, Stack etc. even when Add/Deduce/Peek
37  * bear very different concepts; e.g. Add vs. Insert vs Enque vs Push).
38  */
39  template<typename Type, typename SzType = int>
40  class AContainer
41  {
42  public:
43  /** virtual dtor for containers */
44  virtual ~AContainer() {}
45 
46  /**
47  * number of elements contained in
48  * @return current size
49  */
50  virtual SzType Size() const = 0;
51 
52  /**
53  * add an element
54  * @param element element to be added as new element
55  * @return true on success
56  */
57  virtual bool Add(const Type& element) = 0;
58 
59  /**
60  * deduce one element
61  * @return true on success
62  */
63  virtual bool Deduce() = 0;
64 
65  /**
66  * peek into next element contained in
67  * @return element
68  */
69  virtual Type Peek() const = 0;
70 
71  /**
72  * check if empty
73  * @return true when empty
74  */
75  virtual bool IsEmpty() const
76  {
77  return (this->Size() <= 0);
78  }
79  };
80 
81 #endif//SCIRE_Container_INTFC
82 
84 #define SCIRE_Crate_INTFC
85  /**
86  * Crate contains elements in an arrays.
87  */
88  template<typename Type, typename SzType = int>
89  class ICrate
90  {
91  public:
92  virtual SzType Capacity() const = 0;
93  };
94 #endif//SCIRE_Crate_INTFC
95 }//scire namespace
96 #endif//SCIRE_struct_container_HPP
virtual bool Add(const Type &element)=0
add an element
virtual bool Deduce()=0
deduce one element
virtual SzType Capacity() const =0
virtual SzType Size() const =0
number of elements contained in
Container Inferface.
Definition: container.hpp:40
scire/graph/gale_shapley.hpp
virtual ~AContainer()
virtual dtor for containers
Definition: container.hpp:44
virtual bool IsEmpty() const
check if empty
Definition: container.hpp:75
Crate contains elements in an arrays.
Definition: container.hpp:89
virtual Type Peek() const =0
peek into next element contained in