Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > bd5c3d824c3db63ffd9226c15941e6ad > files > 75

mozart-1.4.0-1mdv2010.0.i586.rpm

functor
  export
     add:    Add
     get:    Get
     getAll: GetAll
     remove: Remove
  define
     Data = {Dictionary.new}
     Ctr  = {New class $
                    prop locking
                    attr i:0
                    meth init(I <= 0)
                       lock i := I end
                    end
                    meth get($)
                       lock @i end
                    end
                    meth inc($)
                       lock I=@i+1 in i := I I end
                    end
                 end init()}
     
     proc {Add X}
        I={Ctr inc($)}
     in
        {Dictionary.put Data I X}
     end
        
     fun {Get ID}
        {Dictionary.get Data ID}
     end

     fun {GetAll}
        {Map {Dictionary.keys Data}
         fun {$ K}
            {AdjoinAt {Dictionary.get Data K} key K}
         end}
     end
     
     proc {Remove ID}
        {Dictionary.remove Data ID}
     end
end