00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef TJSTD_H
00019 #define TJSTD_H
00020
00022
00023 #ifndef TJUTILS_CONFIG_H
00024 #define TJUTILS_CONFIG_H
00025 #include <tjutils/config.h>
00026 #endif
00027
00028 #include <tjutils/tjheap.h>
00029 #include <tjutils/tjcstd.h>
00030
00031
00033
00034
00035
00036 #ifdef STREAM_REPLACEMENT
00037
00038 #define STD_ostream tjstd_ostream
00039 #define STD_istream tjstd_istream
00040 #define STD_ostringstream tjstd_ostringstream
00041 #define STD_ofstream tjstd_ofstream
00042 #define STD_ifstream tjstd_ifstream
00043 #define STD_cout tjstd_cout
00044 #define STD_cerr tjstd_cerr
00045 #define STD_cin tjstd_cin
00046 #define STD_endl tjstd_endl
00047 #define STD_flush tjstd_flush
00048 #define STD_setprecision tjstd_setprecision
00049 #define STD_getline tjstd_getline
00050 #define STD_make_pair tjstd_make_pair
00051
00052 class tjstd_ostream;
00053 class tjstd_istream;
00054 class tjstd_string;
00055
00056 #else
00057
00058 #define STD_ostream std::ostream
00059 #define STD_istream std::istream
00060 #define STD_ostringstream std::ostringstream
00061 #define STD_ofstream std::ofstream
00062 #define STD_ifstream std::ifstream
00063 #define STD_cout std::cout
00064 #define STD_cerr std::cerr
00065 #define STD_cin std::cin
00066 #define STD_endl std::endl
00067 #define STD_flush std::flush
00068 #define STD_setprecision std::setprecision
00069 #define STD_getline std::getline
00070 #define STD_make_pair std::make_pair
00071
00072 #include <iostream>
00073 #include <fstream>
00074 #include <sstream>
00075
00076 #endif // STREAM_REPLACEMENT
00077
00079
00080
00081 #ifdef STL_REPLACEMENT
00082
00083 #define STD_list tjstd_list
00084 #define STD_find tjstd_find
00085 #define STD_pair tjstd_pair
00086 #define STD_map tjstd_map
00087 #define STD_vector tjstd_vector
00088 #define STD_complex tjstd_complex
00089 #define STD_back_inserter tjstd_back_inserter
00090 #define STD_unique_copy tjstd_unique_copy
00091 #define STD_swap tjstd_swap
00092 #define STD_max tjstd_max
00093 #define STD_min tjstd_min
00094
00095
00096 #define STD_abs tjstd_abs
00097 #define STD_arg tjstd_arg
00098 #define STD_log tjstd_log
00099 #define STD_exp tjstd_exp
00100 #define STD_conj tjstd_conj
00101
00102 #else // STL_REPLACEMENT
00103
00104 #include <list>
00105 #include <utility>
00106 #include <map>
00107 #include <complex>
00108 #include <cmath>
00109 #include <new>
00110 #include <vector>
00111 #include <algorithm>
00112
00113 #define STD_list std::list
00114 #define STD_find std::find
00115 #define STD_pair std::pair
00116 #define STD_map std::map
00117 #define STD_vector std::vector
00118 #define STD_complex std::complex<float>
00119 #define STD_back_inserter std::back_inserter
00120 #define STD_unique_copy std::unique_copy
00121 #define STD_swap std::swap
00122 #define STD_max std::max
00123 #define STD_min std::min
00124
00125
00126 #define STD_abs std::abs
00127 #define STD_arg std::arg
00128 #define STD_log std::log
00129 #define STD_exp std::exp
00130 #define STD_conj std::conj
00131
00132 #endif // STL_REPLACEMENT
00133
00135
00136
00137 #ifdef STRING_REPLACEMENT
00138
00139 #define STD_string tjstd_string
00140
00141 #else // STRING_REPLACEMENT
00142
00143 #include <string>
00144 #define STD_string std::string
00145
00146 #endif // STRING_REPLACEMENT
00147
00148
00149
00150
00156
00157
00158 #ifdef STL_REPLACEMENT
00159
00160
00161 template<class I>
00162 class tjnode {
00163
00164 public:
00165 tjnode() : value(0), next(0), prev(0) {}
00166 tjnode (const I& newval) : value(new I(newval)), next(0), prev(0) {}
00167 ~tjnode() {if(value) delete value;}
00168 I* value;
00169 tjnode<I>* next;
00170 tjnode<I>* prev;
00171
00172 private:
00173
00174 tjnode(const tjnode&) {}
00175 tjnode& operator = (const tjnode&) {return *this;}
00176
00177 };
00178
00180
00181
00182 template<class I>
00183 class tjiterator {
00184
00185 public:
00186 tjiterator(tjnode<I>* itemptr=0) : current(itemptr) {}
00187
00188 operator I* () {
00189 if(current) return (current->value);
00190 else return 0;
00191 }
00192
00193 operator const I* () const {
00194 if(current) return (current->value);
00195 else return 0;
00196 }
00197
00198
00199 I& operator * () {return *(operator I* ());}
00200 const I& operator * () const {return *(operator const I* ());}
00201
00202 I* operator -> () {return operator I* ();}
00203 const I* operator -> () const {return operator const I* ();}
00204
00205
00206 tjiterator<I> operator ++ () {
00207 if(current && current->next) current=current->next;
00208 return *this;
00209 }
00210
00211 tjiterator<I> operator ++ (int) {
00212 tjnode<I>* old=current;
00213 if(current && current->next) current=current->next;
00214 return tjiterator<I>(old);
00215 }
00216
00217 tjiterator<I> operator -- () {
00218 if(current && current->prev) current=current->prev;
00219 return *this;
00220 }
00221
00222 tjiterator<I> operator -- (int) {
00223 tjnode<I>* old=current;
00224 if(current && current->prev) current=current->prev;
00225 return tjiterator<I>(old);
00226 }
00227
00228
00229 bool operator == (const tjiterator<I>& i2) const {
00230 return (current==i2.current);
00231 }
00232
00233 bool operator != (const tjiterator<I>& i2) const {
00234 return (current!=i2.current);
00235 }
00236
00237 tjnode<I>* current;
00238 };
00239
00241
00242
00243 template<class I>
00244 class tjstd_list {
00245
00246 public:
00247
00248 typedef tjiterator<I> iterator;
00249 typedef tjiterator<I> const_iterator;
00250
00251 tjstd_list() : first(&end_node), size_cache(0) {}
00252
00253 tjstd_list(unsigned int n, const I& value) : first(&end_node), size_cache(0) {
00254 for(unsigned int i=0; i<n; i++) push_back(value);
00255 }
00256
00257 tjstd_list(const tjstd_list& l) : first(&end_node), size_cache(0) {tjstd_list::operator = (l);}
00258
00259 ~tjstd_list() {clear();}
00260
00261 tjstd_list& operator = (const tjstd_list& l) {
00262 check("operator = (pre)");
00263 clear();
00264 for(const_iterator it=l.begin(); it!=l.end(); ++it) push_back(*it);
00265 check("operator = (post)");
00266 return *this;
00267 }
00268
00269
00270 tjiterator<I> begin() {return tjiterator<I>(first);}
00271 tjiterator<I> end() {return tjiterator<I>(&end_node);}
00272
00273 tjiterator<I> begin() const {return tjiterator<I>(first);}
00274 tjiterator<I> end() const {return tjiterator<I>(&end_node);}
00275
00276
00277 tjiterator<I> push_back(const I& newval) {
00278 check("push_back(pre)");
00279 tjnode<I>* newnode=new tjnode<I>(newval);
00280 push_back_node(newnode);
00281 check("push_back(post)");
00282 return tjiterator<I>(newnode);
00283 }
00284
00285
00286 tjiterator<I> push_front(const I& newval) {
00287 check("push_front(pre)");
00288 tjnode<I>* newnode=new tjnode<I>(newval);
00289 push_front_node(newnode);
00290 check("push_front(post)");
00291 return tjiterator<I>(newnode);
00292 }
00293
00294
00295
00296 tjiterator<I> insert(const tjiterator<I>& pos, const I& newval) {
00297 check("insert(pre)");
00298 tjnode<I>* newnode=new tjnode<I>(newval);
00299 insert_node(pos.current, newnode);
00300 return tjiterator<I>(newnode);
00301 }
00302
00303
00304 void remove(const I& remval) {
00305 check("remove(pre)");
00306 I value2Bremoved(remval);
00307 iterator it=begin();
00308 while(it!=end()) {
00309 if((*it)==value2Bremoved) {
00310 tjnode<I>* toberemoved=it.current;
00311 ++it;
00312 remove_node(toberemoved);
00313 delete toberemoved;
00314 } else ++it;
00315 }
00316 check("remove(post)");
00317 }
00318
00319
00320 tjiterator<I> erase(const tjiterator<I>& b,const tjiterator<I>& e) {
00321 check("erase2(pre)");
00322 iterator it=b;
00323 while(it!=e) {
00324 tjnode<I>* toberemoved=it.current;
00325 it.current=toberemoved->next;
00326 remove_node(toberemoved);
00327 delete toberemoved;
00328 }
00329 check("erase2(post)");
00330 return e;
00331 }
00332
00333
00334 tjiterator<I> erase(const tjiterator<I>& p) {
00335 check("erase1(pre)");
00336 tjiterator<I> result=p; result++;
00337 tjnode<I>* toberemoved=p.current;
00338 remove_node(toberemoved);
00339 delete toberemoved;
00340 check("erase1(post)");
00341 return result;
00342 }
00343
00344
00345 void clear() {erase(begin(),end());}
00346
00347
00348 unsigned int size() const {return size_cache;}
00349 bool empty() const {return !size_cache;}
00350
00351
00352
00353 void sort() {
00354 check("sort(pre)");
00355
00356
00357 tjstd_list<I> list_unsrt;
00358 if(first!=(&end_node)) {
00359 list_unsrt.first=first;
00360 list_unsrt.end_node.prev=end_node.prev;
00361 list_unsrt.end_node.prev->next=&(list_unsrt.end_node);
00362 list_unsrt.size_cache=size_cache;
00363 }
00364
00365
00366 first=&end_node;
00367 end_node.prev=0;
00368 size_cache=0;
00369
00370 while(list_unsrt.begin()!=list_unsrt.end()) {
00371 tjnode<I>* node2sort=list_unsrt.first;
00372 list_unsrt.remove_node(node2sort);
00373 iterator it=begin();
00374 while(it!=end() && (*it)<(*(node2sort->value))) ++it;
00375 insert_node(it.current,node2sort);
00376 }
00377
00378 list_unsrt.check("sort::list_unsrt");
00379 check("sort(post)");
00380 }
00381
00382
00383
00384 void unique() {
00385 check("unique(pre)");
00386 for(iterator it=begin(); it!=end(); ++it) {
00387 while(it.current->next && it.current->next->value && (*(it.current->value))==(*(it.current->next->value)) ) {
00388 tjnode<I>* toberemoved=it.current->next;
00389 remove_node(toberemoved);
00390 delete toberemoved;
00391 }
00392 }
00393 check("unique(post)");
00394 }
00395
00396 private:
00397
00398 void push_back_node(tjnode<I>* newnode) {
00399 check("push_back_node(pre)");
00400 newnode->next=0;
00401 newnode->prev=0;
00402 if(first==(&end_node)) {
00403 first=end_node.prev=newnode;
00404 newnode->next=&end_node;
00405 } else {
00406 end_node.prev->next=newnode;
00407 newnode->prev=end_node.prev;
00408 end_node.prev=newnode;
00409 newnode->next=&end_node;
00410 }
00411 size_cache++;
00412 check("push_back_node(post)");
00413 }
00414
00415
00416 void push_front_node(tjnode<I>* newnode) {
00417 check("push_front_node(pre)");
00418 newnode->next=0;
00419 newnode->prev=0;
00420 if(first==(&end_node)) {
00421 first=end_node.prev=newnode;
00422 newnode->next=&end_node;
00423 } else {
00424 first->prev=newnode;
00425 newnode->next=first;
00426 first=newnode;
00427 }
00428 size_cache++;
00429 check("push_front_node(post)");
00430 }
00431
00432
00433 void remove_node(tjnode<I>* toberemoved) {
00434 check("remove_node(pre)");
00435 if(toberemoved->prev) toberemoved->prev->next=toberemoved->next;
00436 if(toberemoved->next) toberemoved->next->prev=toberemoved->prev;
00437 if(toberemoved==first) first=toberemoved->next;
00438 if(toberemoved==end_node.prev) end_node.prev= toberemoved->prev;
00439 toberemoved->next=0;
00440 toberemoved->prev=0;
00441 size_cache--;
00442 check("remove_node(post)");
00443 }
00444
00445
00446
00447 void insert_node(tjnode<I>* posnode, tjnode<I>* newnode) {
00448 check("insert_node(pre)");
00449 newnode->next=0;
00450 newnode->prev=0;
00451 if(posnode==(&end_node)) {
00452 push_back_node(newnode);
00453 } else {
00454 if(posnode==first) push_front_node(newnode);
00455 else {
00456
00457 posnode->prev->next=newnode;
00458 newnode->prev=posnode->prev;
00459 newnode->next=posnode;
00460 posnode->prev=newnode;
00461 size_cache++;
00462 }
00463 }
00464 check("insert_node(post)");
00465 }
00466
00467
00468 void check(const char* ) const {
00469 #ifdef ODIN_DEBUG
00470
00471
00472
00473
00474
00475
00476
00477 #endif
00478 }
00479
00480
00481 tjnode<I>* first;
00482 mutable tjnode<I> end_node;
00483 int size_cache;
00484 };
00485
00486
00487 template<class I>
00488 tjiterator<I> tjstd_find(const tjiterator<I>& b,const tjiterator<I>& e, const I& findval) {
00489 tjiterator<I> it=b;
00490 while(it!=e) {
00491 if((*it)==findval) return it;
00492 ++it;
00493 }
00494 return e;
00495 }
00496
00497
00499
00500 template<class K, class V>
00501 class tjstd_pair {
00502
00503 public:
00504 tjstd_pair() {}
00505 tjstd_pair(const K& key, const V& value) : first(key), second(value) {}
00506
00507 bool operator == (const tjstd_pair<K,V>& i2) const {
00508
00509 if( (first<i2.first) || (i2.first<first) ) return false;
00510 return true;
00511 }
00512
00513 bool operator < (const tjstd_pair<K,V>& i2) const {
00514 return (first<i2.first);
00515 }
00516
00517 K first;
00518 V second;
00519 };
00520
00521
00522 template <class K, class V>
00523 tjstd_pair<K,V> tjstd_make_pair(const K& k, const V& v) {
00524 return tjstd_pair<K,V>(k,v);
00525 }
00526
00527
00529
00530
00531 template<class K, class V> class tjstd_map : public tjstd_list< tjstd_pair<K,V> > {
00532
00533 public:
00534 V& operator [] (const K& key) {
00535 typename tjstd_map<K,V>::iterator it=find(key);
00536 if(it==tjstd_list< tjstd_pair<K,V> >::end()) {
00537 it=push_back(tjstd_pair<K,V>(key,V()));
00538 tjstd_list< tjstd_pair<K,V> >::sort();
00539 }
00540 return it->second;
00541 }
00542
00543 typename tjstd_map<K,V>::iterator find(const K& key) {
00544 for(typename tjstd_map<K,V>::iterator it=tjstd_list< tjstd_pair<K,V> >::begin(); it!=tjstd_list< tjstd_pair<K,V> >::end(); ++it) {
00545 if( !( (key<(it->first)) || ((it->first)<key) ) ) return it;
00546 }
00547 return tjstd_list< tjstd_pair<K,V> >::end();
00548 }
00549
00550 typename tjstd_map<K,V>::iterator find(const K& key) const {
00551 for(typename tjstd_map<K,V>::const_iterator it=tjstd_list< tjstd_pair<K,V> >::begin(); it!=tjstd_list< tjstd_pair<K,V> >::end(); ++it) {
00552 if( !( (key<(it->first)) || ((it->first)<key) ) ) return it;
00553 }
00554 return tjstd_list< tjstd_pair<K,V> >::end();
00555 }
00556
00557 void insert(const tjstd_pair<K,V>& pair) {
00558 if(find(pair.first)==tjstd_list< tjstd_pair<K,V> >::end()) {
00559 (*this)[pair.first]=pair.second;
00560 }
00561 }
00562
00563 typename tjstd_map<K,V>::iterator insert(typename tjstd_map<K,V>::iterator, const tjstd_pair<K,V>& pair) {
00564 if(find(pair.first)==tjstd_list< tjstd_pair<K,V> >::end()) {
00565 (*this)[pair.first]=pair.second;
00566 }
00567 return find(pair.first);
00568 }
00569
00570
00571 };
00572
00574
00575
00576
00577 struct tjstd_vector_size {
00578 tjstd_vector_size(unsigned int size) : s(size) {}
00579 unsigned int s;
00580 };
00581
00582
00583
00584 template<class E>
00585 class tjstd_vector {
00586
00587 public:
00588 tjstd_vector() : data(0), nelements(0), cap(0) {}
00589
00590 tjstd_vector(tjstd_vector_size size, const E& initval=E()) : data(0), nelements(0), cap(0) {
00591 resize(size.s);
00592 for(unsigned int i=0; i<nelements; i++) {
00593 data[i]=initval;
00594 }
00595 }
00596
00597 tjstd_vector(const tjstd_vector<E>& v) : data(0), nelements(0), cap(0) {
00598 tjstd_vector<E>::operator = (v);
00599 }
00600
00601 ~tjstd_vector() {
00602 if(data) delete[] data;
00603 }
00604
00605 tjstd_vector<E>& operator = (const tjstd_vector<E>& v) {
00606 if(data) delete[] data;
00607 nelements=cap=v.nelements;
00608 data=new E[nelements];
00609 for(unsigned int i=0; i<nelements; i++) data[i]=v.data[i];
00610 return *this;
00611 }
00612
00613 E& operator [] (unsigned long i) {
00614 if(i>=nelements) {
00615
00616 return retdummy;
00617 }
00618 else return data[i];
00619 }
00620
00621 const E& operator [] (unsigned long i) const {
00622 if(i>=nelements) {
00623
00624 return retdummy;
00625 }
00626 else return data[i];
00627 }
00628
00629 void clear() { resize(0);}
00630
00631 void resize(unsigned long newsize) {
00632 if(newsize>cap) {
00633 cap=newsize*2;
00634 E* newdata=new E[cap];
00635 if(data) {
00636 for(unsigned int i=0; i<nelements; i++) newdata[i]=data[i];
00637 delete[] data;
00638 }
00639 data=newdata;
00640 }
00641 else if(newsize<cap/2) {
00642 cap=newsize;
00643 E* newdata=new E[cap];
00644 if(data){
00645 for(unsigned int i=0; i<newsize; i++) newdata[i]=data[i];
00646 delete[] data;
00647 }
00648 data=newdata;
00649 }
00650 nelements=newsize;
00651 }
00652
00653 void reserve(unsigned long newcap) {
00654 if(newcap>cap) {
00655 cap=newcap;
00656 E* newdata=new E[cap];
00657 if(data) {
00658 for(unsigned int i=0; i<nelements; i++) newdata[i]=data[i];
00659 delete[] data;
00660 }
00661 data=newdata;
00662 }
00663 }
00664
00665 unsigned long size() const {return nelements;}
00666 unsigned long capacity() const {return cap;}
00667
00668 void push_back(const E& val) {
00669 resize(nelements+1);
00670 data[nelements-1]=val;
00671 }
00672
00673 private:
00674 E* data;
00675 unsigned long nelements;
00676 unsigned long cap;
00677 E retdummy;
00678
00679 };
00680
00681
00682
00683
00684 template<class E>
00685 bool operator == (const tjstd_vector<E>& v1, const tjstd_vector<E>& v2) {
00686 if(v1.size()!=v2.size()) return false;
00687 bool result=true;
00688 for(unsigned int i=0; i<v1.size(); i++) {
00689 if(v1[i]!=v2[i]) {
00690 result=false;
00691 break;
00692 }
00693 }
00694 return result;
00695 }
00696
00697
00698 template<class E>
00699 bool operator != (const tjstd_vector<E>& v1, const tjstd_vector<E>& v2) {
00700 return !(v1==v2);
00701 }
00702
00703
00704 template<class E>
00705 bool operator < (const tjstd_vector<E>& v1, const tjstd_vector<E>& v2) {
00706 unsigned int v1size=v1.size();
00707 unsigned int v2size=v2.size();
00708 if(v1size!=v2size) return (v1size<v2size);
00709 for(unsigned int i=0; i<v1size; i++) {
00710 if(v1[i]!=v2[i]) return (v1[i]<v2[i]);
00711 }
00712 return false;
00713 }
00714
00716
00717
00718 class tjstd_complex {
00719
00720 float re, im;
00721
00722 public:
00723
00724 tjstd_complex (float real=0, float imaginary=0) {
00725 re = real;
00726 im = imaginary;
00727 }
00728
00729 float real() const { return re;}
00730 float imag() const { return im;}
00731
00732
00733 friend STD_ostream & operator << (STD_ostream & s, tjstd_complex c);
00734
00735 bool operator == (tjstd_complex c) const {
00736 if (c.re == re && c.im == im)
00737 return (1);
00738 else
00739 return (0);
00740 }
00741
00742 bool operator != (tjstd_complex c) const {
00743 if (c.re != re || c.im != im)
00744 return (1);
00745 else
00746 return (0);
00747 }
00748
00749
00750 friend tjstd_complex operator + (tjstd_complex c) {
00751 return (c);
00752 }
00753
00754
00755 friend tjstd_complex operator + (tjstd_complex c1, tjstd_complex c2) {
00756 tjstd_complex sum;
00757 sum.re = c1.re + c2.re;
00758 sum.im = c1.im + c2.im;
00759 return (sum);
00760 }
00761
00762 tjstd_complex operator += (tjstd_complex c) {
00763 re += c.re;
00764 im += c.im;
00765 return (*this);
00766 }
00767
00768
00769
00770 friend tjstd_complex operator - (tjstd_complex c) {
00771 c.re = -c.re;
00772 c.im = -c.im;
00773 return (c);
00774 }
00775
00776
00777
00778 friend tjstd_complex operator - (tjstd_complex c1, tjstd_complex c2) {
00779 tjstd_complex diff;
00780 diff.re = c1.re - c2.re;
00781 diff.im = c1.im - c2.im;
00782 return (diff);
00783 }
00784
00785 tjstd_complex operator -= (tjstd_complex c) {
00786 re -= c.re;
00787 im -= c.im;
00788 return (*this);
00789 }
00790
00791
00792 friend tjstd_complex operator *(tjstd_complex c1, tjstd_complex c2) {
00793 tjstd_complex prod;
00794 prod.re = c1.re * c2.re - c1.im * c2.im;
00795 prod.im = c1.re * c2.im + c1.im * c2.re;
00796 return (prod);
00797 }
00798
00799 tjstd_complex operator *= (tjstd_complex c) {
00800 operator = ((*this) * c);
00801 return (*this);
00802 }
00803
00804 friend tjstd_complex operator / (tjstd_complex c1, tjstd_complex c2) {
00805 tjstd_complex div;
00806 float denominator = c2.re * c2.re + c2.im * c2.im;
00807 if (denominator == 0.0) {
00808 div.re = 0.0;
00809 div.im = 0.0;
00810 } else {
00811 div.re = (c1.re * c2.re + c1.im * c2.im) / denominator;
00812 div.im = (c1.im * c2.re - c1.re * c2.im) / denominator;
00813 }
00814 return (div);
00815 }
00816
00817 tjstd_complex operator /= (tjstd_complex c) {
00818 operator = ((*this) / c);
00819 return (*this);
00820 }
00821
00822 friend tjstd_complex tjstd_conj (tjstd_complex c) {
00823 return tjstd_complex (c.re, -c.im);
00824 }
00825 friend tjstd_complex conj (tjstd_complex c) {return tjstd_conj(c);}
00826
00827 friend float tjstd_abs (tjstd_complex c) {
00828 return float(sqrt (c.re * c.re + c.im * c.im));
00829 }
00830 friend float abs (tjstd_complex c) {return tjstd_abs(c);}
00831
00832 friend float tjstd_arg (tjstd_complex c) {
00833 return float(atan2 (c.im, c.re));
00834 }
00835 friend float arg (tjstd_complex c) {return tjstd_arg(c);}
00836
00837 friend tjstd_complex tjstd_log (tjstd_complex c) {
00838 return (tjstd_complex ((float)log(abs(c)),arg(c)));
00839 }
00840 friend tjstd_complex log (tjstd_complex c) {return tjstd_log(c);}
00841
00842 friend tjstd_complex tjstd_exp (tjstd_complex c) {
00843 return ( tjstd_complex ( (float)exp(c.re)*cos(c.im), (float)exp(c.re)*sin(c.im) ) );
00844 }
00845 friend tjstd_complex exp (tjstd_complex c) {return tjstd_exp(c);}
00846
00847 };
00848
00849
00851
00852 template<typename T>
00853 void tjstd_swap(T& a1, T& a2){
00854 T temp=a1;
00855 a1=a2;
00856 a2=temp;
00857 }
00858
00859
00860 template<typename T>
00861 T tjstd_max(const T& a1, const T& a2){
00862 if(a1>a2) return a1;
00863 else return a2;
00864 }
00865
00866 template<typename T>
00867 T tjstd_min(const T& a1, const T& a2){
00868 if(a1<a2) return a1;
00869 else return a2;
00870 }
00871
00872
00873 #endif // ifdef STL_REPLACEMENT
00874
00875
00876
00878 #ifdef STRING_REPLACEMENT
00879
00880
00881
00882 class tjstd_string {
00883
00884 public:
00885 tjstd_string ();
00886 tjstd_string (unsigned int n, const char c=' ');
00887 tjstd_string (const char *charptr) : sdata(0) {tjstd_string::operator = (charptr);}
00888 tjstd_string (const tjstd_string& str) : sdata(0) {tjstd_string::operator = (str);}
00889
00890 tjstd_string& operator = (const tjstd_string& str);
00891 tjstd_string& operator = (const char *charptr);
00892
00893 ~tjstd_string();
00894
00895 unsigned int size() const {return length_cache;}
00896 unsigned int length() const {return size();}
00897
00898 const char * c_str() const;
00899
00900 char& operator [] (unsigned int i);
00901 const char& operator [] (unsigned int i) const;
00902
00903 friend tjstd_string operator + (const tjstd_string& s1, const tjstd_string& s2);
00904 friend tjstd_string operator + (const tjstd_string& s1, const char* s2);
00905 friend tjstd_string operator + (const char* s1, const tjstd_string& s2);
00906
00907 tjstd_string& operator += (const tjstd_string& s2);
00908
00909 friend bool operator == (const tjstd_string& s, const tjstd_string& t);
00910 friend bool operator == (const tjstd_string& s, const char* t);
00911 friend bool operator == (const char* s, const tjstd_string& t);
00912
00913
00914 friend bool operator != (const tjstd_string& s, const tjstd_string& t);
00915 friend bool operator != (const tjstd_string& s, const char* t);
00916 friend bool operator != (const char* s, const tjstd_string& t);
00917
00918 friend bool operator < (const tjstd_string& s, const tjstd_string& t);
00919 friend bool operator > (const tjstd_string& s, const tjstd_string& t);
00920
00921 friend STD_ostream& operator << (STD_ostream& s,const tjstd_string& t);
00922 friend STD_istream& operator >> (STD_istream& s, tjstd_string& t);
00923
00924 tjstd_string substr(unsigned int begin,unsigned int sublength) const;
00925 void erase(unsigned int begin,unsigned int end);
00926
00927 unsigned int find(const tjstd_string& searchstring, int startpos=0) const;
00928
00929 typedef unsigned int size_type;
00930
00931 static unsigned int npos;
00932
00933 private:
00934
00935 void concat2strings(const tjstd_string& srcstring1, const tjstd_string& srcstring2);
00936 static bool compare2strings(const char* str1, const char* str2);
00937
00938 char* sdata;
00939 unsigned int length_cache;
00940
00941 static char nullchar;
00942 };
00943
00944 #endif // STRING_REPLACEMENT
00946
00947
00949 #endif