| 1892 | } |
| 1893 | |
| 1894 | vtkNek5000Reader::nek5KObject* vtkNek5000Reader::nek5KList::getObject(int id) |
| 1895 | { |
| 1896 | nek5KObject* obj = this->head; |
| 1897 | while (obj) |
| 1898 | { |
| 1899 | if (obj->index == id) // if we found it |
| 1900 | { |
| 1901 | // move found obj to tail of the list |
| 1902 | // if already tail, do nothing |
| 1903 | if (obj == this->tail) |
| 1904 | break; |
| 1905 | |
| 1906 | // if it's the head, update head to next |
| 1907 | if (obj == this->head) |
| 1908 | { |
| 1909 | this->head = this->head->next; |
| 1910 | } |
| 1911 | // now move obj to tail |
| 1912 | obj->next->prev = obj->prev; |
| 1913 | if (obj->prev) // i.e. if current was not the head |
| 1914 | { |
| 1915 | obj->prev->next = obj->next; |
| 1916 | } |
| 1917 | this->tail->next = obj; |
| 1918 | obj->prev = this->tail; |
| 1919 | obj->next = nullptr; |
| 1920 | this->tail = obj; |
| 1921 | break; |
| 1922 | } |
| 1923 | else // otherwise, lok at the next one |
| 1924 | { |
| 1925 | obj = obj->next; |
| 1926 | } |
| 1927 | } |
| 1928 | |
| 1929 | // if we didn't find it |
| 1930 | if (obj == nullptr) |
| 1931 | { |
| 1932 | // if we are not over allocated, |
| 1933 | // create a new object, and put it at the tail |
| 1934 | if (this->cur_count < this->max_count) |
| 1935 | { |
| 1936 | this->cur_count++; |
| 1937 | // obj = nek5KObject::New(); |
| 1938 | obj = new nek5KObject(); |
| 1939 | if (this->head == nullptr) // if list is empty |
| 1940 | { |
| 1941 | this->head = obj; |
| 1942 | this->tail = obj; |
| 1943 | } |
| 1944 | else |
| 1945 | { |
| 1946 | this->tail->next = obj; |
| 1947 | obj->prev = this->tail; |
| 1948 | obj->next = nullptr; |
| 1949 | this->tail = obj; |
| 1950 | } |
| 1951 | // set the index to the one requested |