1 #ifndef SimTK_SimTKCOMMON_STABLEARRAY_H_ 2 #define SimTK_SimTKCOMMON_STABLEARRAY_H_ 59 explicit StableArray(
size_t z,
const T& ival=T()) : stuff(z), nOccupiedSlots(z) {
60 for (
size_t i=0; i<
z; ++i) stuff[i] =
new T(ival);
65 for (
size_t i=0; i<s.
size(); ++i)
66 if (!s.
empty(i)) initializeEmptyElement(i, s[i]);
74 for (
size_t i=0; i<s.
size(); ++i)
75 if (!s.
empty(i)) initializeEmptyElement(i, s[i]);
84 assert(i < stuff.
size());
88 size_t nItems()
const {
return nOccupiedSlots;}
94 void resize(
size_t newz,
const T& ival=T()) {
95 const size_t oldz = stuff.
size();
97 for (
size_t i=newz; i < oldz; ++i)
98 eraseElementIfNecessary(i);
101 for (
size_t i=0; i < newz; ++i)
102 initializeElementIfNecessary(i,ival);
107 for (
size_t i=0; i < stuff.
size(); ++i)
108 eraseElementIfNecessary(i);
126 eraseOccupiedElement(stuff.
size()-1);
133 assert(i <= stuff.
size());
135 else initializeEmptyElement(i,t);
141 for (
size_t i=0; i<
size(); ++i)
142 if (
empty(i))
return i;
152 assert(i < stuff.
size());
153 for (; i < stuff.
size() && !stuff[i]; ++i);
174 else eraseElementIfNecessary(i);
180 assert(firstItem < stuff.
size());
181 return *stuff[firstItem];
185 assert(firstItem < stuff.
size());
186 return *stuff[firstItem];
195 assert(i < stuff.
size() && stuff[i]);
199 assert(i < stuff.
size() && stuff[i]);
204 size_t nOccupiedSlots;
210 void eraseOccupiedElement(
size_t i) {
211 assert(i < stuff.
size() && stuff[i]);
212 delete stuff[i]; stuff[i]=0; --nOccupiedSlots;
215 void initializeEmptyElement(
size_t i,
const T& t) {
216 assert(i < stuff.
size() && !stuff[i]);
217 stuff[i] =
new T(t); ++nOccupiedSlots;
220 void eraseElementIfNecessary(
size_t i) {
221 assert(i < stuff.
size());
222 if (stuff[i]) eraseOccupiedElement(i);
225 void initializeElementIfNecessary(
size_t i,
const T& t) {
226 assert(i < stuff.
size());
227 if (!stuff[i]) initializeEmptyElement(i,t);
234 #endif // SimTK_SimTKCOMMON_STABLEARRAY_H_ const T & back() const
Return a const reference to the last element in this array, which must not be empty.
Definition: Array.h:2297
const T & operator[](size_t i) const
Definition: StableArray.h:194
void erase(size_t i)
Definition: StableArray.h:172
StableArray(const StableArray &s)
Definition: StableArray.h:64
size_t nItems() const
Definition: StableArray.h:88
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
void resize(size_type n)
Change the size of this Array, preserving all the elements that will still fit, and default construct...
Definition: Array.h:2053
void pop_back()
Definition: StableArray.h:124
void resize(size_t newz, const T &ival=T())
Definition: StableArray.h:94
void clear()
Definition: StableArray.h:106
void pop_back()
Remove the last element from this array, which must not be empty.
Definition: Array.h:2411
size_t insert(const T &t)
Definition: StableArray.h:160
size_type size() const
Return the current number of elements stored in this array.
Definition: Array.h:2037
bool empty(size_t i) const
Definition: StableArray.h:83
This file defines the Array_<T,X> class and related support classes including base classes ArrayViewC...
bool empty() const
Definition: StableArray.h:82
size_t size() const
Definition: StableArray.h:87
void push_back(const T &t)
Definition: StableArray.h:115
BLAS_Accelerate_LIBRARY Bsymbolic functions z
Definition: CMakeCache.txt:164
size_t findNextItem(size_t i)
Definition: StableArray.h:151
╨╧ рб▒ с ■ ╖ ╣ ■ │ ┤ ╡ ╢ ье┴ А ° ┐ ч bjbjcTcT ┌┘ │ ├ ╗ t ╖ Я ┴ K K K D П П П А Л2 Ф П Z╞ j J a n u a r A b s t r a c t W e d e s c r i b e t h e g o a l s a n d d e s i g n d e c i s i o n b e h i n d S i m m a t r i t h e S i m T K m a t r i x a n d l i n e a r a l g e b r a l i b r a r a n d p r o v i d e r e f e r e n c e i n f o r m a t i o n f o r u s i n g i t T h e i d e a i s t o p r o v i d e t h e p o w e n a t u r a l n e s s
Definition: Simmatrix.doc:7
StableArray<T> is like std::vector<T> (or SimTK::Array_<T>) but more stable in two ways: ...
Definition: StableArray.h:54
size_t findFreeSlot() const
Definition: StableArray.h:138
T & front()
Definition: StableArray.h:183
const T & back() const
Definition: StableArray.h:191
StableArray(size_t z, const T &ival=T())
Definition: StableArray.h:59
void insertAt(size_t i, const T &t)
Definition: StableArray.h:132
Mandatory first inclusion for any Simbody source or header file.
T & operator[](size_t i)
Definition: StableArray.h:198
~StableArray()
Definition: StableArray.h:80
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable or merely the Work and Derivative Works thereof Contribution shall mean any work of including the original version of the Work and any modifications or additions to that Work or Derivative Works that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner For the purposes of this submitted means any form of or written communication sent to the Licensor or its including but not limited to communication on electronic mailing source code control and issue tracking systems that are managed or on behalf the Licensor for the purpose of discussing and improving the but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as Not a Contribution Contributor shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work Grant of Copyright License Subject to the terms and conditions of this each Contributor hereby grants to You a non no royalty free
Definition: LICENSE.txt:44
void push_back(const T &value)
This method increases the size of the Array by one element at the end and initializes that element by...
Definition: Array.h:2359
const T & front() const
Definition: StableArray.h:178
T & back()
Definition: StableArray.h:192
bool empty() const
Return true if there are no elements currently stored in this array.
Definition: Array.h:2042
StableArray & operator=(const StableArray &s)
Definition: StableArray.h:71
StableArray()
Definition: StableArray.h:56