| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SANDBOX_LINUX_BPF_DSL_CONS_H_ | |
| 6 #define SANDBOX_LINUX_BPF_DSL_CONS_H_ | |
| 7 | |
| 8 #include "base/memory/ref_counted.h" | |
| 9 #include "sandbox/sandbox_export.h" | |
| 10 | |
| 11 namespace sandbox { | |
| 12 | |
| 13 // Cons provides an immutable linked list abstraction as commonly | |
| 14 // provided in functional programming languages like Lisp or Haskell. | |
| 15 template <typename T> | |
| 16 class Cons : public base::RefCounted<Cons<T> > { | |
| 17 public: | |
| 18 // List provides an abstraction for referencing a list of zero or | |
| 19 // more Cons nodes. | |
| 20 typedef scoped_refptr<const Cons<T> > List; | |
| 21 | |
| 22 // Return this node's head element. | |
| 23 const T& head() const { return head_; } | |
| 24 | |
| 25 // Return this node's tail element. | |
| 26 List tail() const { return tail_; } | |
| 27 | |
| 28 // Construct a new List using |head| and |tail|. | |
| 29 static List Make(const T& head, List tail) { | |
| 30 return make_scoped_refptr(new const Cons<T>(head, tail)); | |
| 31 } | |
| 32 | |
| 33 private: | |
| 34 Cons(const T& head, List tail) : head_(head), tail_(tail) {} | |
| 35 virtual ~Cons() {} | |
| 36 | |
| 37 T head_; | |
| 38 List tail_; | |
| 39 | |
| 40 friend class base::RefCounted<Cons<T> >; | |
| 41 DISALLOW_COPY_AND_ASSIGN(Cons); | |
| 42 }; | |
| 43 | |
| 44 } // namespace sandbox | |
| 45 | |
| 46 #endif // SANDBOX_LINUX_BPF_DSL_CONS_H_ | |
| OLD | NEW |