This file is indexed.

/usr/include/viennacl/tools/shared_ptr.hpp is in libviennacl-dev 1.5.2-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#ifndef VIENNACL_TOOLS_SHARED_PTR_HPP
#define VIENNACL_TOOLS_SHARED_PTR_HPP

/* =========================================================================
   Copyright (c) 2010-2012, Institute for Microelectronics,
                            Institute for Analysis and Scientific Computing,
                            TU Wien.
   Portions of this software are copyright by UChicago Argonne, LLC.

                            -----------------
                  ViennaCL - The Vienna Computing Library
                            -----------------

   Project Head:    Karl Rupp                   rupp@iue.tuwien.ac.at

   (A list of authors and contributors can be found in the PDF manual)

   License:         MIT (X11), see file LICENSE in the base directory
============================================================================= */

/** @file tools/shared_ptr.hpp
    @brief Implementation of a shared pointer class (cf. std::shared_ptr, boost::shared_ptr). Will be used until C++11 is widely available.

    Contributed by Philippe Tillet.
*/

#include <cstdlib>
#include <algorithm>

namespace viennacl
{
  namespace tools
  {

    namespace detail
    {

      /** @brief Reference counting class for the shared_ptr implementation */
      class count
      {
        public:
          count(unsigned int val) : val_(val){ }
          void dec(){ --val_; }
          void inc(){ ++val_; }
          bool is_null(){ return val_ == 0; }
          unsigned int val(){ return val_; }
        private:
          unsigned int val_;
      };

      /** @brief Interface for the reference counter inside the shared_ptr */
      struct aux
      {
        detail::count count;

        aux() :count(1) {}
        virtual void destroy()=0;
        virtual ~aux() {}
      };

      /** @brief Implementation helper for the reference counting mechanism inside shared_ptr. */
      template<class U, class Deleter>
      struct auximpl: public detail::aux
      {
        U* p;
        Deleter d;

        auximpl(U* pu, Deleter x) :p(pu), d(x) {}
        virtual void destroy() { d(p); }
      };

      /** @brief Default deleter class for a pointer. The default is to just call 'delete' on the pointer. Provide your own implementations for 'delete[]' and 'free'. */
      template<class U>
      struct default_deleter
      {
        void operator()(U* p) const { delete p; }
      };

    }

    /** @brief A shared pointer class similar to boost::shared_ptr. Reimplemented in order to avoid a Boost-dependency. Will be replaced by std::shared_ptr as soon as C++11 is widely available. */
    template<class T>
    class shared_ptr
    {
        template<class U>
        friend class shared_ptr;

        detail::aux* pa;
        T* pt;

      public:

        shared_ptr() :pa(NULL), pt(NULL) {}

        template<class U, class Deleter>
        shared_ptr(U* pu, Deleter d) : pa(new detail::auximpl<U, Deleter>(pu, d)), pt(pu) {}

        template<class U>
        explicit shared_ptr(U* pu) : pa(new detail::auximpl<U, detail::default_deleter<U> >(pu, detail::default_deleter<U>())), pt(pu) {}

        shared_ptr(const shared_ptr& s) :pa(s.pa), pt(s.pt) { inc(); }

        template<class U>
        shared_ptr(const shared_ptr<U>& s) :pa(s.pa), pt(s.pt) { inc(); }

        ~shared_ptr() { dec(); }

        void reset(){
            shared_ptr<T>().swap(*this);
        }

        void reset(T * ptr){
            shared_ptr<T>(ptr).swap(*this);
        }

        void swap(shared_ptr<T> & other){
            std::swap(pt,other.pt);
            std::swap(pa, other.pa);
        }


        shared_ptr& operator=(const shared_ptr& s)
        {
            if(this!=&s)
            {
                dec();
                pa = s.pa;
                pt = s.pt;
                inc();
            }
            return *this;
        }

        T* get() const {  return pt; }

        T* operator->() const {  return pt; }

        T& operator*() const { return *pt; }

        void inc() { if(pa) pa->count.inc(); }

        void dec()
        {
          if(pa)
          {
            pa->count.dec();

            if(pa->count.is_null())
            {
                pa->destroy();
                delete pa;
                pa = NULL;
            }
          }
        }

    };

  }

}

#endif // VIENNACL_UTILS_SHARED_PTR_HPP