Stream.h 6.39 KB
Newer Older
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
#ifndef OPENMM_STREAM_H_
#define OPENMM_STREAM_H_

/* -------------------------------------------------------------------------- *
 *                                   OpenMM                                   *
 * -------------------------------------------------------------------------- *
 * This is part of the OpenMM molecular simulation toolkit originating from   *
 * Simbios, the NIH National Center for Physics-Based Simulation of           *
 * Biological Structures at Stanford, funded under the NIH Roadmap for        *
 * Medical Research, grant U54 GM072970. See https://simtk.org.               *
 *                                                                            *
 * Portions copyright (c) 2008 Stanford University and the Authors.           *
 * Authors: Peter Eastman                                                     *
 * Contributors:                                                              *
 *                                                                            *
 * Permission is hereby granted, free of charge, to any person obtaining a    *
 * copy of this software and associated documentation files (the "Software"), *
 * to deal in the Software without restriction, including without limitation  *
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
 * and/or sell copies of the Software, and to permit persons to whom the      *
 * Software is furnished to do so, subject to the following conditions:       *
 *                                                                            *
 * The above copyright notice and this permission notice shall be included in *
 * all copies or substantial portions of the Software.                        *
 *                                                                            *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
 * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
 * -------------------------------------------------------------------------- */

#include <string>
36
#include "internal/windowsExport.h"
37
38
39

namespace OpenMM {

40
class OPENMM_EXPORT StreamImpl;
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

/**
 * A Stream encapsulates a particular implementation of a stream of data elements.  A Stream has three
 * fundamental properties:
 * 
 * <ul>
 * <li>A name.  Although a Stream's name has no impact on the API for working with it, a particular platform
 * may choose to implement different Streams in different ways.  The name allows it to distinguish them.</li>
 * <li>A size.  This is the number of data elements contained in the stream.</li>
 * <li>A data type.  There are three basic data types: 32 bit floating point (Float), 64 bit floating point
 * (Double), and 32 bit signed integers (Integer).  In addition, there are compound data types which allow
 * a single stream element to contain multiple values.  For example, the data type Float3 indicates that
 * each stream element is an array of three 32 bit floats.</li>
 * </ul>
 * Stream objects are created by Platforms:
 * 
 * <pre>
 * Stream stream = platform.createStream(streamName, size, dataType);
 * </pre>
 * 
 * A Stream is an opaque reference to the stream data.  You cannot access stream elements directly.  Instead,
 * you must query or modify the stream data by calling methods such as loadFromArray() and saveToArray().
 * These are potentially expensive operations, since they may involve transferring data between main memory
 * and video memory, so they should be called sparing.
 * 
 * It is important to remember that the data type dictates only the API for working with the Stream, not how
 * it is represented internally.  For example, even if a Stream object has type Double, a particular Platform
 * may choose to implement it internally with single precision values.
 */

class Stream {
public:
    Stream();
    Stream(const Stream& copy);
    ~Stream();
76
    Stream& operator=(const Stream& copy);
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
    /**
     * This is an enumeration of the allowed data types for a Stream.
     */
    enum DataType {Float, Float2, Float3, Float4, Double, Double2, Double3, Double4, Integer, Integer2, Integer3, Integer4};
    /**
     * Get the name of this Stream.
     */
    std::string getName() const;
    /**
     * Get the number of elements in this stream.
     */
    int getSize() const;
    /**
     * Get the data type of each element in the stream.
     */
    Stream::DataType getDataType() const;
    /**
     * Copy the contents of an array into this stream.
     * 
     * @param  array a pointer to the start of the array.  The array is assumed to have the same length as this stream,
     * and to contain elements of the correct data type for this stream.  If the stream has a compound data type, all
     * the values should be packed into a single array: all the values for the first element, followed by all the values
     * for the next element, etc.
     */
    void loadFromArray(const void* array);
    /**
     * Copy the contents of this stream into an array.
     * 
     * @param  array a pointer to the start of the array.  The array is assumed to have the same length as this stream,
     * and to contain elements of the correct data type for this stream.  If the stream has a compound data type, all
     * the values should be packed into a single array: all the values for the first element, followed by all the values
     * for the next element, etc.
     */
    void saveToArray(void* array);
    /**
     * Set every element of this stream to the same value.
     * 
     * @param a pointer to the value.  It is assumed to be of the correct data type for this stream.
     */
    void fillWithValue(void* value);
117
118
119
120
    /**
     * Get the object which implements this Stream.
     */
    const StreamImpl& getImpl() const;
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
    /**
     * Get the object which implements this Stream.
     */
    StreamImpl& getImpl();
private:
    friend class Platform;
    /**
     * Create a StreamImpl.
     * 
     * @param name the name of the stream to create
     */
    Stream(StreamImpl* impl);
    StreamImpl* impl;
};

} // namespace OpenMM

#endif /*OPENMM_STREAM_H_*/