asterix.atomic.padded.Atomic.scala Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2014-2015 by its authors. Some rights reserved.
* See the project's home at: https://github.com/monifu/asterix
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package asterix.atomic.padded
import asterix.atomic
object Atomic {
/**
* Constructs an `Atomic[T]` reference. Based on the `initialValue`, it will return the best, most specific
* type. E.g. you give it a number, it will return something inheriting from `AtomicNumber[T]`. That's why
* it takes an `AtomicBuilder[T, R]` as an implicit parameter - but worry not about such details as it just works.
*
* @param initialValue is the initial value with which to initialize the Atomic reference
* @param builder is the builder that helps us to build the best reference possible, based on our `initialValue`
*/
def apply[T, R <: atomic.Atomic[T]](initialValue: T)(implicit builder: AtomicBuilder[T, R]): R =
builder.buildInstance(initialValue)
/**
* Returns the builder that would be chosen to construct Atomic references
* for the given `initialValue`.
*/
def builderFor[T, R <: atomic.Atomic[T]](initialValue: T)(implicit builder: AtomicBuilder[T, R]): AtomicBuilder[T, R] =
builder
}