1#REM/* -*- Mode: C++ -*- 2#REM * Author: Henrik Theiling <theiling@cs.uni-sb.de> 3#REM * 4#REM * @@Begin: Licencing and Copying@@ 5#REM * 6#REM * Copyright (c) Henrik Theiling 7#REM * Licence Version 2, Special Version for Erwin. 8#REM * 9#REM * The term 'this software' used in the following, additional to its 10#REM * usual usage, also includes the instantiated source files generated by 11#REM * tools of this package. 12#REM * 13#REM * This software is provided 'as-is', without warranty of any kind, 14#REM * express or implied. In no event will the authors or copyright holders 15#REM * be held liable for any damages arising from the use of this software. 16#REM * 17#REM * Permission is granted to anyone to use this software for any purpose, 18#REM * including commercial applications, and to alter it and redistribute it 19#REM * freely, subject to the following restrictions: 20#REM * 21#REM * 1. The origin of this software must not be misrepresented; you must 22#REM * not claim that you wrote the original software. If you use this 23#REM * software in a product, an acknowledgment in the product documentation 24#REM * would be appreciated. 25#REM * 26#REM * 2. Altered source versions must be plainly marked as such, and must 27#REM * not be misrepresented as being the original software. 28#REM * 29#REM * 3. You must not use any of the names of the authors or copyright 30#REM * holders of the original software for advertising or publicity 31#REM * pertaining to distribution without specific, written prior permission. 32#REM * 33#REM * 4. If you change this software and redistribute parts or all of it in 34#REM * any form, you must make the source code of the altered version of this 35#REM * software available. As an exception, files that were generated by 36#REM * tools of this package may be used freely, including modification. 37#REM * 38#REM * 5. This notice must not be removed or altered from any source 39#REM * distribution. 40#REM * 41#REM * This licence is governed by the Laws of Germany. Disputes shall be 42#REM * settled by Saarbruecken City Court. 43#REM * 44#REM * @@End: Licencing and Copying@@ 45#REM * 46#REM * Needs preprocessing. 47#REM * Note*: Because the replacement system is recursive and adjusts case, 48#REM * you should use template type names consisting of lower as well as 49#REM * upper case letters. 50#REM * 51#REM * TODO (in no explicit order): 52#REM * - Define something like a `mostly' C++ implementation. Then, 53#REM * many convenience C functions could be thrown away and the C++ 54#REM * inline implementation would replace them completely. (e.g. 55#REM * supply only the _raw versions. No _string, no _vector versions 56#REM * in C). 57#REM * 58#REM * - Sweep Vector_class. Instead of having prototypes for argument 59#REM * types 60#REM * Vector_class * 61#REM * Vector_class & 62#REM * and 63#REM * Vector_t * 64#REM * 65#REM * There should only be one: 66#REM * Vector_t * 67#REM * 68#REM * Together with an auto-cast to this type the code should be 69#REM * clearer. The problem is that newer versions of GCC warn about 70#REM * better conversion sequences which are very annoying. 71#REM * 72#REM * Most unfortunately, Vector_class arguments become ambiguous this 73#REM * way when a cast to Vector_t * and oType * exist and both can be 74#REM * arguments to the function. 75#REM * 76#REM * An alternative would be only to have 77#REM * Vector_class & 78#REM * 79#REM * Then, C -> C++ interaction would work less easily. 80#REM * 81#REM * Furthermore, the C++ versions of forall should use references 82#REM * instead of pointers. 83#REM * 84#REM * Perhaps the easiest way is to have a thousand overloaded 85#REM * functions... The decision is not yet done. The problem is that 86#REM * e.g. insert oder overwrite will be fivefold overloaded then. 87#REM * 88#REM * - In C++, either have the functions with suffixes _raw, _string, 89#REM * _vector, or have the overloaded ones. Not both. Change the 90#REM * #ifdef into a #IFEQ. 91#REM * 92#REM * - shared sub-vectors should be implemented. The data type should 93#REM * be the same, although shared sub-vectors will not support all 94#REM * functions (most notably, all modifying functions (including 95#REM * as_array()) will not be available). 96#REM * 97#REM * - Make shell_quotation correct for empty string. This should 98#REM * result in ''. 99#REM * 100#REM * - Add Vector_SHRINK_EXPLICIT or the like if you do not 101#REM * want vectors to automatically shrink, but only grow. 102#REM * Add Vector_shrink() for this. 103#REM * 104#REM * - For char vectors: add Vector_fgets, Vector_fgetc, 105#REM * Vector_fread, Vector_fwrite. 106#REM * 107#REM * - implement Vector_ALLOW_OUTOFRANGE completely 108#REM * 109#REM * - implement efficient handling of struct types (instead of 110#REM * using oType as parameter, pass (oType const &) in C++ and 111#REM * (oType const *) in C. 112#REM * 113#REM * - the naming of find, rfind, is_equal is wrong compared to 114#REM * overwrite and insert. This must be done (unfortunalely 115#REM * involving C interface incompatibilities) in version 3 of 116#REM * Erwin. 117#REM * 118#REM * DONE: 119#REM * - implement detach() correctly and adjust all the nasty 120#REM * return_if_null2i (self, table) which are wrong, as table may be 121#REM * NULL if nentries==0. 122#REM * (This was actually easy, table does not need to be NULL, but point 123#REM * to a static dummy variable). 124#REM * 125#REM * 126#REM *--------- 127#REM * #REPLACE_TYPE(oType_param_c, oType, oType const *) 128#REM * #REPLACE_TYPE(oType_param_cpp, oType, oType const &) 129#REM * #REPLACE_TYPE(oType_result_c, oType, oType) 130#REM * #REPLACE_TYPE(oType_result_cpp, oType, oType) 131#REM * #REPLACE_TYPE(oType_ptr, oType *, oType *) 132#REM * #REPLACE_TYPE(oType_const_ptr, oType const *, oType const *) 133#REM * #REPLACE_TYPE(oType_ref, oType &, oType &) 134#REM * #REPLACE_TYPE(oType_const_ref, oType const *, oType const &) 135#REM * 136#REM * See the licence and copying notice below. 137#REM */ 138#PARAMETER(oType) 139#DESCRIPTION(Typeofvaluesstored) 140#CHECK 141#REPLACE_PERHAPS_START(oT###ypeVar,oType) 142#REPLACE_PERHAPS_START(oT###ypeSuffix,) 143#REPLACE_PERHAPS_START(oT###ypeParamSuffix,oTypeSuffix) 144#REPLACE_PERHAPS_START(oT###ypeParam,oTypeoTypeParamSuffix) 145#REPLACE_PERHAPS_START(oT###ypeTouched,oTypeParam) 146#REPLACE_PERHAPS_START(oT###ypeVarParam,oTypeVaroTypeParamSuffix) 147#REPLACE_PERHAPS_START(oT###ypeResultSuffix,oTypeSuffix) 148#REPLACE_PERHAPS_START(oT###ypeResult,oTypeoTypeResultSuffix) 149#REPLACE(Vector,Global_vector_oType) 150#REPLACE(NSVector,nsvector_oType) 151#REMisChar:upto8bits 152#REM16bitcharsarecurrentlynotsupported!UseanexplicitisChar=0,isWChar=1forthat. 153#REMNOTE:sizeofoTypeandcharmustbeequal! 154#IFEQ(oType,char) 155#REPLACE_PERHAPS(isChar,1) 156#ENDIF 157#IFEQ(isChar,1) 158#REPLACE(Tchar,char) 159#ENDIF 160#REMisWChar:upto32bits(8,16,32aretypical). 161#REMNOTE:sizeofoTypeandwchar_tmustbeequal! 162#IFEQ(oType,wchar_t) 163#REPLACE_PERHAPS(isWChar,1) 164#ENDIF 165#IFEQ(isWChar,1) 166#REPLACE(Tchar,wchar_t) 167#ENDIF 168#REPLACE(TUchar,unsignedTchar) 169#REPLACE(FORMAT_REPETITION,0) 170#FILES(vector.cdvector_i.hdvector_u.hd) 171#GENERAL(Global_vector_u.ErwinHExtVector_u.ErwinHExt) 172#HEADER(Vector.ErwinHExtVector_i.ErwinHExtVector_d.ErwinHExtVector_f.ErwinHExtVector_ti.ErwinHExtVector_n.ErwinHExt) 173#CLASS_IDENTIFIER(Vector_class) 174#CLASS_IDENTIFIER(NSVector_class) 175#SPLIT_TARGET(Vector) 176#REM***************************************************************************************** 177#OUTPUT(Vector_f.ErwinHExt) 178 179#ifndefERWIN_Vector_f_ErwinHExt 180#defineERWIN_Vector_f_ErwinHExt 181 182/* Unification of Vector_class and Vector_t: they are identical now. */ 183structVector_t; 184#TYPEDEF_GLOBAL(aggregateVector_tNSVector_t) 185 186#ifndef__cplusplus 187typedefstructVector_tVector_t; 188#endif/* not defined __cplusplus */ 189 190typedefVector_tVector_class; 191#TYPEDEF_GLOBAL(aggregateVector_classNSVector_class) 192 193typedefVector_t*Vector_t_p; 194#TYPEDEF_GLOBAL(Vector_t_pNSVector_t_p) 195 196typedefVector_tconst*Vector_t_const_p; 197#TYPEDEF_GLOBAL(Vector_t_const_pNSVector_t_const_p) 198 199#defineVector_SIG__gen_sig__ 200 201ErwinGlobalDefines 202 203#REM#DEEPDECLS(Vector,HASH_RAW,CMP/NULL,ZERO,HAS_CONSTANT_ZERO,ICOPY,OCOPY,IFREE,OFREE,CONSTRUCTOR,DESTRUCTOR) 204#DEEPDECLS(Vector,HASH_RAW,CMP/NULL,ZERO,ICOPY,OCOPY,IFREE,OFREE,CONSTRUCTOR,DESTRUCTOR) 205#REMHACK:currently,HAS_CONSTANT_ZEROisremoved.Itshouldbeputback! 206#REM 207#REMThesedeepdeclsmustbeputintothe_ffile,otherwisetheimplementationmightnotseethem. 208#REMProbablysomeprogramswillnotrequiresomedefinestobemovedfromthedecls.htothe 209#REMsettings.hfilebecauseofthechange,butotherwise,wemightgetveryhardtofindrun-time 210#REMproblemswhentheapplicationhasdifferentsizedobjectsthanthelibrary. 211#REMTHISBUGWASVERYHARDTOFIND! 212 213#endif/* defined ERWIN_Vector_f_ErwinHExt */ 214 215#REM***************************************************************************************** 216#OUTPUT(Vector_n.ErwinHExt) 217 218#CHECKINCLUDE(Vector) 219 220#ifdefVector_NEED_HEADER 221#include"#Vector.ErwinHExt" 222#endif 223 224#REM***************************************************************************************** 225#OUTPUT(Vector_ti.ErwinHExt) 226 227#ifndefERWIN_Vector_ti_ErwinHExt 228#defineERWIN_Vector_ti_ErwinHExt 229 230#defineVector_size_t_KINDUINT 231#defineVector_size_t_TYPE_INFOTYPE_INFO_NAME(Vector_size_t) 232externTYPE_INFO_T(Vector_size_t); 233 234#defineVector_cnt_t_KINDSINT 235#defineVector_cnt_t_TYPE_INFOTYPE_INFO_NAME(Vector_cnt_t) 236externTYPE_INFO_T(Vector_cnt_t); 237 238#defineVector_index_t_KINDSINT 239#defineVector_index_t_TYPE_INFOTYPE_INFO_NAME(Vector_index_t) 240externTYPE_INFO_T(Vector_index_t); 241 242#defineVector_t_KINDSTRUCT 243#defineVector_t_TYPE_INFOTYPE_INFO_NAME(Vector_t) 244externTYPE_INFO_T(Vector_t); 245 246#defineVector_t_p_KINDPOINTER 247#defineVector_t_p_TYPE_INFOTYPE_INFO_NAME(Vector_t_p) 248externTYPE_INFO_T(Vector_t_p); 249 250#defineVector_t_const_p_KINDPOINTER 251#defineVector_t_const_p_TYPE_INFOTYPE_INFO_NAME(Vector_t_const_p) 252externTYPE_INFO_T(Vector_t_const_p); 253 254#defineVector_content_KINDVECTOR 255#defineVector_content_TYPE_INFOTYPE_INFO_NAME(Vector_content) 256externTYPE_INFO_T(Vector_content); 257 258#defineVector_content_p_KINDPOINTER 259#defineVector_content_p_TYPE_INFOTYPE_INFO_NAME(Vector_content_p) 260externTYPE_INFO_T(Vector_content_p); 261 262#defineVector_class###_TYPE_INFOVector_t_TYPE_INFO 263#defineVector_class_p###_TYPE_INFOVector_t_p_TYPE_INFO 264#defineVector_class_const_p###_TYPE_INFOVector_t_const_p_TYPE_INFO 265 266#endif/* defined ERWIN_Vector_ti_ErwinHExt */ 267 268#REM***************************************************************************************** 269#OUTPUT(Vector.ErwinHExt) 270/* -*- Mode: C -*- */ 271#DATE 272/* 273 * Author: Henrik Theiling 274 * Description: 275 * Public header file for vectors with arbitrary value types. 276 * 277 */ 278#LICENCE 279 280#ifdefERWIN_DEBUG_INCLUDE 281#warning"Including Vector.ErwinHExt" 282#endif 283 284#ifndefERWIN_Vector_ErwinHExt 285#defineERWIN_Vector_ErwinHExt 286 287#ifdefERWIN_DEBUG_INCLUDE 288#warning"First inclusion of Vector.ErwinHExt" 289#endif 290 291/* Include basic configuration */ 292#ifdefGlobal_ERWIN_COMPILING 293# include"erwin/defs.h" 294#else 295# include<erwin/defs.h> 296#endif 297 298/* Include definitions */ 299#include"#Vector_d.ErwinHExt" 300 301/* Include basic definitions */ 302#ifdefGlobal_ERWIN_COMPILING 303# include"erwin/base.h" 304#else 305# include<erwin/base.h> 306#endif 307 308#ifdefGlobal_ERWIN_COMPILING 309# include"erwin/forwards.h" 310#else 311# include<erwin/forwards.h> 312#endif 313 314#ifdefHAVE_STDIO_H 315# include<stdio.h> 316#endif 317 318#IFCPPONLY 319#ELSE 320#ifdefined(__cplusplus) 321extern"C"{ 322#endif/* __cplusplus */ 323#ENDIF 324 325#undefGlobal_vector_errno 326#ifGlobal_ERWIN_GLOBAL_ERRNO 327# defineGlobal_vector_errnoGlobal_erwininternalvectorerrno 328/* If you compiled Erwin without the Global_ERWIN_THREAD_SAFE flag, 329 * this variable holds global status code for vectors. 330 */ 331#endif 332 333#undefGlobal_vector_strerror 334#defineGlobal_vector_strerror(X)Global_erwininternalvectorstrerror(X) 335/* Returns a textual description of a given error. This description 336 * starts with `Error: ' or `Warning: ' or something the like 337 * to indicate the status level. This is then followed by a 338 * short description phrase. 339 */ 340 341/*! enum: Global_VECTOR_OK, Global_VECTOR_ERR_*, Global_VECTOR_WARN_* */ 342#undefGlobal_VECTOR_OK 343#defineGlobal_VECTOR_OKGlobal_ERWININTERNALVECTOROK 344/* No error occurred. */ 345 346#undefGlobal_VECTOR_IS_OK 347#defineGlobal_VECTOR_IS_OK(X)Global_ERWININTERNALVECTORISOK(X) 348/* Find out whether the status code vector_errno indicates that everything is fine. */ 349 350#undefGlobal_VECTOR_IS_ERROR 351#defineGlobal_VECTOR_IS_ERROR(X)Global_ERWININTERNALVECTORISERROR(X) 352/* Find out whether the status code vector_errno indicates that an error occured. */ 353 354#undefGlobal_VECTOR_IS_WARNING 355#defineGlobal_VECTOR_IS_WARNING(X)Global_ERWININTERNALVECTORISWARNING(X) 356/* Find out whether the status code vector_errno indicates that an error occured. */ 357 358#undefGlobal_VECTOR_ERR_NOMEM 359#defineGlobal_VECTOR_ERR_NOMEMGlobal_ERWININTERNALVECTORERRNOMEM 360/* Memory exhausted. If you think this is a fatal error and should be 361 * treated like a failed assertion, #define Global_ERWIN_NOMEM_IS_FATAL. 362 */ 363 364#undefGlobal_VECTOR_ERR_OUTOFRANGE 365#defineGlobal_VECTOR_ERR_OUTOFRANGEGlobal_ERWININTERNALVECTORERROUTOFRANGE 366/* Returned whenever an argument has a value that cannot be handled. */ 367 368#undefGlobal_VECTOR_ERR_TOOLARGE 369#defineGlobal_VECTOR_ERR_TOOLARGEGlobal_ERWININTERNALVECTORERRTOOLARGE 370/* The vector cannot handle the new size due to the limited range of 371 * the data type for the index. */ 372 373#undefGlobal_VECTOR_ERR_IO 374#defineGlobal_VECTOR_ERR_IOGlobal_ERWININTERNALVECTORERRIO 375/* Operations doing I/O return this error when an I/O error occured. Which 376 * error it was can be determined by calling ferror(3) on the FILE * you 377 * passed to the vector function. 378 * 379 * Currently, Vector_fread and Vector_fgets may return this error. 380 */ 381 382#undefGlobal_VECTOR_ERR_ASSERTIONFAILED 383#defineGlobal_VECTOR_ERR_ASSERTIONFAILEDGlobal_ERWININTERNALVECTORERRASSERTIONFAILED 384/* Whenever an axiomatic assertion failed, this error is occured. 385 * 386 * Note: Something really went wrong in this case, so do not expect that 387 * every failed assertion allows normal control flow to continue. 388 * This error means the program is broken and would have crashed 389 * or done something bad if the assertion had not been checked. 390 */ 391 392#undefGlobal_VECTOR_ERR_NOTCOMPILED 393#defineGlobal_VECTOR_ERR_NOTCOMPILEDGlobal_ERWININTERNALVECTORERRNOTCOMPILED 394/* If some compile time flags prevented compilation of parts a function needs 395 * at run-time, this is returned. Currently only the `V' argument specifier 396 * of the format functions return this if the files where compiled with 397 * a C compiler instead of a C++ compiler. 398 */ 399 400/* 401 * The following are warnings only. */ 402#undefGlobal_VECTOR_WARN_OUTOFRANGE 403#defineGlobal_VECTOR_WARN_OUTOFRANGEGlobal_ERWININTERNALVECTORWARNOUTOFRANGE 404/* If a value is out of range, this warning is returned. */ 405 406#undefGlobal_VECTOR_WARN_EMTPY 407#defineGlobal_VECTOR_WARN_EMPTYGlobal_ERWININTERNALVECTORWARNEMPTY 408/* Vector_fgets returns this if EOF was reached and no character could be 409 * read anymore. */ 410 411#ifVector_SMALL_SIZE 412/* Size: 16 bit, index:32 bits. if possible. */ 413/* We should use 'int' in the API here, but this requires assert()s 414 * due to different sizes, which are not yet implemented. 415 * 416 * Anyway, since there are not enough overflow checks for the other 417 * settings either, we allow this to be used... 418 */ 419 420/* 16 bit sizes are large enough. */ 421/* The index type is always 'int'. */ 422 423# ifndefVector_PREALLOC_SIZE 424# defineVector_PREALLOC_SIZE(16*1024) 425# endif 426# ifndefVector_CHUNK_SIZE 427# defineVector_CHUNK_SIZE(4*1024) 428# endif 429# ifSIZEOF_INT==2 430/* Prefer 'int' over 'short'. */ 431typedefunsignedintVector_size_t; 432typedefintVector_index_t; 433# defineVector_MAY_BE_INVALID(SIZEOF_VOIDP>SIZEOF_INT) 434# defineVector_SIZE_INDEX_DIFF0 435# elifSIZEOF_SHORT==2 436typedefunsignedshortVector_size_t; 437typedefintVector_index_t;/* 'int' in API, not 'short' */ 438# defineVector_MAY_BE_INVALID(SIZEOF_VOIDP>SIZEOF_SHORT) 439# defineVector_SIZE_INDEX_DIFF1 440# else 441/* Hmm? Strange. Just use int. */ 442typedefunsignedintVector_size_t; 443typedefintVector_index_t; 444# defineVector_MAY_BE_INVALID(SIZEOF_VOIDP>SIZEOF_INT) 445# defineVector_SIZE_INDEX_DIFF0 446# endif 447 448#elifVector_MEDIUM_SIZE 449 450/* Try 32 bit sizes, do not use 64 bits if avoidable. */ 451/* The index type is always 'int'. */ 452 453# ifndefVector_PREALLOC_SIZE 454# defineVector_PREALLOC_SIZE(8*1024) 455# endif 456# ifndefVector_CHUNK_SIZE 457# defineVector_CHUNK_SIZE(128*1024) 458# endif 459 460# ifSIZEOF_INT==4 461/* Prefer 'int' over 'short'. */ 462typedefunsignedintVector_size_t; 463typedefintVector_index_t; 464# defineVector_MAY_BE_INVALID(SIZEOF_VOIDP>SIZEOF_INT) 465# defineVector_SIZE_INDEX_DIFF0 466# elifSIZEOF_LONG==4&&SIZEOF_INT>SIZEOF_LONG 467typedefunsignedlongVector_size_t; 468typedefintVector_index_t; 469# defineVector_MAY_BE_INVALID(SIZEOF_VOIDP>SIZEOF_LONG) 470# defineVector_SIZE_INDEX_DIFF1 471# elifSIZEOF_SHORT==4 472typedefunsignedshortVector_size_t; 473typedefintVector_index_t; 474# defineVector_MAY_BE_INVALID(SIZEOF_VOIDP>SIZEOF_SHORT) 475# defineVector_SIZE_INDEX_DIFF0 476# else 477/* Hmm? Just use int. */ 478typedefunsignedintVector_size_t; 479typedefintVector_index_t; 480# defineVector_MAY_BE_INVALID(SIZEOF_VOIDP>SIZEOF_INT) 481# defineVector_SIZE_INDEX_DIFF0 482# endif 483 484#elifVector_LARGE_INDEX 485 486/* Full size_t support (e.g. >= 2G entries on 64 bit). */ 487/* The size and index are both '(s)size_t'. 488 * This is a different API: we do not have an 'int' index. */ 489# ifndefVector_PREALLOC_SIZE 490# defineVector_PREALLOC_SIZE(16*1024) 491# endif 492# ifndefVector_CHUNK_SIZE 493# defineVector_CHUNK_SIZE(256*1024) 494# endif 495typedefsize_tVector_size_t; 496typedefssize_tVector_index_t; 497# defineVector_MAY_BE_INVALID(SIZEOF_VOIDP>SIZEOF_SIZE_T) 498# defineVector_SIZE_INDEX_DIFF0 499 500#else 501 502/* By default, vectors work with 'int' as index type. */ 503# ifndefVector_PREALLOC_SIZE 504# defineVector_PREALLOC_SIZE(8*1024*1024) 505# endif 506# ifndefVector_CHUNK_SIZE 507# defineVector_CHUNK_SIZE(128*1024) 508# endif 509typedefunsignedintVector_size_t; 510typedefintVector_index_t; 511# defineVector_MAY_BE_INVALID(SIZEOF_VOIDP>SIZEOF_INT) 512# defineVector_SIZE_INDEX_DIFF0 513 514#endif 515 516 517typedefVector_index_tVector_cnt_t; 518/* index is always the same as cnt, it just marks a different usage */ 519 520#IFEQ(isChar,1) 521#defineVector_Tchar_tTchar 522#ENDIF 523 524typedefoTypeVector_value_t; 525#TYPEDEF(Vector_value_tNSVector_value_t) 526 527#TYPEDEF(Vector_size_tNSVector_size_t) 528#TYPEDEF(Vector_cnt_tNSVector_cnt_t) 529#TYPEDEF(Vector_index_tNSVector_index_t) 530 531typedefint(*Vector_cmp_t)(oTypeconst*,oTypeconst*); 532#TYPEDEF(Vector_cmp_tNSVector_cmp_t) 533 534typedefGlobal_ERWIN_BOOL(*Vector_feature_t)(oTypeParam); 535#TYPEDEF(Vector_feature_tNSVector_feature_t) 536 537#ifndefVector_MAP_T_DEFINED 538#defineVector_MAP_T_DEFINED 539/* In order to have oTypeResult as a result type for Vector_map_t, declare that 540 * function yourself and define Vector_MAP_T_DEFINED. 541 */ 542typedefoType(*Vector_map_t)(oTypeParam); 543#TYPEDEF(Vector_map_tNSVector_map_t) 544#endif 545#defineVector_CMP_T_NULL((Vector_cmp_t)NULL) 546 547#ifdef__cplusplus 548typedefbool(*Vector_cpp_feature_t)(oTypeParam); 549#TYPEDEF_CXX(Vector_cpp_feature_tNSVector_cpp_feature_t) 550#endif/* defined __cplusplus */ 551 552#TYPEDEF(Vector_element_ptr_tNSVector_element_ptr_t) 553#TYPEDEF_CXX(Vector_element_ref_tNSVector_element_ref_t) 554#IFEQ(oType,oTypeVar) 555typedefoType*Vector_element_ptr_t; 556#ifdef__cplusplus 557typedefoType&Vector_element_ref_t; 558#endif/* defined __cplusplus */ 559#ELSE 560typedefoTypeconst*Vector_element_ptr_t; 561#ifdef__cplusplus 562typedefoTypeconst&Vector_element_ref_t; 563#endif/* defined __cplusplus */ 564#ENDIF 565 566typedefint(*Vector_combine_t)(Vector_element_ptr_t,oTypeconst*); 567#TYPEDEF(Vector_combine_tNSVector_combine_t) 568#defineVector_COMBINE_T_NULL((Vector_combine_t)NULL) 569 570#IFEQ(isChar,1) 571#defineVector_STRING_LIT(X)X 572#defineVector_tchar_strlen(X)((X)==NULL?0:strlen(X)) 573/* For wchar_t, we'll have to change this */ 574 575/* 576 * For user defined quotation methods */ 577#TYPEDEF(aggregateVector_quotation_method_tNSVector_quotation_method_t) 578typedefstruct_Vector_quotation_method_t{ 579/* This class is used for customising formatting. 580 * The library supports several standard quotations 581 * like C strings or Lisp, Shell, etc. You may 582 * want to define your own syntax by implementing 583 * a few functions here and using 584 * Vector_set_quotation_method() to define your style. 585 */ 586 587Tcharconst*prefix; 588/* The prefix to print in front of a quoted string. 589 * NULL means empty. 590 * E.g. for C, this is |"\""|. 591 */ 592 593Tcharconst*suffix; 594/* The suffix to print in front of a quoted string. 595 * NULL means empty. 596 * 597 * E.g. for C, this is |"\""|. 598 */ 599 600Tcharconst*null_name; 601/* The string to use for quoted output if the string to 602 * print is NULL. (No prefix or suffix will be used in 603 * this case) 604 * 605 * E.g. for C, this is "NULL" and for Lisp, this is "nil". 606 * 607 * If this is NULL, an out of range error is generated when the 608 * NULL string is encountered to be quoted. 609 */ 610 611Tcharconst*empty_name; 612/* If this is != NULL, the empty string is exceptionally represent this way. 613 * 614 * Similar to null_name, but this handles the empty string. E.g. in Unxi Shell 615 * syntax quotation, which is currently implemented to not print string 616 * delimiters, the empty string would in normal printing result in just that: 617 * the empty string. But that's wrong, so this member has the value "''" for 618 * Shell quotation. 619 * 620 * If this is NULL, the string is normally printed using the other fields 621 * and functions of this struct. 622 */ 623 624int(*needs_quotation)(Tcharconst*); 625/* A function that decides whether a string needs quotations. 626 * You can either implement your own checks, or simply return 627 * a value of 2 to let the library check each character for 628 * quotation. 629 * 630 * Results: 631 * [0] no, no quotation 632 * [1] yes, quotation 633 * [2] decide by checking results of the quoted_length function. 634 * If for some oType it returns != 1, it needs quotation. 635 * [3] yes, quote, but leave out prefix and suffix. 636 * [4] Always quote, but decide whether the prefix and suffix 637 * are used by checking the results of the quoted_length 638 * function. If it is != 1 for some character, use them, 639 * otherwise leave them away. 640 * 641 * If the function pointer is NULL, this means to never quote. 642 */ 643 644int(*quoted_length)(int/* previous_quotation_length */,Tchar/* tobequoted */); 645/* For checking individually whether to quote or not for each character: 646 * 647 * NULL means: literal length 1 (no quotation) 648 * 649 * The integer given to this function is the output of this function for the 650 * previous characters. The function can then decide whether and how to quote 651 * depending on the previous value. Initially, -1 is given. 652 * If this function returns a negative value, its absolute value is taked as 653 * the quoted string's length. This is useful for indicating that a string 654 * needs quotation even if the current character's quoted length is 1. 655 */ 656 657void(*quote)(oType*/* destination */,Tchar/* tobequoted */,int/* length */); 658/* The actual implementation of a quotation of one character. 659 * 660 * NULL means: no quotation 661 * 662 * This function must write exactly length non-null characters. No null 663 * character may follow (use memcpy instead of strcpy!) 664 * The length argument is the output of the quoted_length function. 665 */ 666 667void(*check_quote)(oType*/* destination */,int/* length */); 668/* Check that the quotation has worked and eventually fix it so 669 * that it is properly quoted. The string passed is not 670 * null-terminated, but instead the length is given. 671 * 672 * This function pointer may be NULL: in that case it is not invoked. 673 * 674 * NOTE: This function must not change the length of the string! 675 * 676 * E.g. this function is used for the Windows shell quotation method to 677 * swap the last two characters if they are \". This is necessary because 678 * the quotation method is really weird (the backslash has two meanings): 679 * 680 * +----------+-------------+---------------------+ 681 * |! Before |! Quoted | | 682 * | B\C D | "B\C D" | | 683 * | B\"C D | "B\\"C D" | | 684 * | B\"C D\ | "B\\"C D"\ | *not* "B\\"C D\" | 685 * +----------+-------------+---------------------+ 686 * 687 * The last one cannot be "B\\"C D\" since a backslash before a double quote 688 * is interpreted as a quoted double quote. This is prevented by the 689 * check_quote function. 690 * 691 */ 692}Vector_quotation_method_t; 693 694#TYPEDEF(aggregateVector_format_info_tNSVector_format_info_t) 695typedefstruct_Vector_format_info_t{ 696/* This class is used to store information after a 697 * Vector_format() or the like has printed some string 698 * into a vector. 699 */ 700 701Global_ERWIN_BOOLquoted; 702/* Whether the last %s in the format string was quoted. */ 703 704Vector_cnt_tpos; 705/* How many characters from the given string were read by the last %s in 706 * the format string. */ 707 708#ifdef__cplusplus 709_Vector_format_info_t(): 710quoted(0), 711pos(0) 712{} 713#endif/* defined __cplusplus */ 714}Vector_format_info_t; 715 716#ENDIF 717 718/* 719 * ***** handling `vector' objects: ***** */ 720/*--BEGIN-C--*/ 721 722Global_ERWIN_EXPORT 723Vector_t*Vector_new(void)ATTR_MALLOC; 724/* Create a new vector with default values. I.e., with the 725 * default zero element Vector_ZERO and the default initial hash table 726 * size of Vector_INITIAL_SIZE. 727 * 728 */ 729 730 731#ifVector_DYN_ZERO 732Global_ERWIN_EXPORT 733Vector_t*Vector_new_with_zero(oTypeTouched/*zero*/)ATTR_MALLOC; 734/* Create a vector specifying the zero element. */ 735 736 737Global_ERWIN_EXPORT 738Vector_t*Vector_new_with_zero_and_initial_size( 739oTypeTouched/*zero*/,Vector_cnt_t/*initial_size*/)ATTR_MALLOC; 740/* Create a new, empty vector. The first form uses Global_oType_zero as the zero element. 741 * 742 * - If \p initial_size < 0: 743 * the default size Vector_INITIAL_SIZE will be used. 744 * 745 * - If \p initial_size == 0 but Vector_MINIMAL_SIZE > 0: 746 * a size of 1 will be used. 747 * 748 * Note: The vector always has size==0 even if \p initial_size > 0. This 749 * initial size is the size of the data structure used. 750 * The vector does not resize it until the 751 * vector becomes larger than that. 752 */ 753#endif 754 755Global_ERWIN_EXPORT 756Vector_t*Vector_new_with_initial_size(Vector_cnt_t/*initial_size*/)ATTR_MALLOC; 757/* Initialise with a given table size. See Vector_new_with_zero_and_initial_size. 758 */ 759 760Global_ERWIN_EXPORT 761Vector_t*Vector_new_from_raw( 762oTypeVar*/*contents*/,Vector_cnt_t/*nentries*/,Vector_cnt_t/*allocsize*/)ATTR_MALLOC; 763/* This makes a vector from contents. It 'steals' the pointer and makes it its 764 * internal vector table. It is assumed that we can (re/de)allocate the contents 765 * using the normal Global_ERWIN_TMALLOC/REALLOC/CMALLOC/FREE mechanism. 766 * 767 * Initial_size is the amount of memory that is allocated. You can safely pass less 768 * than nentries, meaning we should assume that there are only nentries allocated 769 * cells (this is safe behaviour). If you know the amount that is allocated, you 770 * should pass it to this function to improve performance by preventing unnecessary 771 * reallocations. 772 * 773 * If you want to *copy* contents into a vector, use _new_with_initial_size 774 * and _append_raw instead. 775 * 776 * If contents is NULL or allocsize is 0, then we invoke new_with_initial_size 777 * instead, so whether you get a vector that has no allocated table 778 * at all depends on the setting of Vector_ZERO_SIZE. By default, table with 779 * Vector_INITIAL_SIZE will be allocated. 780 * 781 * If allocsize is non-zero, Vector_MINIMAL_SIZE is ignored (as with the 782 * constructors that contain _with_initial_size), so you may allocate smaller 783 * vectors. (A size of 0, however, is special, see previous paragraph.) 784 */ 785 786#ifVector_DYN_ZERO 787 788Global_ERWIN_EXPORT 789Vector_t*Vector_new_from_raw_with_zero( 790oTypeVar*/*contents*/, 791Vector_cnt_t/*nentries*/, 792Vector_cnt_t/*allocsize*/, 793oTypeTouched/*zero*/)ATTR_MALLOC; 794/* Same as before but with a given zero element. */ 795 796#endif 797 798Global_ERWIN_EXPORT 799Vector_t*Vector_new_from_vector(Vector_t*/*other*/)ATTR_MALLOC; 800/* This might be strange: it makes a new vector from the contents of the other 801 * vector and then detaches the data from the other vector. Its purpose is 802 * mainly useful in C++ where you can clone vectors from a static vector 803 * by this means. E.g.: 804 * 805 * : Vector_class a; 806 * : ... 807 * : return Vector_new_from_vector (a); 808 * 809 * Or with the same effect, but without the need to use a long functions name: 810 * return a.copy_detach(); 811 * 812 * A related thing is Vector_xchg(), because the above is also roughly 813 * equivalent to: 814 * : Vector_t a; 815 * : ... 816 * : Vector_t *b= Vector_new(); 817 * : Vector_xchg(&a, b); 818 * : return b; 819 */ 820 821Global_ERWIN_EXPORT 822intVector_init(Vector_t*/*self*/)ATTR_NONNULL((1)); 823/* 824 * This is for initialising non-heap Vector_t objects that are allocated 825 * manually (thus, not via Vector_new). 826 * 827 * Invoking this function manually is usually discouraged. It is thought 828 * to be for nesting data structures. However, if you need to optimise 829 * heap usage, it is ok to use this function. 830 * 831 * \errno(OK, ERR_NOMEM) 832 */ 833 834#ifVector_DYN_ZERO 835Global_ERWIN_EXPORT 836intVector_init_with_zero_and_initial_size( 837Vector_t*/*self*/, 838oTypeTouched/*zero*/, 839Vector_cnt_t/*initial_size*/)ATTR_NONNULL((1)); 840/* 841 * This is for initialising non-heap Vector_t objects that are allocated 842 * manually (thus, not via Vector_new). 843 * 844 * Invoking this function manually is usually discouraged. It is thought 845 * to be for nesting data structures. However, if you need to optimise 846 * heap usage, it is ok to use this function. 847 * 848 * \errno(OK, ERR_NOMEM) 849 */ 850#endif 851 852Global_ERWIN_EXPORT 853intVector_init_with_initial_size( 854Vector_t*/*self*/, 855Vector_cnt_t/*initial_size*/)ATTR_NONNULL((1)); 856/* 857 * This is for initialising non-heap Vector_t objects. 858 * 859 * Invoking this function manually is usually discouraged. It is thought 860 * to be for nesting data structures. However, if you need to optimise 861 * heap usage, it is ok to use this function. 862 * 863 * \errno(OK, ERR_NOMEM) 864 */ 865 866Global_ERWIN_EXPORT 867voidVector_destroy(Vector_t*/*self*/); 868/* 869 * This is for deleting non-heap Vector_t objects. 870 * 871 * Invoking this function manually is usually discouraged. It is thought 872 * to be for nesting data structures. However, if you need to optimise 873 * heap usage, it is ok to use this function. 874 * 875 * \errno(OK) 876 */ 877 878Global_ERWIN_EXPORT 879voidVector_xchg(Vector_t*/*self*/,Vector_t*/*other*/); 880/* 881 * Exchanges the two vectors' contents. No memory allocation is 882 * performed; this is a fast O(1) operation for swapping two values. 883 */ 884 885#if!Global_ERWIN_GLOBAL_ERRNO 886Global_ERWIN_EXPORT 887intVector_errno(Vector_tconst*)ATTR_PUREATTR_NONNULL((1)); 888/* If you compiled Erwin with Global_ERWIN_THREAD_SAFE, this is the way 889 * to get the status code of a given vector. 890 * 891 * If you do not 892 * have a thread-safe Erwin library, there is a macro with the same name as 893 * this function. 894 * 895 * \noerrno 896 */ 897 898Global_ERWIN_EXPORT 899voidVector_clear_errno(Vector_tconst*/*self*/)ATTR_NONNULL((1)); 900/* If you compiled Erwin with Global_ERWIN_THREAD_SAFE, this is the way 901 * to get the status code of a given vector. 902 * 903 * If you do not 904 * have a thread-safe Erwin library, there is a macro with the same name as 905 * this function. 906 * 907 * \errno(OK) 908 */ 909 910#else 911 912#defineVector_errno(X)Global_vector_errno 913/* If you compiled Erwin without Global_ERWIN_THREAD_SAFE, Vector_errno 914 * is just a synonym for Global_vector_errno. 915 * 916 * If you 917 * have a thread-safe Erwin library, there is a function with the same name as 918 * this macro. 919 * 920 * \noerrno 921 */ 922 923#defineVector_clear_errno(X)((void)(Global_map_errno=Global_MAP_OK)) 924/* If the library was not compiled with Global_ERWIN_THREAD_SAFE, Vector_clear_errno(X) 925 * is a small macro that resets the status code to Global_VECTOR_OK. 926 * 927 * If you 928 * have a thread-safe Erwin library, there is a function with the same name as 929 * this macro. 930 * 931 * \errno(OK) 932 */ 933#endif 934 935 936Global_ERWIN_EXPORT 937Vector_t*Vector_copy(Vector_tconst*/*self*/); 938/* Copies a vector with all its elements and returns that copy. 939 */ 940 941Global_ERWIN_EXPORT 942Vector_t*Vector_copy_err(Vector_tconst*/*self*/,int*/*err*/); 943/* Like Vector_copy but sets *\p err to 1 on failure. 944 */ 945 946Global_ERWIN_EXPORT 947intVector_insert_subvector( 948Vector_t*/*self*/, 949Vector_index_t/*start_index_self*/, 950Vector_tconst*/*other*/, 951Vector_index_t/*start_index_other*/, 952Vector_cnt_t/*size*/, 953Global_ERWIN_BOOL/*docopy*/); 954/* Inserts a portion of a vector into another one. If \p size is < 0, it defines 955 * the last element to enter. -1 therefore means: the rest of the vector starting 956 * at \p start_index 957 * 958 * Returns its success. 959 */ 960 961Global_ERWIN_EXPORT 962Vector_t*Vector_subvector( 963Vector_tconst*/*self*/, 964Vector_index_t/*start_index*/, 965Vector_cnt_t/*size*/, 966Global_ERWIN_BOOL/*docopy*/); 967/* Copies only a portion of the vector. The semantics of the parameters is like in 968 * Vector_insert_subvector. */ 969 970Global_ERWIN_EXPORT 971voidVector_delete(Vector_t*/*self*/); 972/* Deletes everything in the vector and the vector structure itself. 973 * Vector_delete is NULL safe (\p self may be NULL without crash or failed 974 * assertion). 975 */ 976 977Global_ERWIN_EXPORT 978voidVector_detach(Vector_t*/*self*/); 979/* Clears the vector by initialising a new completely empty 980 * table not consuming any memory. The effect is mainly that 981 * you can use the value of Vector_as_array and Vector_as_open_array 982 * independently from the vector. The old function 983 * delete_flat is now a sequence of detach() and delete(). 984 * 985 * Note: This function should be used when the vector is not 986 * needed anymore after a cast to a raw array (e.g. by 987 * Vector_as_array). 988 * 989 * Compare this function with Vector_detach_as_is(). These functions 990 * are important to distinguish if you defined Global_oType_UPDATE_POS. 991 * 992 * Note: use Vector_delete_array() to deallocate the memory if you retrieve 993 * it with, say, Vector_as_open_array(). 994 * 995 * Note: See the documentation of Vector_delete_array and Vector INLINE_STORE! 996 */ 997 998#IFEQ(oType,oTypeVar) 999Global_ERWIN_EXPORT1000voidVector_delete_array(Vector_element_ptr_t/*array*/);1001/* If you extract the vector contents e.g. with Vector_as_array(), then1002 * detach a vector to free its contents later, use this function for1003 * freeing. If the memory management is left with its default settings,1004 * this is a simple free() (or delete[] if you compiled for C++ only).1005 * But to be sure to use the right deallocator in more complex cases,1006 * please prefer to use this function.1007 *1008 * Note: With Vector_INLINE_STORE, you *must only* invoke Vector_delete_array1009 * on arrays obtained with Vector_as_array_detach() or1010 * Vector_as_open_array_detach(). You *must not* invoke it1011 * on arrays obtained with Vector_as_array() or Vector_as_open_array()1012 * because these functions may return a pointer to an inlined array,1013 * causing a SIGSEGV in Vector_delete_array().1014 */1015#ENDIF10161017Global_ERWIN_EXPORT1018voidVector_detach_as_is(Vector_t*/*self*/);1019/* Like Vector_detach_as_is(), but does not invoke Global_oType_UPDATE_POS1020 * for all elements to set them to -1.1021 *1022 * This function is only different from Vector_detach if you defined1023 * Global_oType_UPDATE_POS. Otherwise, it is the same.1024 */10251026Global_ERWIN_EXPORT1027intVector_append(Vector_t*/*self*/,oTypeTouched/*value*/);1028/* Appends one elements, namely \p value, to the end of the vector.1029 *1030 * Returns its success.1031 */10321033Global_ERWIN_EXPORT1034oTypeResultVector_zero(Vector_tconst*/* self */)ATTR_PURE;1035/* Returns the zero element of this vector. This need not be the same1036 * for all vectors (you can specify it with Vector_new_with_zero) unless1037 * you defined Vector_CONSTANT_ZERO.1038 */10391040/*BEGIN:IGNORE*/1041#ifdefined(Global_ERWIN_COMPILING)||Vector_ALLOW_OUTOFRANGE||Vector_RANGE_CHECK||Vector_INLINE_STORE1042/*END:IGNORE*/10431044Global_ERWIN_EXPORT1045oTypeResultVector_nth(Vector_tconst*/*self*/,Vector_index_t/*index*/)ATTR_ERRNO_PURE;1046/* Returns the found element or the zero element on failure.1047 * If \p index is out of range, a message is also output to1048 * stderr if you defined Global_ERWIN_VERBOSE.1049 */10501051/*BEGIN:IGNORE*/1052#else1053#defineVector_INLINE__NTH1054#endif1055/*END:IGNORE*/10561057Global_ERWIN_EXPORT1058oTypeResultVector_nth_char(Vector_tconst*/*self*/,Vector_index_t/*index*/)ATTR_ERRNO_PURE;1059/* Returns the found element or the zero element on failure.1060 *1061 * If you access the element just after the end of the vector, then1062 * that is regarded legal in this function and the zero element is1063 * returned.1064 *1065 * If \p index is out of range, a message is also output to1066 * stderr if you defined Global_ERWIN_VERBOSE.1067 *1068 * Dev.Note: this is pure: cmp to Vector_nth_char_ptr and see Vector_as_array().1069 */10701071Global_ERWIN_EXPORT1072oTypeResultVector_first(Vector_tconst*/*self*/)ATTR_ERRNO_PURE;1073/* Returns the first element of the vector.1074 * This is the same as1075 * : Vector_nth (self, 0)1076 */10771078Global_ERWIN_EXPORT1079oTypeResultVector_last(Vector_tconst*/*self*/)ATTR_ERRNO_PURE;1080/* Returns the last element of the vector1081 *1082 * This is the same as1083 * : Vector_nth (self, Vector_nentries (self) - 1)1084 */108510861087Global_ERWIN_EXPORT1088oTypeVarVector_modify(1089Vector_t*/*self*/,Vector_index_t/*index*/,oTypeTouched/*newvalue*/)ATTR_NONNULL((1));1090/* Returns the old value and inserts the new one at \p index.1091 *1092 * Nothing is freed, \p newvalue is copied if oType_OCOPY is #defined.1093 */109410951096Global_ERWIN_EXPORT1097intVector_set(1098Vector_t*/*self*/,Vector_index_t/*index*/,oTypeTouched/*newvalue*/)ATTR_NONNULL((1));1099/* Like Vector_modify, but the old value is freed using oType_OFREE instead1100 * of being returned.1101 *1102 * Returns its success.1103 */11041105Global_ERWIN_EXPORT1106voidVector_swap(1107Vector_t*/*self*/,Vector_index_t/*index1*/,Vector_index_t/*index2*/)ATTR_NONNULL((1));1108/* Because using set or modify to implement swapping of two elements involves1109 * freeing and copying elements, this functions provides a way to swap1110 * elements without that overhead.1111 */11121113Global_ERWIN_EXPORT1114Vector_element_ptr_tVector_nth_ptr(1115Vector_t*/*self*/,Vector_index_t/*index*/)ATTR_NONNULL((1));1116/* Returns a pointer to the element at \p index or NULL if \p index is out of1117 * range.1118 *1119 * Does not output anything to stderr even if you define Global_ERWIN_VERBOSE.1120 *1121 * Dev.Note: not pure with ALLOW_OUTOFRANGE option.1122 */11231124/* Like Vector_nth_ptr, but constant in input and output type.1125 *1126 * Does not output anything to stderr even if you define Global_ERWIN_VERBOSE.1127 *1128 * Dev.Note: not pure with ALLOW_OUTOFRANGE option.1129 */1130ERWIN_STATIC_INLINE1131oTypeconst*Vector_nth_ptr_const(Vector_tconst*self,Vector_index_tidx);11321133ERWIN_STATIC_INLINE1134oTypeconst*Vector_nth_ptr_const(Vector_tconst*self,Vector_index_tidx)1135{1136returnVector_nth_ptr((Vector_t*)self,idx);1137}11381139Global_ERWIN_EXPORT1140Vector_element_ptr_tVector_nth_ptr_check(Vector_t*/*self*/,Vector_index_t/*index*/);1141/* Returns a pointer to the element at \p index or an signals an error if1142 * the \p index is out of range. (This is the same behaviour towards errors1143 * as Vector_nth has)1144 *1145 * Does not output anything to stderr even if you define Global_ERWIN_VERBOSE.1146 *1147 * Dev.Note: not pure with ALLOW_OUTOFRANGE option.1148 */11491150/* Like Vector_nth_ptr_check, but constant in input and output type.1151 *1152 * Does not output anything to stderr even if you define Global_ERWIN_VERBOSE.1153 *1154 * Dev.Note: not pure with ALLOW_OUTOFRANGE option.1155 */1156ERWIN_STATIC_INLINE1157oTypeconst*Vector_nth_ptr_check_const(Vector_tconst*self,Vector_index_tidx);11581159ERWIN_STATIC_INLINE1160oTypeconst*Vector_nth_ptr_check_const(Vector_tconst*self,Vector_index_tidx)1161{1162returnVector_nth_ptr_check((Vector_t*)self,idx);1163}11641165Global_ERWIN_EXPORT1166Vector_element_ptr_tVector_nth_ptr_char(1167Vector_t*/*self*/,Vector_index_t/*index*/)ATTR_NONNULL((1));1168/* Returns a pointer to the element at \p index if it is in range.1169 * If is is one too large, returns a pointer to the element after the end,1170 * mimicking string behaviour. That element is guaranteed to be allocated,1171 * of couse. If you write to that element, it only is guarateed to have1172 * any effect up to the next change to the vector size. Don't change that1173 * element, though.1174 *1175 * Because this function is so similar to adding an integer to a 'char const *',1176 * i.e., to get a suffix string, this function always zero-terminates the1177 * vector like Vector_as_array() does. So Vector_nth_ptr_char(self,0) is1178 * equivalent to Vector_as_array().1179 *1180 * NOTE: This behaves a bit strange together with ALLOW_OUTOFRANGE:1181 * Accesses to any element starting from a[nentries()] make the vector1182 * larger for the non-const version! This includes the nentries()th1183 * element, which, even if only read with this function, enlarges the1184 * vector due to the potential threat of the user writing to it.1185 *1186 * In case ALLOW_OUTOFRANGE is off, this never makes the vector larger,1187 * but does allow access to nentries()th element. That element is always1188 * ensured to be ZERO, however, so you cannot write to it.1189 *1190 * This signals an error if the \p index is out of range.1191 * (This is the some behaviour towards errors as Vector_nth_char has.)1192 *1193 * Does not output anything to stderr even if you define Global_ERWIN_VERBOSE.1194 *1195 * Dev.Note: not pure, see Vector_as_array().1196 */11971198/* Like Vector_nth_ptr_char, but constant in input and output type.1199 *1200 * Note that despite the 'const', this zero-terminates the vector just like1201 * Vector_nth_ptr_char() and Vector_as_array().1202 *1203 * Does not output anything to stderr even if you define Global_ERWIN_VERBOSE.1204 */1205ERWIN_STATIC_INLINE1206oTypeconst*Vector_nth_ptr_char_const(Vector_tconst*self,Vector_index_tidx);12071208ERWIN_STATIC_INLINE1209oTypeconst*Vector_nth_ptr_char_const(Vector_tconst*self,Vector_index_tidx)1210{1211returnVector_nth_ptr_char((Vector_t*)self,idx);1212}12131214Global_ERWIN_EXPORT1215Vector_element_ptr_tVector_first_ptr(Vector_t*/*self*/)ATTR_NONNULL((1));1216/* Returns a pointer to the element at index 0 or NULL if the vector is empty.1217 *1218 * Does not output anything to stderr even if you define Global_ERWIN_VERBOSE.1219 *1220 * Dev.Note: not pure with ALLOW_OUTOFRANGE option.1221 */12221223Global_ERWIN_EXPORT1224Vector_element_ptr_tVector_last_ptr(Vector_t*/*self*/)ATTR_NONNULL((1));1225/* Returns a pointer to the last element or NULL if the vector is empty.1226 *1227 * Does not output anything to stderr even if you define Global_ERWIN_VERBOSE.1228 *1229 * Dev.Note: not pure with ALLOW_OUTOFRANGE option.1230 */12311232Global_ERWIN_EXPORT1233voidVector_reverse(Vector_t*/*self*/);1234/* Reverses the order of all elements in the vector.1235 *1236 * See Vector_swap, too, which is vaguely related.1237 */12381239Global_ERWIN_EXPORT1240intVector_erase(Vector_t*/*self*/,Vector_index_t/*index*/,Vector_cnt_t/*number_of_elements*/);1241/* The values erased from the the vector are freed. If \p number_of_elements1242 * is negative, the end of the vector is cut off. If \p index or1243 * \p number_of_elements are out of range, they are adjusted appropriately.1244 *1245 * E.g.:1246 * - if index == -2 and count == 5:1247 * then elements 0,1,2 are erased,1248 *1249 * - if index >= nentries:1250 * nothing is erased,1251 *1252 * - if index + count >= nentries:1253 * only the tail of the vector is erased.1254 * However, all this is only done if Vector_ALLOW_OUTOFRANGE is true.1255 * Otherwise, you'll get an assertion failure in all these cases,1256 * because index or count are out of range.1257 *1258 * - if count < 0:1259 * then count is adjusted to nelements - index, e.g.1260 * index == 2, count = -1 will cut off the last two elements of1261 * the vector.1262 * (The absolute value of count is not considered here, only the fact1263 * that it is < 0). This adjustment always happens, i.e., even if1264 * Vector_ALLOW_OUTOFRANGE is false.1265 *1266 * Returns its success.1267 *1268 * Reference: Vector_erase_flags, Vector_swap_erase1269 */12701271#IFEQ(oType,oTypeVar)1272Global_ERWIN_EXPORT1273intVector_erase_flags(1274Vector_t*/* self */,1275Vector_index_t/* index */,1276Vector_cnt_t/* number_of_elements_to_delete */,1277Global_ERWIN_BOOL/* resize */,1278Global_ERWIN_BOOL/* delete_elems */);1279/* Like Vector_erase but you can specify whether1280 * - the vector should be re-allocated by \p resize1281 * - elements should be freed by \p delete_elems.1282 *1283 * Returns its success.1284 */1285#ELSE1286Global_ERWIN_EXPORT1287intVector_erase_flags(1288Vector_t*/* self */,1289Vector_index_t/* index */,1290Vector_cnt_t/* number_of_elements_to_delete */,1291Global_ERWIN_BOOL/* resize */);1292/* Like Vector_erase but you can specify whether the vector should be1293 * re-allocated by \p resize.1294 *1295 * Returns its success.1296 */1297#ENDIF12981299Global_ERWIN_EXPORT1300intVector_swap_erase(1301Vector_t*/*self*/,Vector_index_t/*index*/,Vector_cnt_t/*number_of_elements*/);1302/* This is similar to Vector_erase, but instead of shifting all elements after1303 * the ones erased, this functions copies elements from the end of the vector1304 * into the gap. This is faster if \p number_of_elements is small.1305 * The order of the copied elements is reversed.1306 *1307 * Example:1308 *1309 * Vector= [0 1 2 3 4 5 6 7 8 9]1310 * : Vector.swap_erase(2,3) // erases elements 2,3,4 by overwriting with 9,8,71311 * Vector= [0 1 9 8 7 5 6]1312 *1313 * There are more interesting cases, too:1314 *1315 * Vector= [0 1 2 3 4 5 6 7 8 9]1316 * : Vector.swap_erase(4,4) // erases elements 4,5,6,7 by overwriting with 9,81317 * Vector= [0 1 2 3 9 8]1318 *1319 * Returns its success.1320 */13211322#IFEQ(oType,oTypeVar)1323Global_ERWIN_EXPORT1324intVector_swap_erase_flags(1325Vector_t*/* self */,1326Vector_index_t/* index */,1327Vector_cnt_t/* number_of_elements_to_delete */,1328Global_ERWIN_BOOL/* resize */,1329Global_ERWIN_BOOL/* delete_elems */);1330/* Like Vector_swap_erase but you can specify whether1331 * a) the vector should be re-allocated by \p resize1332 * b) elements should be freed by \p delete_elems.1333 *1334 * Returns its success.1335 */1336#ELSE1337Global_ERWIN_EXPORT1338intVector_swap_erase_flags(1339Vector_t*/* self */,1340Vector_index_t/* index */,1341Vector_cnt_t/* number_of_elements_to_delete */,1342Global_ERWIN_BOOL/* resize */);1343/* Like Vector_swap_erase but you can specify whether the vector should be1344 * re-allocated by \p resize.1345 *1346 * Returns its success.1347 */1348#ENDIF13491350Global_ERWIN_EXPORT1351Vector_cnt_tVector_erase_if(1352Vector_t*/*self*/,Vector_feature_t/* feature */,Global_ERWIN_BOOL/*value*/);1353/* Erases those elements that satisfy \p feature. You can specify which1354 * value \p feature must return for the element in order to trigger that1355 * deletion. So if \p value is Global_ERWIN_FALSE, the feature described1356 * by \p feature is negated.1357 *1358 * The values erased from the vector are freed using oType_OFREE.1359 *1360 * Returns the number of elements cut out of the vector.1361 *1362 * Note: In CommonLisp, this is called |remove-if|.1363 */13641365Global_ERWIN_EXPORT1366Vector_cnt_tVector_erase_equals(Vector_t*/*self*/,Vector_cmp_t/*cmp*/,Vector_combine_t/*combine*/);1367/* Erases the second of two adjacent elements that is equal (wrt. the1368 * given function) to the first. This is repeated recursively so that1369 * groups of adjacent equal elements are reduced to one element.1370 *1371 * Before erasing, the function calls back combine to let the user1372 * adjust things (e.g. copy something from the moribund entry to1373 * the surviving one).1374 *1375 * The default cmp function, used if cmp is NULL, is Global_oType_CMP.1376 *1377 * In a sorted vector, this procedure erases all equal elements.1378 *1379 * The values erased from the vector are freed using oType_OFREE.1380 *1381 * The number of erased elements is returned.1382 */13831384Global_ERWIN_EXPORT1385Vector_cnt_tVector_erase_zero(Vector_t*/*self*/);1386/* Specialised version of Vector_erase_if: deletes zero elements. */13871388#IFEQ(oType,oTypeVar)1389Global_ERWIN_EXPORT1390Vector_cnt_tVector_erase_if_flags(1391Vector_t*/*self*/,1392Vector_feature_t/* feature */,1393Global_ERWIN_BOOL/*value*/,1394Global_ERWIN_BOOL/*resize*/,1395Global_ERWIN_BOOL/*dealloc*/);1396/* Additional to Vector_erase_if, you can specify whether to resize the1397 * vector or whether to deallocate the elements that are cut out.1398 *1399 * Returns the number of elements cut out of the vector.1400 */14011402#ELSE1403Global_ERWIN_EXPORT1404Vector_cnt_tVector_erase_if_flags(1405Vector_t*/*self*/,1406Vector_feature_t/* feature */,1407Global_ERWIN_BOOL/*value*/,1408Global_ERWIN_BOOL/*resize*/);1409/* Additional to Vector_erase_if, you can specify whether to resize the1410 * vector.1411 *1412 * Returns the number of elements cut out of the vector.1413 */1414#ENDIF14151416Global_ERWIN_EXPORT1417voidVector_make_heap(Vector_t*/*self*/,Vector_cmp_t/*cmp*/);1418/* This makes a heap. The first element of the vector will then1419 * be the maximum (according to the given compare function).1420 * The others will have the Heap Property:1421 *1422 * : \forall i \in { 0,..,nentries-1 }:1423 * : nth (floor ((i-1) / 2)) >= nth(i)1424 *1425 * The operation takes O(n log n) time.1426 *1427 * This is the heap property graphically:1428 * : 0 n[father(i)] >= n[i], whether father(i) = floor ((i-1) / 2)1429 * : 1 21430 * : 3 4 5 6 // Note that the indeces in our vectors are just the1431 * : // other way around to1432 *1433 * As a special case, a vector that is sorted in reverse order is a heap.1434 *1435 * The default cmp function, used if cmp is NULL, is Global_oType_PRIORITY_CMP.1436 *1437 * NOTE:1438 * The implementation used here has no dedicated heap_size entry.1439 * The heap is always as large as the whole vector.1440 *1441 * This function checks itself when in debug mode, causing assertion failures1442 * if the heap property is violated after operation.1443 */14441445Global_ERWIN_EXPORT1446Vector_index_tVector_heap_left(Vector_tconst*/*self*/,Vector_index_t/*i*/)ATTR_PURE;1447/* Returns the index of the left child of i in a heap structure.1448 * The index i must be a valid index of the vector.1449 * Returns something < 0 if there is no such child of i.1450 * The left index is guaranteed to be < than the right index.1451 *1452 * The operation takes O(1) time.1453 */14541455Global_ERWIN_EXPORT1456Vector_index_tVector_heap_right(Vector_tconst*/*self*/,Vector_index_t/*i*/)ATTR_PURE;1457/* Returns the index of the left child of i in a heap structure.1458 * The index i must be a valid index of the vector.1459 * Returns something < 0 if there is no such child of i.1460 * The right index is guaranteed to be > than the left index.1461 *1462 * The operation takes O(1) time.1463 */14641465Global_ERWIN_EXPORT1466Vector_index_tVector_heap_father(Vector_tconst*/*self*/,Vector_index_t/*i*/)ATTR_PURE;1467/* Returns the index of the left child of i in a heap structure.1468 * The index i must be a valid index of the vector.1469 * Returns something < 0 if i does not have a father, i.e., if i == 0.1470 *1471 * The operation takes O(1) time.1472 */14731474Global_ERWIN_EXPORT1475oTypeVarVector_heap_extract(Vector_t*/*self*/,Vector_cmp_t/*cmp*/)ATTR_NONNULL((1));1476/* This extracts the maximum from the heap, returns it, shrinks the1477 * vector, and re-heapifies it. See Vector_make_heap()1478 * and Vector_heap_sink(). You may only invoke this for vectors that1479 * have the heap property and have at least one element.1480 *1481 * The operation takes O(log n) time, since it reinvokes Vector_heap_sink.1482 *1483 * The default cmp function, used if cmp is NULL, is Global_oType_PRIORITY_CMP.1484 *1485 * This function checks the input and itself when in debug mode, causing1486 * assertion failures if the heap property is violated.1487 * Note that this check takes O(n) time, so the function is significantly1488 * slower during debugging. If you don't want this, you may1489 *1490 * : #define Vector_DEBUG_EXPENSIVE_CHECKS 01491 * or (for all vectors)1492 * : #define Global_VECTOR_DEBUG_EXPENSIVE_CHECKS 01493 *1494 * Note: this returns oTypeVar instead of oTypeResult (if these are different),1495 * because the element is removed, so no reference can be returned.1496 */14971498Global_ERWIN_EXPORT1499voidVector_heap_raise(1500Vector_t*/*self*/,Vector_index_t/*i*/,Vector_cmp_t/*cmp*/)ATTR_NONNULL((1));1501/* The operation checks for element i whether its priority has increased.1502 * it so, the heap property is re-established.1503 *1504 * The operation takes O(log n) time.1505 *1506 * The default cmp function, used if cmp is NULL, is Global_oType_PRIORITY_CMP.1507 *1508 * This function checks itself when in debug mode, causing1509 * assertion failures if the heap property is violated after operation.1510 * Such an assertion failure may also mean that the vector was no1511 * heap (apart from the element i) before this operation.1512 * Note that this check takes O(n) time, so the function is significantly1513 * slower during debugging. If you don't want this, you may1514 *1515 * : #define Vector_DEBUG_EXPENSIVE_CHECKS 01516 * or (for all vectors)1517 * : #define Global_VECTOR_DEBUG_EXPENSIVE_CHECKS 01518 */15191520Global_ERWIN_EXPORT1521voidVector_heap_sink(1522Vector_t*/*self*/,Vector_index_t/*i*/,Vector_cmp_t/*cmp*/)ATTR_NONNULL((1));1523/* The opposite of Vector_heap_raise: it checks whether the value of i1524 * has decresed and if so, re-establishes the heap property.1525 *1526 * This operation is often called 'heapify'. Because it is related to1527 * heap_raise by being its opposite, we'll call it heap_sink here.1528 *1529 * The operation takes O(log n) time.1530 *1531 * The default cmp function, used if cmp is NULL, is Global_oType_PRIORITY_CMP.1532 *1533 * See Vector_heap_raise() for more info.1534 *1535 * Note that this function does not do debug checks of the heap property,1536 * because it may be used to construct a heap, so one of its purposes is to1537 * be invoked on heaps. We might add a check for a partial heap property1538 * later, though.1539 */15401541Global_ERWIN_EXPORT1542voidVector_heap_fix(1543Vector_t*/*self*/,Vector_index_t/*i*/,Vector_cmp_t/*cmp*/)ATTR_NONNULL((1));1544/* Fix the position of element at index i according to its new priority.1545 *1546 * The operation takes O(log n) time.1547 *1548 * The default cmp function, used if cmp is NULL, is Global_oType_PRIORITY_CMP.1549 *1550 * This is an abbreviation for:1551 * : Vector_heap_raise (self, i, cmp);1552 * : Vector_heap_sink (self, i, cmp);1553 */15541555Global_ERWIN_EXPORT1556intVector_heap_insert(1557Vector_t*/*self*/,oTypeParam/*elem*/,Vector_cmp_t/*cmp*/)ATTR_NONNULL((1));1558/* This function inserts an element into a heap and re-establishes the1559 * heap property.1560 *1561 * This operation is an abbreviation for:1562 * : Vector_append (self, elem);1563 * : Vector_heap_increase (self, Vector_nentries(s) - 1, cmp);1564 *1565 * Thus the operation takes O(log n) time.1566 *1567 * The default cmp function, used if cmp is NULL, is Global_oType_PRIORITY_CMP.1568 *1569 * The success is returned.1570 *1571 * This function checks the input (and itself indirectly via Vector_heap_raise) when1572 * in debug mode, causing assertion failures if the heap property is violated.1573 * Note that this check takes O(n) time, so the function is significantly1574 * slower during debugging. If you don't want this, you may1575 *1576 * : #define Vector_DEBUG_EXPENSIVE_CHECKS 01577 * or (for all vectors):1578 * : #define Global_VECTOR_DEBUG_EXPENSIVE_CHECKS 01579 */15801581Global_ERWIN_EXPORT1582voidVector_heap_erase(1583Vector_t*/*self*/,Vector_index_t/*i*/,Vector_cmp_t/*cmp*/)ATTR_NONNULL((1));1584/* This function deletes an element from the heap and re-establishes the1585 * heap property.1586 *1587 * This operation is an abbreviation for:1588 * : Vector_swap (self, i, Vector_nentries(s) - 1);1589 * : Vector_chop (self, 1);1590 * : Vector_heap_sink (self, i, cmp);1591 *1592 * Thus the operation takes O(log n) time.1593 *1594 * The default cmp function, used if cmp is NULL, is Global_oType_PRIORITY_CMP.1595 *1596 * The success is returned.1597 *1598 * This function checks the input (and itself indirectly via Vector_heap_raise) when1599 * in debug mode, causing assertion failures if the heap property is violated.1600 * Note that this check takes O(n) time, so the function is significantly1601 * slower during debugging. If you don't want this, you may1602 *1603 * : #define Vector_DEBUG_EXPENSIVE_CHECKS 01604 * or (for all vectors)1605 * : #define Global_VECTOR_DEBUG_EXPENSIVE_CHECKS 01606 */16071608Global_ERWIN_EXPORT1609voidVector_heap_sort(Vector_t*/*self*/,Vector_cmp_t/*cmp*/);1610/* Re-builds the heap structure for the given element.1611 * This is one of three sort functions available for vectors:1612 *1613 * +------------------+------------+------------+------------+---------+-------------+1614 * |! Function |! Algorithm |! Typical |! Worst |! Space |! Stability |1615 * | Vector_qsort | Quicksort | O(n log n) | O(n) | O(1) | not stable |1616 * | Vector_heap_sort | Heapsort | O(n log n) | O(n log n) | O(1) | not stable |1617 * | Vector_sort | Mergesort | O(n log n) | O(n log n) | O(n) | stable |1618 * +------------------+------------+------------+------------+---------+-------------+1619 *1620 * The default cmp function, used if cmp is NULL, is Global_oType_PRIORITY_CMP.1621 *1622 * NOTE: This uses a different comparison function by default. Just in case1623 * you defined it (or differently)...1624 *1625 * FIXME: We should implement bubblesort as well, since it is very fast if1626 * only few elements have changed.1627 *1628 * The operation takes O(n log n) time.1629 */16301631Global_ERWIN_EXPORT1632intVector_priority_cmp(Vector_tconst*,Vector_tconst*,Vector_cmp_t/*cmp*/);1633/* Similar to Vector_cmp, with two differences:1634 * - it uses Global_oType_PRIORITY_CMP as its default comparison1635 * function1636 * - it uses lexical ordering as its default, unless you define1637 * Vector_PRIORITY_COMPARE_LEXICOGRAPHICALLY to 0.1638 *1639 * This function is NULL safe. NULL is smaller than any1640 * other vector.1641 *1642 * If cmp is NULL, Global_oType_PRIORITY_CMP will be used. If that is not1643 * defined, an error will occur.1644 */16451646Global_ERWIN_EXPORT1647intVector_chop(Vector_t*/*self*/,Vector_cnt_t/*count*/);1648/* Cuts off the last \p count elements of a vector.1649 *1650 * This is actually nothing more than an abbreviation for:1651 * : (Assert that count is >= 0)1652 * : Vector_erase(self, Vector_nentries(self)-count, count);1653 *1654 * This functions generates an assertion failure if the number of1655 * elements to chop is greater than the number of elements in the1656 * vector. However, if Vector_ALLOW_OUTOFRANGE is true, then1657 * this operation simply clears the vector without assertion failure1658 * in this case.1659 *1660 * Due to the fact that the equivalent using Vector_swap_erase is1661 * very trivial: Vector_swap_erase (self, 0, 1), there is no1662 * Vector_swap_chop() in C (but in C++, we still have it).1663 *1664 * Returns its success.1665 */16661667#IFEQ(oType,oTypeVar)1668Global_ERWIN_EXPORT1669intVector_chop_flags(1670Vector_t*/* self */,1671Vector_cnt_t/* count */,1672Global_ERWIN_BOOL/* resize */,1673Global_ERWIN_BOOL/* delete_elems */);1674/* Like Vector_chop you can specify the deallocation behaviour.1675 *1676 * Returns its success.1677 */1678#ELSE1679Global_ERWIN_EXPORT1680intVector_chop_flags(1681Vector_t*/* self */,1682Vector_cnt_t/* number_of_elements_to_erase_off */,1683Global_ERWIN_BOOL/* resize */);1684/* Like Vector_chop you can specify the deallocation behaviour.1685 *1686 * Returns its success.1687 */1688#ENDIF16891690Global_ERWIN_EXPORT1691oTypeVarVector_last_chop1(Vector_t*/*self*/)ATTR_NONNULL((1));1692/* Cuts off the last element of the vector and returns it.1693 * Like a pop on a stack.1694 */16951696Global_ERWIN_EXPORT1697oTypeVarVector_first_swap_chop1(Vector_t*/*self*/)ATTR_NONNULL((1));1698/* Cuts off the first element of the vector like Vector_swap_erase()1699 * and returns it. This is like Vector_heap_extract() without1700 * heap_sink().1701 */17021703Global_ERWIN_EXPORT1704intVector_append_raw(1705Vector_t*/*self*/,1706oTypeconst*/*elements*/,1707Vector_cnt_t/*count*/)ATTR_NONNULL((1));1708/* Append \p count elements to the end of the vector.1709 *1710 * This is a frontend to Vector_insert_raw which lets you specify an insertion1711 * position.1712 *1713 * Returns its success.1714 */17151716Global_ERWIN_EXPORT1717intVector_append_no_copy(1718Vector_t*/* self */,1719oTypeVarconst*/* theelements */,1720Vector_cnt_t/* number_of_elements_to_insert*/)ATTR_NONNULL((1));1721/* Like Vector_append_raw, but the data is not copyied.1722 *1723 * Returns its success.1724 */17251726Global_ERWIN_EXPORT1727intVector_append_vector(1728Vector_t*/* self */,1729Vector_tconst*/* other */)ATTR_NONNULL((1));1730/* Append a whole \p other vector at the end of the vector \p self.1731 *1732 * This is a frontend to Vector_insert.1733 *1734 * Returns its success.1735 */17361737Global_ERWIN_EXPORT1738intVector_append_string(1739Vector_t*/*self*/,1740oTypeconst*/*theelements*/)ATTR_NONNULL((1));1741/* Like Vector_append_raw, but with a zero-terminated string instead of a1742 * number of elements. The null-termination will *not* be copied.1743 *1744 * Returns its success.1745 */174617471748Global_ERWIN_EXPORT1749intVector_make_gap(1750Vector_t*/*self*/,1751Vector_index_t/* start_index*/,1752Vector_cnt_t/* count */);1753/* Inserts \p count zero elements into the vector at position \p start_index.1754 *1755 * Returns its success.1756 */17571758Global_ERWIN_EXPORT1759intVector_make_gap_with(1760Vector_t*/*self*/,1761Vector_index_t/* start_index*/,1762oTypeTouched/* elem */,1763Vector_cnt_t/* count */);1764/* Like Vector_make_gap but with a given value (which is copied for1765 * each entry if necessary.1766 */176717681769Global_ERWIN_EXPORT1770intVector_overwrite_raw(1771Vector_t*/* self*/,1772Vector_index_t/* start_index_in_self */,1773oTypeconst*/* newdata*/,1774Vector_cnt_t/* count */);1775/* Overwrites portions of the vector from a normal array.1776 * The overwritten data is freed using oType_OFREE in the old vector and1777 * the new data copied from the new data array using oType_OCOPY.1778 *1779 * Returns its success.1780 */17811782#IFEQ(oType,oTypeVar)1783Global_ERWIN_EXPORT1784intVector_overwrite_flags(1785Vector_t*/* self */,1786Vector_index_t/* start_index */,1787oTypeconst*/* values */,1788Vector_cnt_t/* count */,1789Global_ERWIN_BOOL/* copy_elements */,1790Global_ERWIN_BOOL/* delete_overwritten_elements */);1791/* Like Vector_overwrite_raw but you can further specify its1792 * (de-)allocation behaviour.1793 *1794 * Returns its success.1795 */1796#ENDIF17971798Global_ERWIN_EXPORT1799intVector_overwrite_string(Vector_t*/* self*/,1800Vector_index_t/* start_index_in_self */,1801oTypeconst*/* newdata*/);1802/* Overwrites portions of the vector from a normal array.1803 * Like Vector_overwrite_raw but with a zero-terminated string.1804 *1805 * Returns its success.1806 */18071808Global_ERWIN_EXPORT1809intVector_overwrite_vector(1810Vector_t*/* self*/,1811Vector_index_t/* start_index_in_self */,1812Vector_tconst*/* newdata*/);1813/* Overwrites portions of the vector from a vector. Like1814 * Vector_overwrite_raw but takes its data from another vector.1815 *1816 * Returns its success.1817 */18181819Global_ERWIN_EXPORT1820intVector_overwrite(1821Vector_t*/* self*/,1822Vector_index_t/* start_index_in_self */,1823Vector_tconst*/* newdata*/,1824Vector_index_t/* start_index_in_initial */,1825Vector_cnt_t/* max_count */);1826/* Each element is copied using Global_oType_OCOPY, the old contents are deleted1827 * with Global_oType_OFREE. This overwrites maximally max_count elements from1828 * initial to self starting at position start_index_in* in the two1829 * vectors.1830 *1831 * This is a frontend to Vector_overwrite_raw.1832 *1833 * Returns its success.1834 */18351836Global_ERWIN_EXPORT1837intVector_insert(1838Vector_t*/* self */,1839Vector_index_t/* index */,1840oTypeTouched/* element */)ATTR_NONNULL((1));1841/* Inserts one \p element at position \p index.1842 *1843 * Possible values for \p index are 0...Vector_nentries(self) both1844 * inclusive.1845 *1846 * Returns its success.1847 */18481849Global_ERWIN_EXPORT1850intVector_insert_raw(1851Vector_t*/* self */,1852Vector_index_t/* index */,1853oTypeconst*/* values */,1854Vector_cnt_t/* count */);1855/* Inserts elements from an open array whose size is given by \p count.1856 * In all other aspects it works just like Vector_insert_vector.1857 */18581859Global_ERWIN_EXPORT1860intVector_insert_no_copy(1861Vector_t*/* self */,1862Vector_index_t/* index */,1863oTypeVarconst*/* values */,1864Vector_cnt_t/* count */);1865/* Like Vector_insert_raw but does not copy the given data.1866 */18671868Global_ERWIN_EXPORT1869intVector_insert_string(1870Vector_t*/* self */,1871Vector_index_t/* start_index */,1872oTypeconst*/* values */)ATTR_NONNULL((1));1873/* Inserts a zero-terminated string into the vector.1874 *1875 * In all other aspects it works just like Vector_insert_vector.1876 */18771878Global_ERWIN_EXPORT1879intVector_insert_vector(1880Vector_t*/*self*/,1881Vector_index_t/* start_index */,1882Vector_tconst*/*initial*/);1883/*1884 * Each element is copied using Global_oType_OCOPY.1885 *1886 * This is a simple frontend to Vector_make_gap and Vector_overwrite.1887 * To insert only portions of the initial vector, use these functions1888 * directly.1889 *1890 * Possible values for \p index are 0...Vector_nentries(self) both1891 * inclusive.1892 *1893 * Returns its success.1894 */189518961897Global_ERWIN_EXPORT1898Vector_cnt_tVector_string_length(1899Vector_tconst*/* self */,oTypeconst*/* string */)ATTR_PURE;1900/* Find out the string length of the given zero-terminated \p string.1901 *1902 * The zero element is taken from the vector. This does not modify1903 * the vector at all, nor does it look at the vector's elements. It1904 * only gets the zero element from the vector.1905 */190619071908Global_ERWIN_EXPORT1909intVector_ensure_size(Vector_t*/*self*/,Vector_cnt_t/*size*/)ATTR_NONNULL((1));1910/* Possibly enlarges the vector by appending null elements.1911 *1912 * This is more than Vector_ensure_table_size, since the vector gets the given1913 * size with zero-initialised elements at the tail if necessary.1914 *1915 * Returns its success.1916 */19171918Global_ERWIN_EXPORT1919intVector_ensure_size_with(1920Vector_t*/*self*/,Vector_cnt_t/*size*/,oTypeTouched/*elem*/)ATTR_NONNULL((1));1921/* Possibly enlarges the vector by appending the given elements.1922 *1923 * This is similar to Vector_ensure_size, but you can define with which element1924 * the vector will be filled when grown.1925 *1926 * Returns its success.1927 */19281929Global_ERWIN_EXPORT1930intVector_set_size(Vector_t*/*self*/,Vector_cnt_t/*size*/);1931/* Set the vector size (by shrinking or enlarging and filling with1932 * null elements).1933 *1934 * *Note* that the function will never resize the vector smaller1935 * than Vector_MINIMAL_SIZE (actually, no function will do that).1936 *1937 * Returns its success.1938 */19391940Global_ERWIN_EXPORT1941intVector_set_size_with(Vector_t*/*self*/,Vector_cnt_t/*size*/,oTypeTouched/*elem*/);1942/* Set the vector size (by shrinking or enlarging and filling with1943 * the given elements).1944 *1945 * This is similar to Vector_set_size, but you can define with which element1946 * the vector will be filled when grown.1947 *1948 * Returns its success.1949 */19501951Global_ERWIN_EXPORT1952intVector_set_size_no_resize(Vector_t*/*self*/,Vector_cnt_t/*size*/);1953/* Set the vector size (by shrinking or enlarging and filling with1954 * null elements). When shrinking, no resizing of the table will1955 * be done.1956 *1957 * Returns its success.1958 */19591960Global_ERWIN_EXPORT1961intVector_set_size_raw(Vector_t*/*self*/,Vector_cnt_t/*size*/);1962/* Set the vector size by shrinking or enlarging without, resizing,1963 * deallocation and without filling with null elements.1964 *1965 * This function similar to Vector_set_size_no_resize: when shrinking,1966 * no resizing will be done. Further, this function does not free1967 * any elements during shrinking, so that the elements up to the1968 * allocation size will remain in memory unmodified. When enlarging1969 * the vector up to the allocation size, this function will1970 * not initialise the data.1971 *1972 * This function is useful if you want to temporarily hide elements1973 * at the end of the vector. E.g. when handling heaps where1974 * the vector size is different from the heap size.1975 * See Vector_make_heap.1976 *1977 * BE CAREFUL: if you use this function to shrink the vector, and then1978 * use it to enlarge the vector to a size greater than1979 * the original size, then there will be uninitialised1980 * elements. Basic initialisation (constructor invocation)1981 * is performed when the vector needs to be reallocated1982 * to enlarged it, however. But no null element is ever1983 * written by this function.1984 *1985 * Returns its success.1986 */19871988Global_ERWIN_EXPORT1989voidVector_shrink(Vector_t*/*self*/,Global_ERWIN_BOOL/* tight */);1990/* Perform a table shrink operation if necessary. Mostly useful1991 * if Vector_NO_AUTO_SHRINK is set, otherwise, this function is1992 * automatically invoked whenever the vector shrinks.1993 *1994 * If \p tight is not Global_ERWIN_FALSE, the vector is reallocated to the1995 * absolute minimum that is necessary to store the data. Otherwise,1996 * the standard algorithm of halving chunks is used.1997 *1998 * *Note* that the function will never resize the vector smaller1999 * than Vector_MINIMAL_SIZE (actually, no function will do that).2000 *2001 * If Vector_MINIMAL_SIZE == 0, and if you invoke this function2002 * on an empty vector, the vector will not use any allocated2003 * internal structure anymore until you insert anything.2004 *2005 * When Vector_LOW_MEM is active, this functions has no operation, since the2006 * table size cannot be changed independently from the size.2007 *2008 * *Note* that calling Vector_as_array() on a shrinked2009 * vector is not wise since the vector will have to resize for2010 * the padded zero element.2011 *2012 * Note: This function is always successful. Even if realloc2013 * failed, the vector is still consistent. Therefore, no2014 * error code is returned. However, the error code is2015 * set up correctly.2016 *2017 * Further Note: If you defined memory overflow errors to be2018 * fatal (by #define Global_ERWIN_NOMEM_IS_FATAL), they are also2019 * fatal in this function.2020 */20212022Global_ERWIN_EXPORT2023intVector_ensure_table_size(Vector_t*/*self*/,Vector_cnt_t/*size*/)ATTR_NONNULL((1));2024/* Pre-allocates vector elements. To be used when you know some good2025 * upper approximation to the expected number of elements which will be2026 * inserted in the future. Does not change the contents of the vector.2027 *2028 * To set a minimal size for the vector by appending zero elements,2029 * use Vector_ensure_size.2030 *2031 * When Vector_LOW_MEM is active, this functions has no operation, since the2032 * table size cannot be changed independently from the size.2033 *2034 * Returns its success.2035 */20362037Global_ERWIN_EXPORT2038Vector_element_ptr_tVector_as_array(Vector_tconst*);2039/* returns a pointer to the string the vector is stored in. The string2040 * is terminated with a zero element (usually Global_oType_ZERO, but this2041 * can be changed by using Vector_new_with_zero).2042 *2043 * Note: For convenience, this takes a const pointer although the2044 * representation (but not the contained data) might be changed. It only2045 * changes things outside the user view (behind the end of the vector).2046 *2047 * Further note that NULL is ok, NULL is returned, regardless of Vector_ALLOW_NULL.2048 *2049 * When Vector_INLINE_STORE is active, the returned pointer may become2050 * invalid when you invoke Vector_detach or Vector_detach_as_is. Use2051 * Vector_as_array_detach() in that case (you cannot split that operation2052 * in this case).2053 *2054 * Developer's Note: this functions is not __pure__: it may change the2055 * internal structure, and thus the result of table_size() and2056 * has_heap_storage() etc.2057 */20582059Global_ERWIN_EXPORT2060Vector_element_ptr_tVector_as_open_array(Vector_tconst*)ATTR_ERRNO_PURE;2061/* Same as Vector_as_array, but without the guaranteed zero element.2062 * This is sometimes faster and /never/ resizes the vector.2063 *2064 * Note: If Vector_MINIMAL_SIZE is 0 and the vector has size 0, this2065 * function might return NULL instead of an allocated array!2066 * This is because the function will never try to reallocate.2067 *2068 * When Vector_INLINE_STORE is active, the returned pointer may become2069 * invalid when you invoke Vector_detach or Vector_detach_as_is. Use2070 * Vector_as_array_detach() in that case (you cannot split that operation2071 * in this case).2072 */20732074Global_ERWIN_EXPORT2075Vector_element_ptr_tVector_as_array_detach(Vector_t*);2076/* Like Vector_as_array() followed by Vector_detach() with the difference2077 * that this also works when Vector_INLINE_STORE is active.2078 */20792080Global_ERWIN_EXPORT2081voidVector_ensure_heap_storage(Vector_t*)ATTR_NONNULL((1));2082/* Ensure that the contents are stored on the heap so that _detach2083 * does not destroy the vector. Used by Vector_as_array_detach(), but2084 * may also be used manually before as_array() or Vector_nth_ptr() to2085 * ensure that the pointer is on the heap.2086 *2087 * This function actually does something only when Vector_INLINE_STORE2088 * is used or Vector_MINIMAL_SIZE is 0. Otherwise, this function does2089 * nothing. This includes not doing any harm.2090 *2091 * Note: With both LOW_MEM and INLINE_STORE active, this functions may2092 * append ZERO elements to the vector, because resizing the table2093 * may mean to resize the vector.2094 *2095 * Note: With Vector_MINIMAL_SIZE == 0, vectors of size 0 are still *not*2096 * resized to size 1.2097 * Functions returning pointers to the table (e.g. Vector_as_open_array)2098 * will return NULL in this special case, which is ususally no problem2099 * in handling.2100 * This function is for handling the more complex cases that occur with2101 * the Vector_INLINE_STORE option.2102 */21032104Global_ERWIN_EXPORT2105Global_ERWIN_BOOLVector_has_heap_storage(Vector_tconst*)ATTR_PURE;2106/* Returns whether the storage on the heap is allocated or not.2107 * This is interesting only when Vector_MINIMIAL_SIZE == 0 or2108 * Vector_INLINE_STORE is activated.2109 */21102111Global_ERWIN_EXPORT2112Vector_cnt_tVector_inline_store_cnt(void)ATTR_PURE;2113/* Returns the number of elements the inline store has.2114 * This is 0 unless Vector_INLINE_STORE is activated, in which case other2115 * values are possible. The result is a constant, therefore there is no2116 * argument to this function.2117 */21182119Global_ERWIN_EXPORT2120Vector_element_ptr_tVector_as_open_array_detach(Vector_t*);2121/* Like Vector_as_open_array() followed by Vector_detach() with the difference2122 * that this also works when Vector_INLINE_STORE is active.2123 */21242125Global_ERWIN_EXPORT2126voidVector_qsort(Vector_t*,Vector_cmp_t/*order*/);2127/* Uses the \p order function to sort the vector. The compare function may be NULL2128 * if Global_oType_CMP is defined. In this case that default compare function2129 * is used. See Vector_u.h for definition.2130 *2131 * For a stable sort function, see Vector_sort.2132 *2133 * For a guaranteed O(n log n) runtime and O(1) space, see Vector_heap_sort.2134 *2135 * The default cmp function, used if cmp is NULL, is Global_oType_CMP.2136 *2137 * This function the CLib function qsort(3). Note that qsort(3) need not2138 * use Quicksort internally, e.g. if the glibc under Linux finds that there2139 * is enough memory, it uses merge sort instead. So you have good chances2140 * that this function is stable *in many cases under Linux*. However, if you2141 * need stability, this function does not guarantee that. Especially, when2142 * running your programm under Windows, its qsort(3) implementation is *not*2143 * stable. That's perfectly ok. For stability, simply always use2144 * Vector_sort().2145 *2146 * In sorted vectors, you can find entries in O(log n) vector using2147 * Vector_bfind or Vector_locate.2148 */21492150Global_ERWIN_EXPORT2151voidVector_sort(Vector_t*,Vector_cmp_t/*order*/);2152/* Uses Global_erwin_merge_sort, which implements a stable sorting algorithm.2153 * Uses the \p order function. \p order may be NULL (see Vector_qsort and2154 * Vector_heap_sort) if Global_oType_CMP is defined, which will then be used.2155 *2156 * The default cmp function, used if cmp is NULL, is Global_oType_CMP.2157 *2158 * Uses Erwin's erwin_merge_sort function which is stable but needs O(n) space.2159 *2160 * You can find entries in a sorted vector using Vector_bfind or Vector_locate.2161 */21622163Global_ERWIN_EXPORT2164Vector_index_tVector_bfind(Vector_tconst*,oTypeParam,Vector_cmp_t);2165/* Needs a sorted vector. Then searches with binary search. Uses the cmp function.2166 * cmp may be NULL (see above)2167 * -1 means: not found.2168 *2169 * Uses the system function bsearch().2170 *2171 * This operation takes O(log n) time.2172 *2173 * The default cmp function, used if cmp is NULL, is Global_oType_CMP.2174 *2175 * This function checks the input when in debug mode, causing assertion2176 * failures if input is not sorted.the heap property is violated after operation.2177 * Note that this check takes O(n) time, so the function is significantly2178 * slower during debugging. If you don't want this, you may2179 *2180 * #define Vector_DEBUG_EXPENSIVE_CHECKS 02181 * or #define Global_VECTOR_DEBUG_EXPENSIVE_CHECKS 0 (for all vectors)2182 *2183 * References2184 * ~~~~~~~~~~2185 * Vector_qsort, Vector_sort, Vector_locate, Vector_find.2186 */21872188Global_ERWIN_EXPORT2189Global_ERWIN_BOOLVector_locate(2190Vector_index_t*/*index*/,2191Vector_tconst*/*self*/,2192oTypeParam/*needle*/,2193Vector_cmp_t/*order*/,2194int/* how */);2195/* Needs a sorted vector. Then searches with binary search. Uses the cmp function.2196 * cmp may be NULL (see above)2197 *2198 * In contrast to Vector_bfind you are provided with a possible2199 * insertion position that will keep the vector's order.2200 *2201 * The function returns Global_ERWIN_TRUE if the element was found and Global_ERWIN_FALSE if not.2202 *2203 * This operation takes O(log n) time.2204 *2205 * The default cmp function, used if cmp is NULL, is Global_oType_CMP.2206 *2207 * This function checks the input when in debug mode, causing assertion2208 * failures if input is not sorted.the heap property is violated after operation.2209 * Chis check takes O(n) time, so the function is significantly slower2210 * during debugging. If you don't want this, you may2211 *2212 * #define Vector_DEBUG_EXPENSIVE_CHECKS 02213 * or #define Global_VECTOR_DEBUG_EXPENSIVE_CHECKS 0 (for all vectors)2214 *2215 * The \p how argument defines what value to return for the *\p index. The following table2216 * give an explanation of the value written into *\p index:2217 *2218 * +---------+------------------------+------------------------+-----------------------+2219 * |! \p how |! if found (result == |! if not found (result |! usage |2220 * | | Global_ERWIN_TRUE) | == Global_ERWIN_FALSE | |2221 * +---------+------------------------+------------------------+-----------------------+2222 * | -1 | the smallest index | insertion position | to find an element or |2223 * | | of equal elements | | to insert an element |2224 * | | | | at the smallest |2225 * | | | | possible position |2226 * +---------+------------------------+------------------------+-----------------------+2227 * | 0 | some index of an equal | insertion position | to find and insert |2228 * | | element | | without caring about |2229 * | | | | order of equal |2230 * | | | | elements |2231 * +---------+------------------------+------------------------+-----------------------+2232 * | 1 | the largest index of | insertion position - 1 | to find an element or |2233 * | | equal elements | | to insert an element |2234 * | | | | at the largest |2235 * | | | | possible position. |2236 * +---------+------------------------+------------------------+-----------------------+2237 *2238 * At first sight, for \p how==1 the value of \p index seems strange. But from the point of2239 * view of inserting even in case of equality, you can simply insert at (*\p index+1) to2240 * insert at the right most possible position keeping the vector's order without looking at2241 * the function's return value. However, in case of finding the element, *\p index always2242 * points to an equal element. Note that because of this, \p index may be -1 (for \p how=12243 * if you want to insert at the beginning).2244 *2245 * Note: for \p how==0 and \p how==-1, the functions will set *\p index to2246 * Vector_nentries(self) if the searched element is larger than any in the vector,2247 * because that is the correct value for Vector_insert.2248 *2249 * Summarized constraints that always hold:2250 *2251 * +-------------------------------------+------------------------------------------+2252 * | for \p how==0 and \p how==-1 | *\p index always is the correct |2253 * | | insertion position. |2254 * +-------------------------------------+------------------------------------------+2255 * | for \p how==1 | (*\p index + 1) always is the correct |2256 * | | insert position. |2257 * +-------------------------------------+------------------------------------------+2258 * | if the return value is | *\p index points to an equal element. |2259 * | Global_ERWIN_TRUE | |2260 * +-------------------------------------+------------------------------------------+2261 *2262 * References2263 * ~~~~~~~~~~2264 * Vector_qsort, Vector_sort, Vector_bfind.2265 */22662267/* ***** iteration: ***** */2268/* New approach: */2269#defineVector_forall(v,i,h)\2270for(Vector_init_iterator((v),&(i));\2271Vector_next_iteration((v),&(i),&(h));/*nix*/)2272/* Iteration operator for vectors. Iterates over all indices and values starting at index 02273 * and incrementing \p i by 1 in each iteration. In constrast to maps, you do not need an2274 * iterator (the index is used as an iterator).2275 *2276 * In C++, use vector_forall.2277 *2278 * Iterators are nestable without restriction (even on the same vector).2279 * During iteration, the vector may not be changed.2280 * If you use C++, the *_copy and *_sorted iterators allow changing during iteration.2281 *2282 * You may freely use break and continue in the loop.2283 *2284 * : int i;2285 * : char *s;2286 * : vector_char_p_forall (v, i, s) {2287 * : printf ("v[%d]=%s\n", i, s);2288 * : }2289 */22902291#defineVector_forall_ptr(v,i,h)for(Vector_init_iterator(v,&(i));Vector_next_iteration_ptr(v,&(i),&(h));/*nix*/)2292/* Iteration operator for vectors. Iterates over all indices and pointers to values starting at2293 * index 0. In contrast to Vector_forall this macro can be used to change the values due to2294 * the pointer iteration. */22952296#defineVector_forall_ptr_const(v,i,h)for(Vector_init_iterator(v,&(i));Vector_next_iteration_ptr_const(v,&(i),&(h));/*nix*/)22972298#defineVector_forall_reverse(v,i,h)for(Vector_init_iterator_reverse(v,&(i));Vector_next_iteration_reverse(v,&(i),&(h));/*nix*/)2299/* Iterator operator for reversed order, i.e., starting at index Vector_nentries()-1 and2300 * decrementing \p i downto 0. See Vector_forall for details.2301 */23022303#defineVector_forall_ptr_reverse(v,i,h)for(Vector_init_iterator_reverse(v,&(i));Vector_next_iteration_ptr_reverse(v,&(i),&(h));/*nix*/)2304/* Iterator operator for reversed order, i.e., starting at index Vector_nentries()-1 and2305 * decrementing \p i downto 0. See Vector_forall, Vector_forall_reverse and2306 * Vector_forall_ptr for details.2307 */23082309#defineVector_forall_ptr_const_reverse(v,i,h)for(Vector_init_iterator_reverse(v,&(i));Vector_next_iteration_ptr_const_reverse(v,&(i),&(h));/*nix*/)23102311Global_ERWIN_EXPORT2312voidVector_init_iterator(Vector_tconst*,Vector_index_t*/*keyptr*/);2313/*private*/23142315Global_ERWIN_EXPORT2316Global_ERWIN_BOOLVector_next_iteration(Vector_tconst*,Vector_index_t*/*keyptr*/,oType*/*valueptr*/);2317/*private*/23182319Global_ERWIN_EXPORT2320Global_ERWIN_BOOLVector_next_iteration_ptr(Vector_t*,Vector_index_t*/*keyptr*/,oTypeVar**/*valuepp*/);2321/*private*/23222323Global_ERWIN_EXPORT2324Global_ERWIN_BOOLVector_next_iteration_ptr_const(Vector_tconst*,Vector_index_t*/*keyptr*/,oTypeVarconst**/*valuepp*/);2325/*private*/23262327Global_ERWIN_EXPORT2328voidVector_init_iterator_reverse(Vector_tconst*,Vector_index_t*/*keyptr*/);2329/*private*/23302331Global_ERWIN_EXPORT2332Global_ERWIN_BOOLVector_next_iteration_reverse(Vector_tconst*,Vector_index_t*/*keyptr*/,oType*/*valueptr*/);2333/*private*/23342335Global_ERWIN_EXPORT2336Global_ERWIN_BOOLVector_next_iteration_ptr_reverse(Vector_t*,Vector_index_t*/*keyptr*/,oTypeVar**/*valueptr*/);2337/*private*/23382339Global_ERWIN_EXPORT2340Global_ERWIN_BOOLVector_next_iteration_ptr_const_reverse(Vector_tconst*,Vector_index_t*/*keyptr*/,oTypeVarconst**/*valueptr*/);2341/*private*/23422343/* ***** access to all entries: ***** */2344Global_ERWIN_EXPORT2345voidVector_clear(Vector_t*/*self*/);2346/* Like Vector_erase for all elements. */23472348Global_ERWIN_EXPORT2349voidVector_clear_keep(Vector_t*/*self*/,Vector_cnt_t/*table_min_size*/);2350/* Like Vector_clear(), but the internal table is not shrunk below2351 * the given minimal size (instead of the predefined minimal table size)2352 */23532354#IFEQ(oType,oTypeVar)2355Global_ERWIN_EXPORT2356voidVector_clear_flags(Vector_t*/*self*/,Global_ERWIN_BOOL/* resize */,Global_ERWIN_BOOL/* delete_elems */);2357/* Like Vector_clear you can specify whether a realloc will be performed and2358 * whether the elements will be freed.2359 * The former is useful if you want to clear the vector but expect new data of2360 * around the same length to be inserted afterwards.2361 *2362 * This function is only available of oType == oTypeVar.2363 */2364#ENDIF23652366Global_ERWIN_EXPORT2367voidVector_clear_no_resize(Vector_t*/*self*/);2368/* Compatibility & convenience:2369 * Like Vector_clear(\p self) without resizing the table.2370 */23712372/*BEGIN:IGNORE*/2373#ifdefined(Global_ERWIN_COMPILING)||!defined(NDEBUG)2374/*END:IGNORE*/23752376Global_ERWIN_EXPORT2377Vector_cnt_tVector_nentries(Vector_tconst*/*self*/)ATTR_PURE;2378/* Returns the number of entries in the vector.2379 *2380 * Note: This is not called `Vector_size' in order to prevent confusion2381 * about the unit of the result. `size' might refer to bytes. `nentries', however,2382 * is clearer.2383 */23842385Global_ERWIN_EXPORT2386Global_ERWIN_BOOLVector_empty(Vector_tconst*/*self*/)ATTR_PURE;2387/* Returns whether the vector contains no elements. */23882389/*BEGIN:IGNORE*/2390/* #if defined(Global_ERWIN_COMPILING) || Vector_ALLOW_OUTOFRANGE || Vector_RANGE_CHECK */2391#else2392#defineVector_INLINE__NENTRIES2393#endif2394/*END:IGNORE*/23952396Global_ERWIN_EXPORT2397Vector_cnt_tVector_table_size(Vector_tconst*/*self*/)ATTR_PURE;2398/* For debugging and optimisation purposes (use rarely): the current2399 * size of of the internal pre-allocated array of elements.2400 */240124022403Global_ERWIN_EXPORT2404Vector_index_tVector_find(2405Vector_tconst*/*self*/,Vector_index_t/*start*/,oTypeParam/*needle*/)ATTR_ERRNO_PURE;2406/* Tries to finds an entry equal to needle. Returns the index of the first element >= start2407 * or -1 of nothing was found. The search is performed from the beginning to the end.2408 *2409 * If start is negativ, search is started at the last but start-th position. So to search2410 * the whole vector, start should be 0.2411 *2412 * Note: This function is not called `Vector_search', because it does not only2413 * perform the search, but also returns the result of that search.2414 *2415 * References2416 * ~~~~~~~~~~2417 * Vector_rfind, Vector_bfind.2418 */24192420Global_ERWIN_EXPORT2421Vector_element_ptr_tVector_find_ptr(2422Vector_tconst*/*self*/,Vector_index_t/*start*/,oTypeParam/*needle*/)ATTR_ERRNO_PURE;2423/* Like Vector_find but returns a pointer to the found item or NULL on failure. */24242425Global_ERWIN_EXPORT2426Vector_index_tVector_rfind(2427Vector_tconst*/*self*/,Vector_index_t/*start*/,oTypeParam/*needle*/)ATTR_ERRNO_PURE;2428/* Tries to finds an entry equal to needle. Returns the index of the first element <= start2429 * or -1 of nothing was found. The search is performed from the end to the beginning.2430 *2431 * If start is negativ, search is started at the last but start-th position. So to search2432 * the whole vector, start should be -1.2433 *2434 * References2435 * ~~~~~~~~~~2436 * Vector_find2437 */24382439Global_ERWIN_EXPORT2440Vector_element_ptr_tVector_rfind_ptr(2441Vector_tconst*/*self*/,Vector_index_t/*start*/,oTypeParam/*needle*/)ATTR_ERRNO_PURE;2442/* Like Vector_rfind but returns a pointer to the found item or NULL on failure. */24432444Global_ERWIN_EXPORT2445Vector_index_tVector_find_raw(2446Vector_tconst*/*self*/,2447Vector_index_t/*start*/,2448oTypeconst*/*needle*/,2449Vector_cnt_t/*len*/)ATTR_ERRNO_PURE;2450/* Like Vector_find but tries to find equal parts. See Vector_rfind_raw. */24512452Global_ERWIN_EXPORT2453Vector_index_tVector_rfind_raw(Vector_tconst*/*self*/,Vector_index_t/*start*/,2454oTypeconst*/*needle*/,Vector_cnt_t/*len*/)ATTR_ERRNO_PURE;2455/* Like Vector_rfind but tries to find equal parts.2456 *2457 * Return the position of `needle' or -1 if it is not found.2458 * Note that it is no problem to search for the zero element Global_oType_ZERO.2459 * These all use the Vector_EQUAL macro.2460 *2461 * Negative values for start will count from the end of the vector.2462 */24632464Global_ERWIN_EXPORT2465Vector_index_tVector_find_if(2466Vector_tconst*/*self*/,2467Vector_index_t/* start*/,2468Vector_feature_t/*feature*/,2469Global_ERWIN_BOOL/* value */);2470/* find_if behaves like position-if in CommonLisp.2471 *2472 * Tries to find an entry with a certain feature. Returns the index of the first element >= start2473 * or -1 of nothing was found. The search is performed from the beginning to the end.2474 *2475 * If start is negativ, search is started at the last but start-th position. So to search2476 * the whole vector, start should be 0.2477 */24782479Global_ERWIN_EXPORT2480Vector_index_tVector_rfind_if(2481Vector_tconst*/*self*/,2482Vector_index_t/* start */,2483Vector_feature_t/*feature*/,2484Global_ERWIN_BOOL/* value */);2485/* Tries to find an entry with a certain feature. Returns the index of the first element <= start2486 * or -1 of nothing was found. The search is performed from the end to the beginning.2487 *2488 * If start is negativ, search is started at the last but start-th position. So to search2489 * the whole vector, start should be -1.2490 */249124922493Global_ERWIN_EXPORT2494Global_ERWIN_BOOLVector_is_equal_at(Vector_tconst*/*self*/,Vector_index_t/*pos*/,2495oTypeconst*/*other*/,Vector_cnt_t/*len*/)ATTR_ERRNO_PURE;2496/* Checks whether the given string is found at the given position.2497 * Negative values for pos will count from the end of the vector.2498 */24992500Global_ERWIN_EXPORT2501voidVector_ltrim_if(Vector_t*/*self*/,Vector_feature_t/*feature*/,Global_ERWIN_BOOL/*value*/);2502/* Cuts off all elements that have the `feature' from the left of the vector2503 *2504 * References: Vector_rtrim_if, Vector_trim_if2505 */25062507Global_ERWIN_EXPORT2508voidVector_rtrim_if(Vector_t*/*self*/,Vector_feature_t/*feature*/,Global_ERWIN_BOOL/*value*/);2509/* Cuts off all elements that have the `feature' from the right of the vector2510 *2511 * References: Vector_ltrim_if, Vector_trim_if2512 */25132514Global_ERWIN_EXPORT2515voidVector_trim_if(Vector_t*/*self*/,Vector_feature_t/*feature*/,Global_ERWIN_BOOL/*value*/);2516/* Cuts off all elements that have the `feature' from the left and right of the vector2517 *2518 * References: Vector_ltrim_if, Vector_rtrim_if2519 */25202521Global_ERWIN_EXPORT2522voidVector_map(Vector_t*/*self*/,Vector_map_t/*map*/);2523/* Applies a given function to all elements of the vector. */25242525Global_ERWIN_EXPORT2526intVector_cmp(Vector_tconst*,Vector_tconst*,Vector_cmp_t/*cmp*/);2527/* Returns a comparison value for lexical sort order, or by length order,2528 * depending on Vector_COMPARE_LEXICOGRAPHICALLY, which defaults to 1 for2529 * non-character types, and to 0 for all others. The difference is that2530 * the length order checks the length of the vector first, which is expected2531 * to yield a quicker distinction for most vectors.2532 *2533 * This function is NULL safe. NULL is smaller than any2534 * other vector. By this you can easily sort a vector in reverse order and then2535 * rtrim_if(is_NULL) to get rid of NULL elements.2536 *2537 * If cmp is NULL, Global_oType_CMP will be used. If that is not defined, an error2538 * will occur.2539 */25402541Global_ERWIN_EXPORT2542Global_hashval_tVector_hash_raw(Vector_tconst*)ATTR_ERRNO_PURE;2543/* Returns a hash value, which is derived from hash values for oType.2544 *2545 * This is traditionally called hash_raw although the hash value is2546 * good enough for a normal HASH nowadays.2547 *2548 * Note: Usually you want hash values if you work with maps. So you2549 * should define the hash value in such a way that both the map2550 * header as well as the vector header find them.2551 *2552 * Further Note: This will only be implemented if Global_oType_HASH_RAW2553 * is defined.2554 *2555 */25562557ERWIN_WRAPPER2558Global_hashval_tVector_hash(Vector_tconst*)ATTR_ERRNO_PURE;2559/* Same as Vector_hash_raw() now that hash_raw() is good enough. */25602561ERWIN_WRAPPER2562Global_hashval_tVector_hash(Vector_tconst*x)2563{2564returnVector_hash_raw(x);2565}25662567#IFEQ(isChar,1)25682569Global_ERWIN_EXPORT2570intVector_fread(Vector_t*/*self*/,FILE*/*f*/,Vector_cnt_t/* max_count */);2571/* Read the whole file or a prefix into the vector.2572 * If you pass -1 for max_count, there is no maximal count.2573 *2574 * This function returns the number of elements read or -1 in case of2575 * an error. If vector_errno is VECTOR_ERR_IO, you can use ferror(f)2576 * to query the error.2577 */25782579Global_ERWIN_EXPORT2580intVector_fgets(Vector_t*/*self*/,FILE*/*f*/,Vector_cnt_t/* max_count */);2581/* Read one line into the vector. You can bound the number of elements stored2582 * in the vector. However, a line is always read completely to the end.2583 *2584 * This function returns the error code. VECTOR_OK means no error.2585 *2586 * If no char could be read, this returns VECTOR_WARN_EMPTY. Otherwise,2587 * VECTOR_OK is returned if not file error occured, VECTOR_ERR_IO2588 * otherwise. Then you can query the error on the file using ferror (f).2589 *2590 * Like the clib function, the trailing \n is appended if it was there.2591 */25922593/* Note: Clean writing is easier, so that functions for that are not2594 * provided. */25952596Global_ERWIN_EXPORT2597voidVector_ltrim(Vector_t*/*self*/);2598/* See Vector_trim.2599 */26002601Global_ERWIN_EXPORT2602voidVector_rtrim(Vector_t*/*self*/);2603/* See Vector_trim.2604 */26052606Global_ERWIN_EXPORT2607voidVector_trim(Vector_t*/*self*/);2608/* Like the Vector_trim_if family with an isspace feature. The special isspace used2609 * here defines '\0' to be a space. This is useful for pre-allocating space2610 * by inserting \0, then using standard clib functions to fill the buffer,2611 * and then trimming it.2612 */26132614Global_ERWIN_EXPORT2615voidVector_chomp(Vector_t*/*self*/);2616/* Like Vector_rtrim with ((X) == '\n' || (X) == '\r') feature2617 */26182619Global_ERWIN_EXPORT2620voidVector_to_upper(Vector_t*/*self*/);2621/* Translates all elements using the Global_erwin_to_upper function.2622 */26232624Global_ERWIN_EXPORT2625voidVector_to_lower(Vector_t*/*self*/);2626/* Translates all elements using the Global_erwin_to_lower function.2627 */26282629Global_ERWIN_EXPORT2630Vector_index_tVector_basename_index(Vector_tconst*/*self*/)ATTR_ERRNO_PURE;2631/* NOTE: This function is obsolete and left in for compatibility reasons.2632 * Use Vector_basename_range instead.2633 *2634 * Returns the index of the first character that belongs to the basename of a2635 * file name. The algorithm depends on the operating system this runs on.2636 *2637 * E.g. under Unix, for "/tmp/test///" this function returns 5. To get the2638 * length of the basename, use Vector_basename_range.2639 */26402641Global_ERWIN_EXPORT2642voidVector_basename_range(Vector_index_t*/*first*/,Vector_cnt_t*/*length*/,Vector_tconst*/*self*/);2643/* Returns the index of the first and last characters that belongs to the basename2644 * of a file name. The algorithm depends on the operating system this runs on.2645 *2646 * This is an extended version of Vector_basename_index, which does not return2647 * the last index. E.g. under Unix, for "/tmp/test///" this function returns:2648 * *first= 5,2649 * *length= 42650 *2651 * first and length may be NULL in which case nothing is returned for the2652 * respective value.2653 */26542655Global_ERWIN_EXPORT2656intVector_append_directory(Vector_t*/*self*/,Vector_tconst*/*path*/);2657/* Append the directory of path to self. This appended string includes the2658 * path separator if necessary. Returns Global_vector_errno.2659 */26602661Global_ERWIN_EXPORT2662intVector_append_basename(Vector_t*/*self*/,Vector_tconst*/*path*/);2663/* Append the base name of path to self. This appended string does not include2664 * any path separator. Returns Global_vector_errno.2665 */26662667Global_ERWIN_EXPORT2668intVector_append_config_file_name(2669Vector_t*/*self*/,2670oTypeconst*/*program_name*/,2671Global_ERWIN_BOOL/*local*/);2672/* Append the default configuration file name (either global or local one) to the vector.2673 * The default global name under Unix is2674 * : /etc/progname.conf2675 * under Windos it is2676 * : C:\etc\progname.ini2677 *2678 * The default local name under Unix is2679 * : $HOME/.prognamerc2680 * under Windos2681 * : %HOME%\progname.ini2682 *2683 * Returns Global_vector_errno. Note that if $HOME is not defined (which is typical under DOS),2684 * VECTOR_ERR_OUTOFRANGE is returned and nothing appended if local != 0.2685 */26862687#ifVector_NO_FORMAT==026882689#ifdefHAVE_STDARG_H2690# include<stdarg.h>2691#endif26922693/*2694 * Format options for the oformat family2695 */2696#if!defined(Global_FO_QUOTE_C_STRING)26972698/*! enum: Global_FO_* */2699#defineGlobal_FO_NO_QUOTE0UL2700/* Format option for Vector_o_format family: perform no quotation on %s strings.2701 * This is the default.2702 *2703 * The NULL pointer is printed as (null).2704 */2705#defineGlobal_FO_QUOTE_C_STRING1UL2706#defineGlobal_FO_QUOTE_PERL_STRING1UL2707/* Format option for Vector_oformat family: quote all %s strings for a C compiler.2708 * There is another option Global_FO_QUOTE_IN_C_STRING which does not output2709 * the surrounding "" of the string.2710 *2711 * The NULL pointer is printed as NULL.2712 */27132714#defineGlobal_FO_QUOTE_IN_C_STRING2UL2715#defineGlobal_FO_QUOTE_IN_PERL_STRING2UL2716/* Format option for Vector_oformat family: quote all %s strings for a C compiler,2717 * assume that we are inside a string and do not output the embracing "". With the2718 * surrounding "", use the Global_FO_QUOTE_C_STRING option.2719 *2720 * The NULL pointer is printed as the empty string.2721 */27222723#defineGlobal_FO_QUOTE_BOURNE_SHELL3UL2724/* Format option for Vector_oformat family: quote all %s strings for a Bourne shell.2725 *2726 * The NULL pointer produces an out of range error.2727 */27282729#defineGlobal_FO_QUOTE_FORMAT4UL2730/* Format option for Vector_oformat family: quote all %s strings for fprintf command.2731 *2732 * Note: Usually the C compiler reads a format string first, so you are likely2733 * to quote again for a C compiler with Global_FO_QUOTE_C_STRING2734 *2735 * The NULL pointer produces an out of range error.2736 */27372738#defineGlobal_FO_QUOTE_WIN_SHELL5UL2739/* Format option for Vector_oformat family: quote all %s strings for a Windows shell.2740 *2741 * The NULL pointer produces an out of range error.2742 */27432744#defineGlobal_FO_QUOTE_LISP_STRING6UL2745/* Format option for Vector_oformat family: quote all %s strings in CommonLisp syntax.2746 *2747 * The NULL pointer is printed as nil.2748 */27492750#defineGlobal_FO_QUOTE_IN_LISP_STRING7UL2751/* Format option for Vector_oformat family: quote all %s strings in CommonLisp2752 * syntax. Do not output the embracing "". See Global_FO_QUOTE_LISP_STRING.2753 *2754 * The NULL pointer is printed as the empty string.2755 */27562757#defineGlobal_FO_QUOTE_URL8UL2758/* Format option for Vector_oformat family: quote all %s strings for2759 * using in an URL. */27602761#defineGlobal_FO_QUOTE_HTML9UL2762#defineGlobal_FO_QUOTE_XML9UL2763#defineGlobal_FO_QUOTE_SGML9UL2764/* Format option for Vector_oformat family: quote all %s strings for2765 * in HTML syntax (no charset conversion is done, so if you pass char*,2766 * this is iso-8859-1 in HTML and XML, while in SGML, it is whatever2767 * you declared). This is suitable for HTML,XML, and SGML -- we do2768 * not assume any named entities. (Not even < > and &).2769 * Anything else is quoted in decimal for maximum compatibility.2770 */27712772/* FIXME: Have base64 and quoted-printable, too. */2773#defineGlobal_FO_QUOTE_RESERVED310UL2774#defineGlobal_FO_QUOTE_RESERVED211UL2775#defineGlobal_FO_QUOTE_RESERVED112UL27762777#defineGlobal_FO_QUOTE_USER113UL2778/* Format option for Vector_oformat family: user defined %s quotation method no. 1 */27792780#defineGlobal_FO_QUOTE_USER214UL2781/* Format option for Vector_oformat family: user defined %s quotation method no. 2 */27822783#defineGlobal_FO_QUOTE_USER315UL2784/* Format option for Vector_oformat family: user defined %s quotation method no. 3 */27852786#defineGlobal_FO_QUOTE_USER_MINGlobal_FO_QUOTE_USER12787#defineGlobal_FO_QUOTE_USER_MAXGlobal_FO_QUOTE_USER327882789/* 4 bits -> 4 bits */2790#defineGlobal_FO_QUOTE_MASK15UL2791#ifdefERWIN_DOS2792# defineGlobal_FO_QUOTE_SHELLGlobal_FO_QUOTE_WIN_SHELL2793/* Format option for Vector_oformat family: depending on the operating system you compiled2794 * for, this is either equal to Global_FO_QUOTE_BOURNE_SHELL or2795 * Global_FO_QUOTE_WIN_SHELL. */27962797#else2798# defineGlobal_FO_QUOTE_SHELLGlobal_FO_QUOTE_BOURNE_SHELL2799#endif/* ERWIN_DOS */28002801#defineGlobal_FO_VOID_P0UL/* default: %p reads a normal pointer */2802#defineGlobal_FO_VECTOR16UL2803/* Instead of reading a normal pointer, %p reads a Vector_t *.2804 */28052806#defineGlobal_FO_S_TYPE_MASK16UL28072808/* 1 bit -> +4 = 5 bits */2809#defineGlobal_FO_NO_CENTER0UL/* default: right adjusted, with `-' left adjusted */2810#defineGlobal_FO_CENTER32UL2811/* Format option for Vector_oformat family:2812 * Center the string. The `-' format specifier then determines whether to tend to2813 * center to the left or to the right when it is not possible to center perfectly.2814 */28152816/* 1 bit -> +5 = 6 bits */2817#defineGlobal_FO_RADIX_DEFAULT0UL/* default: 10 or 16 for %x. */2818#defineGlobal_FO_RADIX_SHIFT6UL2819#defineGlobal_FO_RADIX_MASK127UL2820#defineGlobal_FO_RADIX(RADIX)((((unsignedlong)(RADIX))&Global_FO_RADIX_MASK)<<Global_FO_RADIX_SHIFT)2821/* Format option for Vector_oformat family: specify a radix for numbers. With printf,2822 * only 8, 10, 16 are possible (via the %o, %d and %x formats resp.). This allows2823 * you to specify a different radix.2824 *2825 * For integers, you may use a format specifier character to set base, casing in2826 * a few cases, in which case their variant printing form will be used:2827 *2828 * Global_FO_RADIX('d') - base = 10 - like %d - "10"2829 * Global_FO_RADIX('x') - base = 16, lowcase, variant - like %#x - "0xa"2830 * Global_FO_RADIX('X') - base = 16, upcase, variant - like %#X - "0XA"2831 * Global_FO_RADIX('o') - base = 8, variant - like %#o - "012"2832 * Global_FO_RADIX('b') - base = 2, lowcase, variant - "0b1010"2833 * Global_FO_RADIX('B') - base = 2, upcase, variant - "0B1010"2834 *2835 * Of course, 'b' and 'B' are not format specifiers but are provided2836 * for convenience.2837 *2838 * Other radix values > 64 are undefined. (Values <= 64 will be treated2839 * as numeric, e.g. ASCII '@' will select base64 digits.)2840 *2841 * This does *not* change the handling of the sign: %d is signed by default2842 * and %u,%x,%o are unsigned.2843 *2844 * For floats, the Global_FO_RADIX setting overrides the format specifier.2845 * In contrast to integers, the variant form is not selected when using the2846 * base to set the format specifier.2847 * You may use:2848 *2849 * Global_FO_RADIX('e') - %e2850 * Global_FO_RADIX('E') - %E2851 * Global_FO_RADIX('f') - %f2852 * Global_FO_RADIX('F') - %F2853 * Global_FO_RADIX('g') - %g2854 * Global_FO_RADIX('G') - %G2855 * Global_FO_RADIX('a') - %a2856 * Global_FO_RADIX('A') - %A2857 */28582859#defineGlobal_FO_GET_RADIX(X)(((X)>>Global_FO_RADIX_SHIFT)&Global_FO_RADIX_MASK)28602861/* 6 bits -> +7 = 13 bits */2862#defineGlobal_FO_NO_SEP0UL/* default: do not separate digits */2863#defineGlobal_FO_SEP_AT_SHIFT13UL2864#defineGlobal_FO_SEP_AT_MASK7UL2865#defineGlobal_FO_SEP_AT(AT)(((((unsignedlong)(AT))&Global_FO_SEP_AT_MASK)<<Global_FO_SEP_AT_SHIFT)|Global_FO_DO_USE_SEP)2866/* Format option for Vector_oformat family: separate digits of numbers every AT digits.2867 * If missing or 0, the a value of 3 is used.2868 */28692870#defineGlobal_FO_GET_SEP_AT(X)(((X)>>Global_FO_SEP_AT_SHIFT)&Global_FO_SEP_AT_MASK)28712872/* 3 bits -> +13 = 16 bits */2873#defineGlobal_FO_DO_USE_SEP(1UL<<16)2874/* If set, digits are separated into digit groups.2875 * Both FO_USE_SEP and FO_SET_AT macros automatically set this flag.2876 */2877#defineGlobal_FO_USE_SEP_SHIFT17UL2878#defineGlobal_FO_USE_SEP_MASK255UL2879#defineGlobal_FO_USE_SEP(C)(((((unsignedlong)((unsignedchar)(C)))&Global_FO_USE_SEP_MASK)<<Global_FO_USE_SEP_SHIFT)|Global_FO_DO_USE_SEP)2880/* Format option for Vector_oformat family:2881 * The separator to use between digits if Global_FO_SEP_AT was specified.2882 * The default separator is ','.2883 */28842885#defineGlobal_FO_GET_USE_SEP(X)(((X)>>Global_FO_USE_SEP_SHIFT)&Global_FO_USE_SEP_MASK)28862887/* 9 bits -> +16 = 25 bits */2888#defineGlobal_FO_LOWCASE0UL/* default: digits are lowercase (except for %X) */2889#defineGlobal_FO_UPCASE(1UL<<25)2890/* Format option for Vector_oformat family: print digits in upper case. This is most2891 * useful together with the Global_FO_RADIX option.2892 *2893 * The default is to print in lower case. Any mentioning of upper case in any2894 * way will select upper case printing. E.g. %X together with Global_FO_LOWCASE2895 * will still print in upper case. Similarly, %d together with Global_FO_LOWCASE2896 * and Global_FO_RADIX('X') will print in upper case.2897 */28982899/* 1 bit -> +25 = 26 bits */2900#defineGlobal_FO_PRINT0UL/* default: do print into vector. */2901#defineGlobal_FO_CHECK(1UL<<26)2902/* Format option for Vector_oformat family: perform all formating actions without2903 * modifying the Vector_t. This is useful to compute the width of the resulting2904 * string. */29052906/* 1 bit -> +26 = 27 bits */2907#defineGlobal_FO_SPECIAL(1UL<<27)2908/* Same as # flag in format string: select special form.2909 * The reason to give it is because %#d is not defined, but may be feasible2910 * together with a RADIX() annotation, when you do want 0x and 0 prefixes.2911 */29122913/* 1 bit -> +27 = 28 bits2914 * There are five bits left.2915 */2916#endif/* !defined(FO_C_STRING) */291729182919Global_ERWIN_EXPORT2920voidVector_set_quotation_method(2921Vector_tconst*/* self */,2922int/* which */,2923Vector_quotation_method_tconst*);2924/* Set new quotation methods for the `s' and `v' formats.2925 * `which' may only be Global_FO_QUOTE_USER1 or Global_FO_QUOTE_USER2.2926 *2927 * self is needed to set the status code.2928 *2929 * This function is not thread safe, even if you define Global_ERWIN_THREAD_SAFE.2930 * There is only one array of user quotation methods. If you change it, do it2931 * at the beginning of your program in the main thread!2932 */29332934Global_ERWIN_EXPORT2935Vector_quotation_method_tconst*Vector_get_quotation_method(2936Vector_tconst*/*self */,2937int/* which */);2938/* Get quotation methods.2939 * Which must be from the Global_FO_QUOTE_* family.2940 */29412942Global_ERWIN_EXPORT2943voidVector_format(Vector_t*/*self*/,Tcharconst*/*format*/,...)ATTR_FORMAT_PRINTF(2,3);2944/* See Vector_oformat. */29452946Global_ERWIN_EXPORT2947voidVector_vformat(2948Vector_t*/*self*/,2949Tcharconst*/*format*/,2950va_list)ATTR_FORMAT_VPRINTF(2);2951/* See Vector_oformat. */29522953/* FIXME: have a scanf function, too, which especially does the unquoting2954 * of all implemented formats. */29552956Global_ERWIN_EXPORT2957voidVector_oformat(2958Vector_t*/*self*/,2959unsignedlong/* options */,2960Tcharconst*/*format*/,...)ATTR_FORMAT_PRINTF(3,4);2961/* The format is as in the printf family according to C99 standard. These functions will2962 * never cause a buffer overflow. The \type(long long) type (64 bits integer) is supported2963 * if the compiler supports one. Its format character is 'll', but `L' is also2964 * understood.2965 *2966 * This function reimplements the whole2967 * printf functionality, so if you do not like this overhead, you can define Vector_NO_FORMAT,2968 * but because of the guaranteed prevention of buffer overflows, it is usually good2969 * to use this.2970 *2971 * To keep ANSI/ISO conformance (ISO/IEC 9899:1999 = C99), all extra functionality has been2972 * put into the additional `options' argument. The following format options are supported:2973 *2974 * +------------------------------+------------------------------------------------+2975 * | d, i, u, o, x, X, c, s, m, p | conversion, own implementation |2976 * | e, E, f, F, g, G, a, A | conversions passed through to standard library |2977 * | #, 0, -, SPACE | flags |2978 * | h, hh, l, ll, L, j, z, t | length |2979 * +------------------------------+------------------------------------------------+2980 *2981 * Note: Use ll with integers only and L with floats only to be compliant with POSIX.2982 * (Erwin treats both exactly the same just like glibc.)2983 *2984 * Currently unsupported2985 * ~~~~~~~~~~~~~~~~~~~~~2986 * +----+-------------------------------------+2987 * | $ | argument reordering |2988 * | n | number of characters written so far |2989 * +----+-------------------------------------+2990 *2991 * - L + float is only supported if the compiler has is a long double type2992 * - ll + int is only supported if the compiler has a 64 bit int type.2993 *2994 * Compatibility2995 * ~~~~~~~~~~~~~2996 * For compatibility, the following are implemented (don't use if you want to2997 * be POSIX compliant).2998 * +----------------+--------------------------------------------------------+2999 * | C | use lc instead |3000 * | S | use ls instead |3001 * | Z | use z instead |3002 * | q | use ll instead |3003 * | L + int | use ll instead |3004 * | ll + float | use L instead |3005 * | l + float | double instead of float |3006 * | ' (apostrophy) | No locale support: always digit width 3, separator=' ' |3007 * +----------------+--------------------------------------------------------+3008 *3009 * Note: FO_RADIX(64) uses base-64 digits, but is not mmencode compatible, as the3010 * base64 encoding works on chunks of 3 bytes which are interpreted as3011 * 4 6-bit digits each. The problem is that the digit order is reversed to3012 * the normal order, so you cannot easily convert from the format output3013 * to real base64 output. Maybe we'll introduce a quotation method for3014 * base64 some day.3015 *3016 * Further note that you can print negative number with base != 10 by using %d with3017 * the option FO_RADIX(...).3018 *3019 * Options3020 * ~~~~~~~3021 * You can use the Global_FO_CHECK option to simulate operation. By this, you can check3022 * things via the first argument to Vector_rovformat or Vector_roformat. The use3023 * of Vector_format_pos() and Vector_format_quoted() is *deprecated*.3024 *3025 * The following options are supported to allow extended functionality.3026 * They can be ORed together.3027 *3028 * - Global_FO_VECTOR:3029 * All %p refer to a \type(Vector_t *) instead of to a \type(char *).3030 *3031 * - Global_FO_UPCASE:3032 * Use upper case digits first in numbers (this is needed3033 * because there is no %D).3034 * e.g.3035 * : format (Global_FO_UPCASE + Global_FO_RADIX(23), "%d", 2387)3036 * appends |4BI|3037 *3038 * - Global_FO_CENTER:3039 * Selects centering. I.e. in addition to default right3040 * adjustment or right adjustment by the |-| option.3041 *3042 * This does not work for floating point3043 * arguments (see below) since the clib does not support it.3044 *3045 * This can be combined with |-| to3046 * specify that if it cannot be centred exactly, it should3047 * be more left adjusted instead of right.3048 * E.g.3049 * : Vector_oformat (v, Global_FO_CENTER, "%04X", 10)3050 * will append "\tt(00A )" whereas3051 * : Vector_oformat (v, Global_FO_CENTER, "%-04X", 10)3052 * will append "\tt(0A )".3053 *3054 * - Global_FO_RADIX(radix):3055 * radix: a number between 0 and 64:3056 * Switches the radix of the %d, %i, %x and %o command from their3057 * default to this number.3058 *3059 * The digit set is as follows:3060 *3061 * - radix <= 36: for %x (lower case): 0..9, a..z and3062 * for %X (upper case): 0..9, A..Z3063 *3064 * - radix = 64: always base64 digits (but different digit order!)3065 *3066 * - radix > 36 && radix < 64: base64 with only the first radix characters.3067 *3068 * Also see the documentation of the Global_FO_RADIX macro to3069 * learn about the special radix values of 'd', 'i', 'o', 'x', 'X',3070 * 'b', 'e', 'E', 'f', 'F', 'g', 'G', 'a', 'A'.3071 *3072 * - Global_FO_QUOTE_SHELL:3073 * Quotation for Shell: either Unix or Windows, depending on compilation3074 * environment: equivalent to Global_FO_QUOTE_BOURNE_SHELL under Unix3075 * and te Global_FO_QUOTE_WIN_SHELL under Dos or Windows.3076 *3077 * - Global_FO_QUOTE_BOURNE_SHELL:3078 * Quote for a Bourne shell.3079 * : Vector_oformat (FO_QUOTE_BOURNE_SHELL, "%s", "a b!c")3080 * -> \tt(a\ b\!c)3081 *3082 * - Global_FO_QUOTE_WIN_SHELL:3083 * Quote for a Windows shell.3084 * : Vector_oformat (FO_QUOTE_WIN_SHELL, "%s", "a b!c")3085 * -> \tt("a b!c")3086 *3087 * - Global_FO_QUOTE_C_STRING:3088 * Quote in double quoted C syntax. Single quotes are still3089 * quoted as \'. This also tries to get maximum compatibility3090 * for reading such a string by sometimes quoting although3091 * unnecessary since it is known that some buggy compilers may3092 * misinterpret something. E.g. someone might read \0001 as3093 * only one character. Therefore, the previous is quoted as3094 * \000\001.3095 *3096 * : Vector_oformat (FO_QUOTE_C_STRING, "%s", "a'b\\c\"d\0\7e")3097 * -> \tt("a\'b\\c\"d\000\007e")3098 *3099 * This handles NULL and prints it as NULL.3100 *3101 * - Global_FO_QUOTE_IN_C_STRING:3102 * Similar to previous, but does not output enclosing double3103 * quotes, so it is suitable for either appending several3104 * quoted strings or for quoting in character syntax (single3105 * quotes), by manually providing enclosing quotes in the3106 * format string.3107 *3108 * : Vector_oformat (FO_QUOTE_C_STRING, "%s", "a'b\\c\"d\0\7e")3109 * -> \tt(a\'b\\c\"d\000\007e)3110 *3111 * - Global_FO_QUOTE_LISP_STRING:3112 * CommonLisp quotation: this is like a simple C quotation:3113 * basically, only " and \ need quotation.3114 *3115 * : Vector_oformat (FO_QUOTE_C_STRING, "%s", "a'b\\c\"d")3116 * -> \tt("a'b\\c\"d")3117 *3118 * - Global_FO_QUOTE_IN_LISP_STRING:3119 * Same as before without enclosing double quotes.3120 *3121 * : Vector_oformat (FO_QUOTE_C_STRING, "%s", "a'b\\c\"d")3122 * -> \tt(a'b\\c\"d)3123 *3124 * - Global_FO_QUOTE_FORMAT:3125 * Quote to be suitable as a printf format string. I.e.,3126 * % is quoted as %%. Note that this does not include a3127 * C quotation, so when you have a literal string, and want3128 * to print a format string in C, you'll need to first3129 * quote for format, and then again for C.3130 * : Vector_oformat (FO_QUOTE_FORMAT, "%s", "%s")3131 * -> \tt(%%s)3132 *3133 * - Global_FO_QUOTE_USER1 ... USER3:3134 * User quotation: can be defined by the application by3135 * Vector_set_quotation_method().3136 *3137 * Of the above, one can be selected: all %s and %c commands3138 * will quote their argument according to the given quotation.3139 *3140 * Note: Quotation is only done for %s and %c, not for anything3141 * else!3142 *3143 * Further Note: because it appeared to happened *too*3144 * often, to mix quotation and non-quotation in one format string,3145 * you can specify left adjustment without giving a minimal width to3146 * switch off quotation. So to switch off quotation for some %s,3147 * use %-s.3148 *3149 * Note: This will only work if the minimal with is not given3150 * at all to prevent confusion:3151 *3152 * : Vector_oformat (FO_QUOTE_C_STRING, "%s.%-s.%s", "b", "c", "d")3153 * This will append: \tt("b".c."d")3154 *3155 * - Global_FO_SEP_AT(position):3156 * Position is a number between 0 and 15.3157 *3158 * Put commas into a number. E.g.3159 * : oformat (Global_FO_SEP_AT(3), "%d", 10000000)3160 * -> \tt(10,000,000)3161 *3162 * This is equivalent to using "%'d" for an appropriate locale.3163 *3164 * The number defines at how many digits this should happen.3165 * So Chinese people would perhaps want it between blocks of3166 * four digits:3167 *3168 * : oformat(Global_FO_SEP_AT(4), "%d", 10000000)3169 * -> \tt(1000,0000)3170 *3171 * (since 1000,0000 = qian1 wan4; qian1 (=1000) wan4 (=10000))3172 *3173 * (For some unknown reason, however, it seems that Asian languages3174 * with base words up to 10000 (instead of 1000 as most Western European3175 * languages) still use separators at all three digits. Why?)3176 *3177 * - Global_FO_USE_SEP('.'):3178 * Define which character to use for digit separation:3179 *3180 * E.g Germans might want to format their numbers like this:3181 * : oformat(Global_FO_USE_SEP('.') |3182 * : Global_FO_SEP_AT(3), "%d", 10000000)3183 * -> \tt(10.000.000)3184 *3185 * Format specifiers3186 * ~~~~~~~~~~~~~~~~~3187 * - %n: writes the current length of the vector into the given3188 * int* pointer. (or short* or long* or long long* if this3189 * is indicated by s, l or q).3190 *3191 * Note: it writes the absolute length of the vector, NOT3192 * the relative length wrt. to the starting length!3193 *3194 * Chopping behaviour with quoted strings3195 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~3196 *3197 * When using both width arguments, characters will never be3198 * output in halves (or other pieces). Instead, the string is3199 * tried to be kept shorter. Sometimes this is not possible3200 * (e.g. when the length of the prefix + suffix exceeds the total3201 * width). In rare cases the string will therefore be longer.3202 * This behaviour is useful for breaking strings over several lines.3203 *3204 * If you specify the exact length argument, the string will still3205 * not be expanded or chopped. (e.g. %80.78s will produce3206 * lines which are always 80 characters wide and which contain3207 * at most 78 characters representing a string and which will3208 * be padded with spaces to the right):3209 * Example:3210 * : Vector_oformat(Global_FO_SHELL_QUOTE, "%7.5s", "Du da!")3211 * : // This means: max. 5 chars, min.7 resulting in padding.)3212 * appends \tt(Du\ d )3213 *3214 * The number of characters read from the input string can be3215 * retrieved by using Vector_roformat() or Vector_rovformat() and3216 * reading it from the resulting info structure.3217 *3218 * E.g. the following loop generates a C parsable string which3219 * does not exceed 78 characters on each line:3220 * : int print_c_string (Vector_t *v, char const *c)3221 * : {3222 * : Vector_format_info_t info;3223 * : do {3224 * : Vector_roformat (&info, Global_FO_QUOTE_C_STRING, v, "%.78s\n", c);3225 * : c+= info.pos;3226 * : } while (Global_VECTOR_IS_OK(Global_vector_errno) && *c != '\0');3227 * : }3228 *3229 * If more than one l, q, h and Z flag is given, the last one will be used.3230 *3231 * Note: float and double formatations are passed to the standard library.3232 * So whether e.g. long double is implemented depends on your clib.3233 * This includes the `a' and `A' conversions (GNU).3234 *3235 * Further Note:3236 * oType_ZERO will be used! This means that if it is != '\0', the %s3237 * argument will terminate printing at the first character equal to3238 * oType_ZERO.3239 */32403241#IFNEQ(FORMAT_REPETITION,0)3242/*3243 * Grouped Repetition:3244 * %NUM[ ... %]3245 * Repeat the sequence several times. E.g.:3246 * Vector_format (v, "%3[%6d%]", i, o, p);3247 * It is allowed for NUM to be 0. NUM defaults to 1.3248 *3249 * It is also allowed for NUM to be `*' in which case the number3250 * is read from an integer argument.3251 *3252 * If the special form character # is used, a pointer is read3253 * from the arg list used for all following arg list referencing.3254 * This pointer is also used for nested %[ forms. If the nested3255 * are given with a special flag, the pointer from the nested3256 * form is read from the position of the outer special form3257 * pointer. If NUM is * and the special form is given, the3258 * repetition number is still read without influence of the #.3259 *3260 * Example 1: You can print the argument list of a program with3261 * Vector_format (v, "%#*[%< %.2s%]", argc, argv);3262 *3263 * Example 2: You can output a two dimensional 3x3 array like this:3264 * Vector_format (v, "%#3[%3[%6d,%]\n%]", a);3265 *3266 * Note: For floating pointer arguments, you must use `lf' for a3267 * double like in fscanf when reading from pointers.3268 *3269 * %NUM<3270 * %NUM> Skip the following NUM characters of the format string if this3271 * is the first (last) iteration of the innermost repetition loop.3272 * NUM defaults to 1.3273 * The special form reverses the logic.3274 *3275 * Example: You can output the above array in C syntax is follows:3276 * Vector_format (v, "int a[3][3]={%#3[{ %3[ %6d%>,%] }%2>,\n%]};\n", a);3277 *3278 */3279#ENDIF/* FORMAT_REPETITION */32803281Global_ERWIN_EXPORT3282voidVector_ovformat(3283Vector_t*/* self */,3284unsignedlong/* options */,3285Tcharconst*/* format */,3286va_list/* arguments */)ATTR_FORMAT_VPRINTF(3);3287/* See Vector_oformat. */32883289Global_ERWIN_EXPORT3290voidVector_format_info_init(Vector_format_info_t*);3291/* Initialises a Vector_format_info_t structure. Only required for C code.3292 * In C++, the constructor is used for this.3293 *3294 * A Vector_format_info_t structure must be initialised before invoking3295 * Vector_rovformat() with a pointer to it.3296 */32973298Global_ERWIN_EXPORT3299voidVector_format_info_done(Vector_format_info_t*);3300/* Sweeps a Vector_format_info_t structure. Only required for C code.3301 * In C++, the destructor is used for this.3302 *3303 * A Vector_format_info_t structure must be sweeps before deallocation.3304 */33053306Global_ERWIN_EXPORT3307voidVector_roformat(3308Vector_format_info_t*/* info */,3309Vector_t*/* self */,3310unsignedlong/* options */,3311Tcharconst*/* format */,3312.../* arguments */)ATTR_FORMAT_PRINTF(4,5);3313/* Additional to Vector_oformat it stores information about the performed formatting3314 * in info. Use this in favour of Vector_format_quoted to retrieve information you3315 * need.3316 */33173318Global_ERWIN_EXPORT3319voidVector_rovformat(3320Vector_format_info_t*/* info */,3321Vector_t*/* self */,3322unsignedlong/* options */,3323Tcharconst*/* format */,3324va_list/* arguments */)ATTR_FORMAT_VPRINTF(4);3325/* Additional to Vector_ovformat it stores information about the performed formatting3326 * in info. Use this in favour of Vector_format_quoted to retrieve information you3327 * need.3328 */33293330#ifGlobal_ERWIN_GLOBAL_ERRNO3331Global_ERWIN_EXPORT3332Global_ERWIN_BOOLVector_format_quoted(void)ATTR_DEPRECATED;3333/* DEPRECATED3334 * ----------3335 * Use3336 * : Vector_roformat (&info, FO_CHECK ...3337 *3338 * Was quotation ever necessary during the format?3339 *3340 * This function is not thread safe. It uses global variables. Therefore, this3341 * function is not available when you compile with thread support3342 * (Global_ERWIN_THREAD_SAFE). Use Vector_rovformat or Vector_roformat.3343 */33443345Global_ERWIN_EXPORT3346Vector_index_tVector_format_pos(void)ATTR_DEPRECATED;3347/* DEPRECATED3348 * ----------3349 * Use3350 * : Vector_roformat (&info, FO_CHECK ...3351 *3352 * Returns how many characters were read from the last %s command.3353 *3354 * This function is not thread safe. It uses global variables. Therefore, this3355 * function is not available when you compile with thread support3356 * (Global_ERWIN_THREAD_SAFE). Use Vector_rovformat or Vector_roformat.3357 */33583359#endif/* Global_ERWIN_GLOBAL_ERRNO */33603361#endif/* Vector_NO_FORMAT==0 */33623363#ENDIF33643365/*--END-C--*/33663367#include"#Vector_i.ErwinHExt"3368/* Same problem as for arrays. For efficient implementation, the compiler3369 * needs to know the size of a vector structure.3370 */33713372#IFCPPONLY3373#ELSE3374#ifdefined(__cplusplus)3375}3376#endif/* __cplusplus */3377#ENDIF33783379/*3380 * If initial_size < 0 for any of the following functions, the default3381 * size will be used.3382 */33833384structVector_t3385#ifdefVector_SUPER_CLASS3386:Vector_SUPER_CLASS_ACCESSVector_SUPER_CLASS3387#endif3388{3389/*3390 * The Vector Class3391 * ================3392 * This class implements dynamically resizable arrays.3393 *3394 * Throughout the documentation, the following prefixes will be used:3395 * - Global_:3396 * The library prefix: for applications, this is typically3397 * empty, for an xyz-Library, this is either \tt(XYZ_), \tt(xyz_) or3398 * \tt(Xyz), depending on the identifier in occurs in.3399 * +---------------------+-----------------+3400 * |! Template |! Instantiation |3401 * | Global_VECTOR_OK | XYZ_VECTOR_OK |3402 * | Global_vector_new | xyz_vector_new |3403 * +---------------------+-----------------+3404 *3405 * - Vector_:3406 * This is equivalent to Global_vector_oType, or the name3407 * that was set with \tt(-name=...) for this data structure.3408 * The case and underbar convention is adjusted, too.3409 *3410 * Assuming a library prefix \tt(xyz) and oType == char, you get:3411 * +-------------------+----------------------------+3412 * |! Template |! Instantiation |3413 * | Vector_t | xyz_vector_char_t |3414 * | Vector_ALLOW_NULL | XYZ_VECTOR_CHAR_ALLOW_NULL |3415 * +-------------------+----------------------------+3416 * - Vector_class:3417 * This is the name of the data structure type in C++: capitalised3418 * and with underbars removed:3419 * +-------------------+-----------------+3420 * |! Vector_t |! Vector_class |3421 * | vector_char_t | VectorChar |3422 * +-------------------+-----------------+3423 *3424 * Conventions3425 * -----------3426 *3427 * It was tried to keep the argument order consistent, with some rules:3428 *3429 * - for functions returning multiple values into pointer arguments, these3430 * are always /before/ input arguments. (e.g. Vector_locate (output, self, ...)).3431 * (Mnemonic: like memcpy, strcpy, assignment statement etc.)3432 * : Global_ERWIN_BOOL Vector_locate (int *i, Vector_t const *, ...)3433 * : ^output ^output ^input ^input3434 * : ^first input = self3435 * - the self argument is always the first input argument.3436 * - index before element (e.g.,3437 * : Vector_insert (self, position, element)3438 * - count after element(s). E.g.:3439 * : Vector_insert_raw (self, position, elemnt_ptr, count)3440 * - flags last. E.g.:3441 * : Vector_overwrite_flags (self, start, value, count,3442 * : copy_elems, delete_overwritten)3443 *3444 * Results3445 * ~~~~~~~3446 * - if there is no natural result value, C functions return their success,3447 * i.e., the value of Global_vector_errno:3448 * : int Vector_erase (Vector_t *self, int pos, int count)3449 * In these circumstances, C++ functions return the vector itself as3450 * a reference:3451 * : Vector_t &Vector_t::erase (int pos, int count = 1)3452 * - if Vector_errno is not interesting, either because it is not3453 * set or because only memory overflow or assertion failures may be3454 * a possible sources of an error, the C functions return void:3455 * : void Vector_delete (Vector_t *self)3456 * The C++ functions still return the object reference.3457 *3458 * Status Codes3459 * ------------3460 *3461 * These are undef'ed first because there is only one error code for all3462 * the arrays in your program.3463 * All the functions returing error codes will both return this error3464 * and write it into Global_vector_errno.3465 *3466 * +-----------------------+---------------------------+-----------------------------+3467 * |! Condition |! Description |! Macro to use |3468 * +-----------------------+---------------------------+-----------------------------+3469 * | == Global_VECTOR_OK | Ok. | Global_VECTOR_IS_OK(X) |3470 * +-----------------------+---------------------------+-----------------------------+3471 * | < Global_VECTOR_OK | *Error*: operation did | Global_VECTOR_IS_ERROR(X) |3472 * | | not succeed. | |3473 * +-----------------------+---------------------------+-----------------------------+3474 * | > Global_VECTOR_OK | *Warning*: operation | Global_VECTOR_IS_WARNING(X) |3475 * | | succeeded but not | |3476 * | | perfectly. (e.g. rehash | |3477 * | | failed) | |3478 * +-----------------------+---------------------------+-----------------------------+3479 *3480 *3481 * In all cases, the consistency of the data structure is guaranteed.3482 *3483 * Warnings are only visible in Global_vector_errno; the functions still return3484 * VECTOR_OK.3485 */34863487Vector_STD_MEMBERS(Vector_t)34883489#ifdef__cplusplus3490public:/* The implementation is in C, so these need access. */3491#endif/* defined __cplusplus */34923493Vector_record34943495#ifdef__cplusplus34963497/*! doc-ignore */3498Vector_t*it(){returnthis;}34993500/*! doc-ignore */3501Vector_tconst*it()const{returnthis;}35023503/*--BEGIN-CLASS--*/3504public:3505#ifdef__cplusplus3506#if!Global_ERWIN_DEFAULT_NEW_DELETE3507staticvoid*operatornew(size_t);3508staticvoidoperatordelete(void*,size_t);3509staticvoid*operatornew[](size_t);3510staticvoidoperatordelete[](void*,size_t);3511#endif3512#endif35133514/* Creation */35153516Vector_t(void);35173518staticVector_tconst&static_zero();35193520#ifVector_HAVE_INT_CONSTRUCTOR3521Global_ERWIN_EXPLICITVector_t(Vector_cnt_tinitial_size);3522#endif3523#ifVector_DYN_ZERO3524Global_ERWIN_EXPLICITVector_t(oTypeTouched);3525Vector_t(oTypeTouched,Vector_cnt_t);3526#endif35273528/*3529 * Enforced vector copying. All of the following functions create a new vector3530 * and leave the old one (if any) intact. It can be defined whether the elements3531 * are to be copied. */35323533Vector_t(Vector_tconst*,booldo_copyVector_DEFAULT_ARG(true));35343535Vector_t(Vector_tconst*,Vector_index_t,Vector_cnt_t,booldo_copyVector_DEFAULT_ARG(true));35363537Vector_t(oTypeVarconst*,booldo_copyVector_DEFAULT_ARG(true));3538Vector_t(oTypeVarconst*,Vector_cnt_t,booldo_copyVector_DEFAULT_ARG(true));3539#IFEQ(oType,oTypeVar)3540#ELSE3541Global_ERWIN_EXPLICITVector_t(oTypeconst*);3542Vector_t(oTypeconst*,Vector_cnt_t);3543#ENDIF35443545/* The following is thought to be for coercing arrays to vectors. The vector3546 * then operates directly on the given array. See Vector_new_from_raw for3547 * details. */35483549Vector_t(bool/* must_be_true */,3550oTypeVar*/* other */,3551Vector_cnt_t/* count */,3552Vector_cnt_t/* alloc */);3553/* alloc may be -1: see Vector_new_from_raw */35543555#ifVector_DYN_ZERO3556Vector_t(bool/* must_be_true */,3557oTypeVar*/* other */,3558Vector_cnt_t/* count */,3559Vector_cnt_t/* alloc */,3560oTypeTouched/* zero_element */);3561/* alloc may be -1: see Vector_new_from_raw */3562#endif35633564Vector_t(bool/* must_be_true */,3565Vector_t*/* other */);35663567Vector_t(bool/* must_be_true */,3568Vector_t&/* other */);35693570void_constructor(void);3571void_destructor(void);35723573/* Check for NULL pointers */3574protected:3575#ifndefNDEBUG3576voidcn()const;3577voidcn(voidconst*)const;3578#else3579/* Hopefully optimised away: */3580staticvoidcn(){}3581staticvoidcn(voidconst*){}3582#endif35833584public:3585/* Status code */35863587#if!Global_ERWIN_GLOBAL_ERRNO3588intget_errno(void)const3589{returnit()->m_errno;}35903591voidclear_errno(void)const3592{Vector_clear_errno(it());}3593#else3594staticintget_errno(void)3595{returnGlobal_vector_errno;}35963597staticvoidclear_errno(void)3598{Global_vector_errno=Global_VECTOR_OK;}3599#endif36003601/* Copying */36023603Vector_t(Vector_tconst&,booldocopyVector_DEFAULT_ARG(true));3604Vector_t(Vector_tconst&,Vector_index_t,Vector_cnt_t,booldo_copyVector_DEFAULT_ARG(true));36053606Vector_t*copy(void)const3607{3608if(this==NULL)3609returnNULL;3610returnnewVector_t(it(),true);3611}36123613Vector_t*copy_err(int*err)const3614{3615if(this==NULL)/* special case for copy function */3616returnNULL;3617Vector_t*result=newVector_t(it(),true);3618if(err!=NULL&&Global_VECTOR_IS_ERROR(get_errno()))3619*err=1;3620returnresult;3621}36223623/* The following functions assume that Vector_t and Vector_t are the3624 * same type making things more easy. Since they did not exist in pre 2.0.265,3625 * we can simply not declare them when the compat is define. */36263627Vector_t*copy_detach()3628{3629returnVector_new_from_vector(it());3630}36313632Vector_t&xchg(Vector_t*other)3633{3634Vector_xchg(it(),other);3635return*this;3636}36373638Vector_t&xchg(Vector_t&other)3639{3640Vector_xchg(this,&other);3641return*this;3642}36433644/* Normal members */36453646Vector_t*subvector(Vector_index_tb,Vector_cnt_tc)const3647{3648returnnewVector_t(this,b,c,true);3649}36503651Vector_t*subvector(Vector_index_tb,Vector_cnt_tc,boold)const3652{3653returnnewVector_t(this,b,c,d);3654}365536563657/* Assignment */36583659Vector_t&operator=(Vector_tconst&);3660Vector_t&operator=(Vector_tconst*);36613662/* Destruction */36633664~Vector_t();36653666/* Re-init by dropping responsibility for the table: */36673668Vector_t&detach(void)3669{Vector_detach(it());return*this;}36703671Vector_t&detach_as_is(void)3672{Vector_detach_as_is(it());return*this;}36733674/* Conversion to C type <= 2.0.264 / conversion to pointer > 2.0.264 */36753676operatorVector_tconst*()const3677{returnit();}36783679operatorVector_t*()3680{returnit();}36813682/* operator int () const { cn(); return get_errno(); }3683 * FIXME: maybe add this one day. It produces invisible semantics changes with3684 * old versions when 'explicit' is used as well. */36853686#ifVector_MANY_CASTS!=03687operatorVector_element_ptr_t()const3688{returnas_array();}36893690operatorbool()const3691{return!empty();}3692#endif36933694#ifVector_POSITION_POINTER3695Vector_index_t*pos_ptr(){return&m_pos;}3696Vector_index_t&pos_ref(){returnm_pos;}3697Vector_index_tpos(){returnm_pos;}3698voidset_pos(Vector_index_ty){m_pos=y;}3699#endif37003701oTypeResultnth(Vector_index_ti)const3702{3703#ifdefVector_INLINE__NTH3704cn();3705returnm_table[i];3706#else3707returnVector_nth(it(),i);3708#endif3709}37103711oTypeResultnth_char(Vector_index_ti)const3712{returnVector_nth_char(it(),i);}37133714Vector_element_ptr_tnth_ptr_check(Vector_index_ti)3715{3716returnVector_nth_ptr_check(it(),i);3717}37183719oTypeconst*nth_ptr_check(Vector_index_ti)const3720{3721returnVector_nth_ptr_check_const(it(),i);3722}37233724Vector_element_ptr_tnth_ptr_char(Vector_index_ti)3725{3726returnVector_nth_ptr_char(it(),i);3727}37283729oTypeconst*nth_ptr_char(Vector_index_ti)const3730{3731returnVector_nth_ptr_char_const(it(),i);3732}37333734Vector_element_ptr_tnth_ptr(Vector_index_ti)3735{3736returnVector_nth_ptr(it(),i);3737}37383739oTypeconst*nth_ptr(Vector_index_ti)const3740{3741returnVector_nth_ptr_const(it(),i);3742}37433744Vector_element_ref_tnth_ref(Vector_index_ti)3745{3746return*(Vector_nth_ptr(it(),i));3747}37483749oTypeconst&nth_ref(Vector_index_ti)const3750{3751return*(Vector_nth_ptr_const(it(),i));3752}37533754Vector_element_ref_tnth_ref_check(Vector_index_ti)3755{3756return*(Vector_nth_ptr_check(it(),i));3757}37583759oTypeconst&nth_ref_check(Vector_index_ti)const3760{3761return*(Vector_nth_ptr_check_const(it(),i));3762}37633764Vector_element_ref_tnth_ref_char(Vector_index_ti)3765{3766return*(Vector_nth_ptr_char(it(),i));3767}37683769oTypeconst&nth_ref_char(Vector_index_ti)const3770{3771return*(Vector_nth_ptr_char_const(it(),i));3772}377337743775#IFEQ(isChar,1)37763777oTypeResultoperator[](Vector_index_ti)const3778{returnnth_char(i);}37793780Vector_element_ref_toperator[](Vector_index_ti)3781{return*nth_ptr_char(i);}37823783#ELSE37843785Vector_element_ref_toperator[](Vector_index_ti)3786{return*nth_ptr_check(i);}37873788oTypeResultoperator[](Vector_index_ti)const3789{returnnth(i);}37903791#ENDIF37923793oTypeResultfirst(void)const3794{3795returnnth(0);3796}37973798Vector_element_ptr_tfirst_ptr()3799{3800returnVector_first_ptr(it());3801}38023803Vector_element_ref_tfirst_ref()3804{3805return*(Vector_first_ptr(it()));3806}38073808oTypeResultlast(void)const3809{3810returnnth(nentries()-1);3811}38123813Vector_element_ptr_tlast_ptr()3814{3815returnVector_last_ptr(it());3816}38173818Vector_element_ref_tlast_ref()3819{3820return*(Vector_last_ptr(it()));3821}38223823oTypeVarmodify(Vector_index_ti,oTypeTouchedv)3824{returnVector_modify(it(),i,v);}38253826Vector_t&reverse(void)3827{3828Vector_reverse(it());3829return*this;3830}38313832oTypeVarlast_chop1(void)3833{3834returnVector_last_chop1(it());3835}38363837oTypeVarfirst_swap_chop1(void)3838{3839returnVector_first_swap_chop1(it());3840}38413842/* Set */38433844Vector_t&set(Vector_index_ti,oTypeTouchedv)3845{Vector_set(it(),i,v);return*this;}38463847/* Erase family */38483849Vector_t&swap_erase(Vector_index_ti,Vector_cnt_tn=-1)3850{Vector_swap_erase(it(),i,n);return*this;}385138523853#IFEQ(oType,oTypeVar)3854Vector_t&swap_erase(Vector_index_ti,Vector_cnt_tn,boola,boolb=true)3855{3856Vector_swap_erase_flags(it(),i,n,a,b);3857return*this;3858}3859#ENDIF38603861Vector_t&erase(Vector_index_ti,Vector_cnt_tn=-1)3862{Vector_erase(it(),i,n);return*this;}386338643865Vector_cnt_terase_zero()3866{3867returnVector_erase_zero(it());3868}38693870#IFEQ(oType,oTypeVar)3871Vector_t&erase(Vector_index_ti,Vector_cnt_tn,boola,boolb=true)3872{3873Vector_erase_flags(it(),i,n,a,b);3874return*this;3875}38763877Vector_cnt_terase_if(Vector_feature_tf,3878boolinvVector_DEFAULT_ARG(true),3879boolaVector_DEFAULT_ARG(true),3880boolbVector_DEFAULT_ARG(true))3881{3882returnVector_erase_if_flags(it(),f,inv,a,b);3883}38843885Vector_cnt_terase_if_not(3886Vector_feature_tf,3887boolinvVector_DEFAULT_ARG(true),3888boolaVector_DEFAULT_ARG(true),3889boolbVector_DEFAULT_ARG(true))3890{3891returnVector_erase_if_flags(it(),f,!inv,a,b);3892}38933894Vector_cnt_terase_equals(Vector_cmp_tfcmpVector_DEFAULT_ARG(Vector_CMP_T_NULL),3895Vector_combine_tcombineVector_DEFAULT_ARG(Vector_COMBINE_T_NULL))3896{3897returnVector_erase_equals(it(),fcmp,combine);3898}38993900#ELSE3901Vector_t&erase(Vector_index_ti,Vector_cnt_tn,boola)3902{3903Vector_erase_flags(it(),i,n,a);3904return*this;3905}39063907Vector_cnt_terase_if(Vector_feature_tf,3908boolinvVector_DEFAULT_ARG(true),3909boolaVector_DEFAULT_ARG(true))3910{3911returnVector_erase_if_flags(it(),f,inv,a);3912}39133914Vector_cnt_terase_if_not(3915Vector_feature_tf,3916boolinvVector_DEFAULT_ARG(true),3917boolaVector_DEFAULT_ARG(true))3918{3919returnVector_erase_if_flags(it(),f,!inv,a);3920}39213922#ENDIF39233924Vector_t&swap_chop(Vector_cnt_tnVector_DEFAULT_ARG(1))3925{3926Vector_swap_erase(it(),0,n);3927return*this;3928}39293930#IFEQ(oType,oTypeVar)3931Vector_t&swap_chop(boola,boolbVector_DEFAULT_ARG(true))3932{3933Vector_swap_erase_flags(it(),0,1,a,b);3934return*this;3935}3936Vector_t&swap_chop(Vector_cnt_tn,boola,boolbVector_DEFAULT_ARG(true))3937{3938Vector_swap_erase_flags(it(),0,n,a,b);3939return*this;3940}3941#ELSE3942#if03943/* bool against int is a bad overloading technique, since it introduces3944 * very bad ambiguities */39453946Vector_t&swap_chop(boola)3947{3948Vector_swap_erase_flags(it(),0,1,a);3949return*this;3950}3951#endif39523953Vector_t&swap_chop(Vector_cnt_tn,boola)3954{3955Vector_swap_erase_flags(it(),0,n,a);3956return*this;3957}3958#ENDIF39593960Vector_t&chop(Vector_cnt_tnVector_DEFAULT_ARG(1))3961{3962Vector_chop(it(),n);3963return*this;3964}39653966#IFEQ(oType,oTypeVar)3967Vector_t&chop(boola,boolbVector_DEFAULT_ARG(true))3968{3969Vector_chop_flags(it(),1,a,b);3970return*this;3971}3972Vector_t&chop(Vector_cnt_tn,boola,boolbVector_DEFAULT_ARG(true))3973{3974Vector_chop_flags(it(),n,a,b);3975return*this;3976}3977#ELSE3978#if03979/* bool against int is a bad overloading technique, since it introduces3980 * very bad ambiguities */39813982Vector_t&chop(boola)3983{3984Vector_chop_flags(it(),1,a);3985return*this;3986}3987#endif3988Vector_t&chop(Vector_cnt_tn,boola)3989{3990Vector_chop_flags(it(),n,a);3991return*this;3992}3993#ENDIF39943995Vector_t&prepend(oTypeToucheda)3996{Vector_insert(it(),0,a);return*this;}39973998Vector_t&prepend_raw(oTypeconst*a,Vector_cnt_tn)3999{Vector_insert_raw(it(),0,a,n);return*this;}40004001Vector_t&prepend_no_copy(oTypeVarconst*a,Vector_cnt_tn)4002{Vector_insert_no_copy(it(),0,a,n);return*this;}40034004Vector_t&prepend_vector(Vector_tconst*a)4005{Vector_insert_vector(it(),0,a->it());return*this;}40064007Vector_t&prepend_vector(Vector_tconst&a)4008{Vector_insert_vector(it(),0,a.it());return*this;}40094010Vector_t&prepend_string(oTypeconst*a)4011{Vector_insert_string(it(),0,a);return*this;}401240134014Vector_t&append(oTypeToucheda)4015{Vector_append(it(),a);return*this;}40164017Vector_t&append_raw(oTypeconst*a,Vector_cnt_tn)4018{Vector_append_raw(it(),a,n);return*this;}40194020Vector_t&append_no_copy(oTypeVarconst*a,Vector_cnt_tn)4021{Vector_append_no_copy(it(),a,n);return*this;}40224023Vector_t&append_vector(Vector_tconst*a)4024{Vector_append_vector(it(),a->it());return*this;}40254026Vector_t&append_vector(Vector_tconst&a)4027{Vector_append_vector(it(),a.it());return*this;}40284029Vector_t&append_string(oTypeconst*a)4030{Vector_append_string(it(),a);return*this;}40314032Vector_t&append_subvector(4033Vector_tconst&a,4034Vector_index_tb,4035Vector_cnt_tcVector_DEFAULT_ARG(-1),4036Global_ERWIN_BOOLdVector_DEFAULT_ARG(Global_ERWIN_TRUE))4037{4038returninsert_subvector(0,a,b,c,d);4039}40404041Vector_t&append_subvector(4042Vector_tconst*a,4043Vector_index_tb,4044Vector_cnt_tcVector_DEFAULT_ARG(-1),4045Global_ERWIN_BOOLdVector_DEFAULT_ARG(Global_ERWIN_TRUE))4046{4047returninsert_subvector(0,a,b,c,d);4048}40494050#ifVector_DIRECT_RECURSION==04051/* The following function is really bad when format() is defined and you mix up4052 append and format.40534054 Compare:4055 : v->append ("There are many pieces");4056 : v->format ("There are many pieces");40574058 These are equivalent. I would choose to use append here. But look at this:4059 : v->append ("There are %d pieces", i);4060 : v->format ("There are %d pieces", i);40614062 Of course, the second one was meant here. This is an easy typo the compiler4063 cannot warn about.40644065 Therefore, Erwin does not implement the following function. It is still4066 available via append_raw.4067 */40684069/*4070 int append (oType const *a, int n)4071 { return Vector_append_raw (it(), a, n); }4072 */40734074Vector_t&prepend(Vector_tconst*a)4075{Vector_insert_vector(it(),0,a->it());return*this;}40764077Vector_t&prepend(Vector_tconst&a)4078{Vector_insert_vector(it(),0,a.it());return*this;}40794080Vector_t&prepend(oTypeconst*a)4081{Vector_insert_string(it(),0,a);return*this;}40824083Vector_t&append(Vector_tconst*a)4084{Vector_append_vector(it(),a->it());return*this;}40854086Vector_t&append(Vector_tconst&a)4087{Vector_append_vector(it(),a.it());return*this;}40884089Vector_t&append(oTypeconst*a)4090{Vector_append_string(it(),a);return*this;}40914092Vector_t&operator<<(oTypeconst*a)4093{Vector_append_string(it(),a);return*this;}40944095/* For the same reason as the one above, we will not implement the following functions, since4096 * the second one may be invoked for append ("Test", 4) with an autocast. You will then4097 * effectively append "", which is probably not what you want. The first one is4098 * not implemented for symmetry reasons.40994100Vector_t &append (4101Vector_t const *a,4102Vector_index_t b,4103Vector_index_t c Vector_DEFAULT_ARG (-1),4104 Global_ERWIN_BOOL d Vector_DEFAULT_ARG (Global_ERWIN_TRUE))4105 {4106 return append_subvector (a, b, c, d);4107 }41084109Vector_t &append (4110Vector_t const &a,4111Vector_index_t b,4112Vector_index_t c Vector_DEFAULT_ARG (-1),4113 Global_ERWIN_BOOL d Vector_DEFAULT_ARG (Global_ERWIN_TRUE))4114 {4115 return append_subvector (a, b, c, d);4116 }4117 */41184119#endif/* Vector_DIRECT_RECURSION == 0*/41204121Vector_t&operator<<(oTypeToucheda)4122{Vector_append(it(),a);return*this;}41234124Vector_t&operator<<(Vector_tconst*a)4125{Vector_append_vector(it(),a->it());return*this;}41264127Vector_t&operator<<(Vector_tconst&a)4128{Vector_append_vector(it(),a.it());return*this;}41294130/* Find family */41314132Vector_index_tfind(oTypeParamneedle)const4133{returnVector_find(it(),0,needle);}41344135Vector_index_tfind_raw(oTypeconst*needle,Vector_cnt_tn)const4136{returnVector_find_raw(it(),0,needle,n);}41374138Vector_index_tfind_string(oTypeconst*needle)const4139{returnVector_find_raw(it(),0,needle,string_length(needle));}41404141Vector_index_tfind_vector(Vector_tconst&needle)const4142{returnVector_find_raw(it(),0,needle.it()->m_table,needle.it()->m_nentries);}41434144Vector_index_tfind_vector(Vector_tconst*needle)const4145{returnVector_find_raw(it(),0,needle->it()->m_table,needle->it()->m_nentries);}41464147#ifVector_DIRECT_RECURSION==04148Vector_index_tfind(oTypeconst*needle,Vector_cnt_tn)const4149{returnVector_find_raw(it(),0,needle,n);}41504151Vector_index_tfind(oTypeconst*needle)const4152{returnVector_find_raw(it(),0,needle,string_length(needle));}41534154Vector_index_tfind(Vector_tconst&needle)const4155{returnVector_find_raw(it(),0,needle.it()->m_table,needle.it()->m_nentries);}41564157Vector_index_tfind(Vector_tconst*needle)const4158{returnVector_find_raw(it(),0,needle->it()->m_table,needle->it()->m_nentries);}4159#endif41604161Vector_index_tfind(Vector_index_ta,oTypeParamneedle)const4162{returnVector_find(it(),a,needle);}41634164Vector_index_tfind_raw(Vector_index_ta,oTypeconst*needle,Vector_cnt_tn)const4165{returnVector_find_raw(it(),a,needle,n);}41664167Vector_index_tfind_string(Vector_index_ta,oTypeconst*needle)const4168{returnVector_find_raw(it(),a,needle,string_length(needle));}41694170Vector_index_tfind_vector(Vector_index_ta,Vector_tconst&needle)const4171{returnVector_find_raw(it(),a,needle.it()->m_table,needle.it()->m_nentries);}41724173Vector_index_tfind_vector(Vector_index_ta,Vector_tconst*needle)const4174{returnVector_find_raw(it(),a,needle->it()->m_table,needle->it()->m_nentries);}41754176#ifVector_DIRECT_RECURSION==04177Vector_index_tfind(Vector_index_ta,oTypeconst*needle,Vector_cnt_tn)const4178{returnVector_find_raw(it(),a,needle,n);}41794180Vector_index_tfind(Vector_index_ta,oTypeconst*needle)const4181{returnVector_find_raw(it(),a,needle,string_length(needle));}41824183Vector_index_tfind(Vector_index_ta,Vector_tconst&needle)const4184{returnVector_find_raw(it(),a,needle.it()->m_table,needle.it()->m_nentries);}41854186Vector_index_tfind(Vector_index_ta,Vector_tconst*needle)const4187{returnVector_find_raw(it(),a,needle->it()->m_table,needle->it()->m_nentries);}4188#endif41894190/* rFind family */41914192Vector_index_trfind(oTypeParamneedle)const4193{returnVector_rfind(it(),-1,needle);}41944195Vector_index_trfind_raw(oTypeconst*needle,Vector_cnt_tn)const4196{returnVector_rfind_raw(it(),-1,needle,n);}41974198Vector_index_trfind_string(oTypeconst*needle)const4199{returnVector_rfind_raw(it(),-1,needle,string_length(needle));}42004201Vector_index_trfind_vector(Vector_tconst&needle)const4202{returnVector_rfind_raw(it(),-1,needle.it()->m_table,needle.it()->m_nentries);}42034204Vector_index_trfind_vector(Vector_tconst*needle)const4205{returnVector_rfind_raw(it(),-1,needle->it()->m_table,needle->it()->m_nentries);}42064207#ifVector_DIRECT_RECURSION==04208Vector_index_trfind(oTypeconst*needle,Vector_cnt_tn)const4209{returnVector_rfind_raw(it(),-1,needle,n);}42104211Vector_index_trfind(oTypeconst*needle)const4212{returnVector_rfind_raw(it(),-1,needle,string_length(needle));}42134214Vector_index_trfind(Vector_tconst&needle)const4215{returnVector_rfind_raw(it(),-1,needle.it()->m_table,needle.it()->m_nentries);}42164217Vector_index_trfind(Vector_tconst*needle)const4218{returnVector_rfind_raw(it(),-1,needle->it()->m_table,needle->it()->m_nentries);}4219#endif42204221Vector_index_trfind(Vector_index_ta,oTypeParamneedle)const4222{returnVector_rfind(it(),a,needle);}42234224Vector_index_trfind_raw(Vector_index_ta,oTypeconst*needle,Vector_cnt_tn)const4225{returnVector_rfind_raw(it(),a,needle,n);}42264227Vector_index_trfind_string(Vector_index_ta,oTypeconst*needle)const4228{returnVector_rfind_raw(it(),a,needle,string_length(needle));}42294230Vector_index_trfind_vector(Vector_index_ta,Vector_tconst&needle)const4231{returnVector_rfind_raw(it(),a,needle.it()->m_table,needle.it()->m_nentries);}42324233Vector_index_trfind_vector(Vector_index_ta,Vector_tconst*needle)const4234{returnVector_rfind_raw(it(),a,needle->it()->m_table,needle->it()->m_nentries);}42354236#ifVector_DIRECT_RECURSION==04237Vector_index_trfind(Vector_index_ta,oTypeconst*needle,Vector_cnt_tn)const4238{returnVector_rfind_raw(it(),a,needle,n);}42394240Vector_index_trfind(Vector_index_ta,oTypeconst*needle)const4241{returnVector_rfind_raw(it(),a,needle,string_length(needle));}42424243Vector_index_trfind(Vector_index_ta,Vector_tconst&needle)const4244{returnVector_rfind_raw(it(),a,needle.it()->m_table,needle.it()->m_nentries);}42454246Vector_index_trfind(Vector_index_ta,Vector_tconst*needle)const4247{returnVector_rfind_raw(it(),a,needle->it()->m_table,needle->it()->m_nentries);}4248#endif424942504251/* is_equal_at family4252 * FIXME: Some functions are missing. Compare to overwrite. This is because4253 * the C function has a bad calling convention. This must be fixed in4254 * the next major release of Erwin. */42554256boolis_equal_at_raw(Vector_index_ta,oTypeconst*b,Vector_cnt_tn)const4257{returnGlobal_ERWIN_TO_BOOL(Vector_is_equal_at(it(),a,b,n));}42584259boolis_equal_at_string(Vector_index_ta,oTypeconst*b)const4260{returnGlobal_ERWIN_TO_BOOL(Vector_is_equal_at(it(),a,b,string_length(b)));}42614262boolis_equal_at_vector(Vector_index_ta,Vector_tconst&b)const4263{returnGlobal_ERWIN_TO_BOOL(Vector_is_equal_at(it(),a,b.it()->m_table,b.it()->m_nentries));}42644265boolis_equal_at_vector(Vector_index_ta,Vector_tconst*b)const4266{returnGlobal_ERWIN_TO_BOOL(Vector_is_equal_at(it(),a,b->it()->m_table,b->it()->m_nentries));}42674268#ifVector_DIRECT_RECURSION==04269boolis_equal_at(Vector_index_ta,oTypeconst*b,Vector_cnt_tn)const4270{returnGlobal_ERWIN_TO_BOOL(Vector_is_equal_at(it(),a,b,n));}42714272boolis_equal_at(Vector_index_ta,oTypeconst*b)const4273{returnGlobal_ERWIN_TO_BOOL(Vector_is_equal_at(it(),a,b,string_length(b)));}42744275boolis_equal_at(Vector_index_ta,Vector_tconst&b)const4276{returnGlobal_ERWIN_TO_BOOL(Vector_is_equal_at(it(),a,b.it()->m_table,b.it()->m_nentries));}42774278boolis_equal_at(Vector_index_ta,Vector_tconst*b)const4279{returnGlobal_ERWIN_TO_BOOL(Vector_is_equal_at(it(),a,b->it()->m_table,b->it()->m_nentries));}4280#endif42814282Vector_index_tfind_if(Vector_feature_tfeature,boolinvertedVector_DEFAULT_ARG(true))4283{4284returnVector_find_if(it(),0,feature,inverted);4285}42864287Vector_index_tfind_if(Vector_index_tstart,Vector_feature_tfeature,boolinvertedVector_DEFAULT_ARG(true))4288{4289returnVector_find_if(it(),start,feature,inverted);4290}42914292Vector_index_trfind_if(Vector_feature_tfeature,boolinvertedVector_DEFAULT_ARG(true))4293{4294returnVector_rfind_if(it(),-1,feature,inverted);4295}42964297Vector_index_trfind_if(Vector_index_tstart,Vector_feature_tfeature,boolinvertedVector_DEFAULT_ARG(true))4298{4299returnVector_rfind_if(it(),start,feature,inverted);4300}43014302/* Convenience functions */43034304Vector_index_tfind_if_not(Vector_feature_tfeature,boolinvertedVector_DEFAULT_ARG(true))4305{4306returnVector_find_if(it(),0,feature,!inverted);4307}43084309Vector_index_tfind_if_not(Vector_index_tstart,Vector_feature_tfeature,boolinvertedVector_DEFAULT_ARG(true))4310{4311returnVector_find_if(it(),start,feature,!inverted);4312}43134314Vector_index_trfind_if_not(Vector_feature_tfeature,boolinvertedVector_DEFAULT_ARG(true))4315{4316returnVector_rfind_if(it(),-1,feature,!inverted);4317}43184319Vector_index_trfind_if_not(Vector_index_tstart,Vector_feature_tfeature,boolinvertedVector_DEFAULT_ARG(true))4320{4321returnVector_rfind_if(it(),start,feature,!inverted);4322}43234324/* Trimming */43254326Vector_t<rim_if(Vector_feature_tfeature,boolinvertedVector_DEFAULT_ARG(true))4327{4328Vector_ltrim_if(it(),feature,inverted);4329return*this;4330}43314332Vector_t<rim_if_not(Vector_feature_tfeature,boolinvertedVector_DEFAULT_ARG(true))4333{4334Vector_ltrim_if(it(),feature,!inverted);4335return*this;4336}43374338Vector_t&rtrim_if(Vector_feature_tfeature,boolinvVector_DEFAULT_ARG(true))4339{4340Vector_rtrim_if(it(),feature,inv);4341return*this;4342}43434344Vector_t&rtrim_if_not(Vector_feature_tfeature,boolinvVector_DEFAULT_ARG(true))4345{4346Vector_rtrim_if(it(),feature,!inv);4347return*this;4348}43494350Vector_t&trim_if(Vector_feature_tfeature,boolinvVector_DEFAULT_ARG(true))4351{4352Vector_trim_if(it(),feature,inv);4353return*this;4354}43554356Vector_t&trim_if_not(Vector_feature_tfeature,boolinvVector_DEFAULT_ARG(true))4357{4358Vector_trim_if(it(),feature,!inv);4359return*this;4360}43614362/* Mapping */43634364Vector_t&map(Vector_map_tfmap)4365{4366Vector_map(it(),fmap);4367return*this;4368}43694370#IFEQ(isChar,1)4371Vector_t<rim(void)4372{Vector_ltrim(it());return*this;}43734374Vector_t&rtrim(void)4375{Vector_rtrim(it());return*this;}43764377Vector_t&trim(void)4378{Vector_trim(it());return*this;}43794380Vector_t&chomp(void)4381{Vector_chomp(it());return*this;}43824383Vector_t&to_upper(void)4384{4385Vector_to_upper(it());4386return*this;4387}43884389Vector_t&to_lower(void)4390{4391Vector_to_lower(it());4392return*this;4393}43944395/* Additional operators for appending strings to the vector. */4396#ifdefERWIN_UNSIGNED_LONG_LONG4397Vector_t&operator<<(ERWIN_UNSIGNED_LONG_LONGa){format("%Lu",a);return*this;}4398Vector_t&operator<<(ERWIN_LONG_LONGa){format("%Ld",a);return*this;}4399#endif44004401Vector_t&operator<<(unsignedlonga){format("%lu",a);return*this;}4402Vector_t&operator<<(signedlonga){format("%ld",a);return*this;}4403Vector_t&operator<<(unsignedinta){format("%u",a);return*this;}4404Vector_t&operator<<(signedinta){format("%d",a);return*this;}44054406Vector_t&operator<<(doublea){format("%g",a);return*this;}44074408Vector_t&operator<<(void*a){format("%p",a);return*this;}44094410Vector_t&operator<<(unsignedshorta){returnoperator<<((unsignedint)a);}4411Vector_t&operator<<(signedshorta){returnoperator<<((signedint)a);}44124413Vector_t&operator<<(boola)4414{4415append((oTypeconst*)(a?"true":"false"));4416return*this;4417}44184419/* The stringify() family is for creating vectors from printing values.4420 * It was mainly added to make it easier to handle different types of4421 * integers without the user needing to know the exact type when using4422 * printf-like functions.4423 *4424 * fprintf (f, "Number of things: %s\n", +stringify(thing_count));4425 *4426 * The stringify() family is also suited for lazy people who want to do4427 * something like:4428 *4429 * #define _S +VChar::stringify4430 * #define _F +VChar().format4431 *4432 * _S is especially handy when the precise integer type is unknown and you4433 * must print via C-style formating. E.g. you can use:4434 *4435 * fprintf (f, "Number of things: %s\n", _S(thing_count));4436 *4437 * Here, no need to bother about %d vs. %ld vs. %Ld etc.4438 *4439 * Furthermore, it was decided against having a Qt-like parameter list4440 * as arg()), because the primary usage is different: for arg(),4441 * you specify the print width in the arg() call while for stringify(),4442 * it is cleaner to specify it in the printf-like format string:4443 *4444 * printf ("Length: %10s bytes\n", _S(count));4445 * vs.4446 * QString("Length: %1 byets\n").arg(count,10)4447 *4448 * So the width argument is less important for stringify().4449 * However, we do want easy access to the base argument for ints,4450 * so we move the width (and precision) to the end of the parameter4451 * list, and have the base as second for integer arguments.4452 *4453 * Further, we want the other options arguments to make it easy to4454 * quote on the fly. The options argument will be just after the4455 * base (if present).4456 *4457 * printf ("Key and value are: %s=%s",4458 * _S(key), _S(value, FO_QUOTE_C_STRING));4459 *4460 * printf ("Count: %s", _S(count, 10, FO_USE_SEP_(' ')));4461 *4462 * For integers, a base of 0 will be interpreted like 10.4463 *4464 * Also note that zero padding of numbers can be achievd by increasing4465 * the precision instead of the width:4466 *4467 * _S(5) = "5"4468 * _S(5,10,0,5,0) = " 5"4469 * _S(5,10,0,0,5) = "00005"4470 *4471 * For 'double' variant of stringify(), the char argument which may4472 * be 'e', 'f', 'g', or 'a' will take the place of the base argument.4473 */44744475#ifdefERWIN_UNSIGNED_LONG_LONG4476staticVector_tstringify(4477ERWIN_UNSIGNED_LONG_LONGa,intbase=0,intoptions=0,intwidth=0,intprec=-1)4478{4479returnVector_t().format(options|Global_FO_RADIX(base),"%*.*Lu",width,prec,a);4480}44814482staticVector_tstringify(4483ERWIN_LONG_LONGa,intbase=0,intoptions=0,intwidth=0,intprec=-1)4484{4485returnVector_t().format(options|Global_FO_RADIX(base),"%*.*Ld",width,prec,a);4486}4487#endif44884489staticVector_tstringify(4490unsignedlonga,intbase=0,intoptions=0,intwidth=0,intprec=-1)4491{4492returnVector_t().format(options|Global_FO_RADIX(base),"%*.*lu",width,prec,a);4493}44944495staticVector_tstringify(4496longa,intbase=0,intoptions=0,intwidth=0,intprec=-1)4497{4498returnVector_t().format(options|Global_FO_RADIX(base),"%*.*ld",width,prec,a);4499}45004501staticVector_tstringify(4502unsigneda,intbase=0,intoptions=0,intwidth=0,intprec=-1)4503{4504returnstringify((unsignedlong)a,base,options,width,prec);4505}45064507staticVector_tstringify(4508inta,intbase=0,intoptions=0,intwidth=0,intprec=-1)4509{4510returnstringify((long)a,base,options,width,prec);4511}45124513staticVector_tstringify(4514unsignedshorta,intbase=0,intoptions=0,intwidth=0,intprec=-1)4515{4516returnstringify((unsignedlong)a,base,options,width,prec);4517}45184519staticVector_tstringify(4520shorta,intbase=0,intoptions=0,intwidth=0,intprec=-1)4521{4522returnstringify((long)a,base,options,width,prec);4523}45244525#if04526/* Must be explicitly typecast to int to make clear code. */4527staticVector_tstringify(4528unsignedchara,intbase=0,intoptions=0,intwidth=0,intprec=-1)4529{4530returnstringify((unsignedlong)a,base,options,width,prec);4531}45324533staticVector_tstringify(4534signedchara,intbase=0,intoptions=0,intwidth=0,intprec=-1)4535{4536returnstringify((long)a,base,options,width,prec);4537}4538#endif45394540staticVector_tstringify(4541doublea,intbase=0,intoptions=0,intwidth=0,intprec=-1)4542{4543returnVector_t().format(options|Global_FO_RADIX(base),"%*.*lg",width,prec,a);4544}45454546staticVector_tstringify(chara,intoptions=0,intwidth=0)4547{4548returnVector_t().format(options,"%*c",width,a);4549}45504551staticVector_tstringify(charconst*a,intoptions=0,intwidth=0,intprec=-1)4552{4553returnVector_t().format(options,"%*.*s",width,prec,a);4554}45554556#ifdefERWIN_WIDE_CHARACTERS4557staticVector_tstringify(wchar_tconst*a,intoptions=0,intwidth=0,intprec=-1)4558{4559returnVector_t().format(options,"%*.*ls",width,prec,a);4560}4561#endif45624563staticVector_tstringify(Vector_tconst*a,intoptions=0,intwidth=0,intprec=-1)4564{4565returnVector_t().format(options|Global_FO_VECTOR,"%*.*s",4566width,prec,(charconst*)a);4567/* We are using %s to pass the vector to be able to use the precision4568 * with a gcc warning. Both %p and %s honour the Global_FO_VECTOR flag. */4569}45704571staticVector_tstringify(Vector_tconst&a,intoptions=0,intwidth=0,intprec=-1)4572{4573returnstringify(&a,options,width,prec);4574}45754576staticVector_tstringify(boola,intoptions=0,intwidth=0,intprec=-1)4577{4578returnstringify((Tcharconst*)(a?"true":"false"),options,width,prec);4579}45804581#ENDIF/* IFEQ (isChar,1) */45824583#IFEQ(isChar,1)4584intfread(FILE*fileptr,Vector_cnt_tmax_countVector_DEFAULT_ARG(-1))4585{4586returnVector_fread(it(),fileptr,max_count);4587}45884589Vector_t&fgets(FILE*fileptr,Vector_cnt_tmax_countVector_DEFAULT_ARG(-1))4590{4591Vector_fgets(it(),fileptr,max_count);4592return*this;4593}45944595Vector_index_tbasename_index(void)const4596{4597returnVector_basename_index(it());4598}45994600voidbasename_range(Vector_index_t&no1,Vector_cnt_t&length)const4601{4602Vector_basename_range(&no1,&length,it());4603}46044605Vector_t&append_directory(Vector_tconst&other)4606{4607Vector_append_directory(it(),other.it());4608return*this;4609}46104611Vector_t&append_directory(Vector_tconst*other)4612{4613Vector_append_directory(it(),other->it());4614return*this;4615}46164617Vector_t&append_basename(Vector_tconst&other)4618{4619Vector_append_basename(it(),other.it());4620return*this;4621}46224623Vector_t&append_basename(Vector_tconst*other)4624{4625Vector_append_basename(it(),other->it());4626return*this;4627}46284629Vector_t&append_config_file_name(4630oTypeconst*progname,4631boollocalVector_DEFAULT_ARG(false))4632{4633Vector_append_config_file_name(it(),progname,local);4634return*this;4635}463646374638#ifVector_NO_FORMAT==04639Vector_t&format(Tcharconst*,...)ATTR_FORMAT_PRINTF(2,3);4640Vector_t&vformat(Tcharconst*,va_list)ATTR_FORMAT_VPRINTF(2);46414642/* functions with option argument: */4643Vector_t&format(unsignedlong,Tcharconst*,...)ATTR_FORMAT_PRINTF(3,4);4644Vector_t&vformat(unsignedlong,Tcharconst*,va_list)ATTR_FORMAT_VPRINTF(3);46454646/* function with returned info */4647Vector_t&format(Vector_format_info_t*,Tcharconst*,...)ATTR_FORMAT_PRINTF(3,4);4648Vector_t&vformat(Vector_format_info_t*,Tcharconst*,va_list)ATTR_FORMAT_VPRINTF(3);46494650/* functions with returned info and option argument: */4651Vector_t&format(Vector_format_info_t*,unsignedlong,Tcharconst*,...)ATTR_FORMAT_PRINTF(4,5);4652Vector_t&vformat(Vector_format_info_t*,unsignedlong,Tcharconst*,va_list)ATTR_FORMAT_VPRINTF(4);46534654#ifGlobal_ERWIN_GLOBAL_ERRNO4655staticboolformat_quoted()ATTR_DEPRECATED;4656staticVector_index_tformat_pos()ATTR_DEPRECATED;4657#endif46584659#endif/* Vector_NO_FORMAT */4660#ENDIF/* IFEQ (isChar,1) */46614662Vector_t&make_gap(Vector_index_ta,Vector_cnt_tb)4663{4664Vector_make_gap(it(),a,b);4665return*this;4666}46674668Vector_t&make_gap(Vector_index_ta,oTypeTouchedx,Vector_cnt_tb)4669{4670Vector_make_gap_with(it(),a,x,b);4671return*this;4672}46734674/* compatibility function */4675Vector_t&make_gap_with(Vector_index_ta,oTypeTouchedx,Vector_cnt_tb)4676{4677returnmake_gap(a,x,b);4678}46794680oTypeResultzero(void)const4681{returnVector_zero(it());}46824683/* Overwrite family */46844685Vector_t&overwrite(4686Vector_index_ti,4687Vector_tconst*a,4688Vector_index_tia,4689Vector_cnt_tn)4690{4691Vector_overwrite(it(),i,a->it(),ia,n);4692return*this;4693}46944695Vector_t&overwrite(4696Vector_index_ti,4697Vector_tconst&a,4698Vector_index_tia,4699Vector_cnt_tn)4700{4701Vector_overwrite(it(),i,a.it(),ia,n);4702return*this;4703}47044705Vector_t&overwrite_raw(Vector_index_ti,oTypeconst*a,Vector_cnt_tn)4706{4707Vector_overwrite_raw(it(),i,a,n);4708return*this;4709}47104711Vector_t&overwrite_string(Vector_index_ti,oTypeconst*a)4712{4713Vector_overwrite_string(it(),i,a);4714return*this;4715}47164717Vector_t&overwrite_vector(Vector_index_ti,Vector_tconst*a)4718{4719Vector_overwrite_vector(it(),i,a->it());4720return*this;4721}47224723Vector_t&overwrite_vector(Vector_index_ti,Vector_tconst&a)4724{4725Vector_overwrite_vector(it(),i,a.it());4726return*this;4727}47284729#IFEQ(oType,oTypeVar)4730Vector_t&overwrite_flags(Vector_index_ti,oTypeconst*a,Vector_cnt_tn,booldealloc,booldocopy)4731{4732Vector_overwrite_flags(it(),i,a,n,dealloc,docopy);4733return*this;4734}4735#ENDIF47364737#ifVector_DIRECT_RECURSION==04738Vector_t&overwrite(Vector_index_ti,oTypeconst*a,Vector_cnt_tn)4739{4740Vector_overwrite_raw(it(),i,a,n);4741return*this;4742}47434744Vector_t&overwrite(Vector_index_ti,oTypeconst*a)4745{4746Vector_overwrite_string(it(),i,a);4747return*this;4748}47494750Vector_t&overwrite(Vector_index_ti,Vector_tconst*a)4751{4752Vector_overwrite_vector(it(),i,a->it());4753return*this;4754}47554756Vector_t&overwrite(Vector_index_ti,Vector_tconst&a)4757{4758Vector_overwrite_vector(it(),i,a.it());4759return*this;4760}4761#endif47624763/* Insert family */47644765Vector_t&insert(Vector_index_ti,oTypeToucheda)4766{4767Vector_insert(it(),i,a);4768return*this;4769}47704771Vector_t&insert_raw(Vector_index_ti,oTypeconst*a,Vector_cnt_tn)4772{4773Vector_insert_raw(it(),i,a,n);4774return*this;4775}47764777Vector_t&insert_no_copy(Vector_index_ti,oTypeVarconst*a,Vector_cnt_tn)4778{4779Vector_insert_no_copy(it(),i,a,n);4780return*this;4781}47824783Vector_t&insert_string(Vector_index_ti,oTypeconst*a)4784{4785Vector_insert_string(it(),i,a);4786return*this;4787}47884789Vector_t&insert_vector(Vector_index_ti,Vector_tconst*a)4790{4791Vector_insert_vector(it(),i,a->it());4792return*this;4793}47944795Vector_t&insert_vector(Vector_index_ti,Vector_tconst&a)4796{4797Vector_insert_vector(it(),i,a.it());4798return*this;4799}48004801Vector_t&insert_subvector(4802Vector_index_ti,4803Vector_tconst*a,4804Vector_index_tbVector_DEFAULT_ARG(0),4805Vector_cnt_tcVector_DEFAULT_ARG(-1),4806Global_ERWIN_BOOLdVector_DEFAULT_ARG(Global_ERWIN_TRUE))4807{4808Vector_insert_subvector(it(),i,a->it(),b,c,d?Global_ERWIN_TRUE:Global_ERWIN_FALSE);4809return*this;4810}48114812Vector_t&insert_subvector(4813Vector_index_ti,4814Vector_tconst&a,4815Vector_index_tbVector_DEFAULT_ARG(0),4816Vector_cnt_tcVector_DEFAULT_ARG(-1),4817Global_ERWIN_BOOLdVector_DEFAULT_ARG(Global_ERWIN_TRUE))4818{4819Vector_insert_subvector(it(),i,a.it(),b,c,d?Global_ERWIN_TRUE:Global_ERWIN_FALSE);4820return*this;4821}48224823#ifVector_DIRECT_RECURSION==04824Vector_t&insert(4825Vector_index_ti,4826Vector_tconst&a,4827Vector_index_tb,4828Vector_cnt_tcVector_DEFAULT_ARG(-1),4829Global_ERWIN_BOOLdVector_DEFAULT_ARG(Global_ERWIN_TRUE))4830{4831returninsert_subvector(i,a,b,c,d);4832}48334834Vector_t&insert(4835Vector_index_ti,4836Vector_tconst*a,4837Vector_index_tb,4838Vector_cnt_tcVector_DEFAULT_ARG(-1),4839Global_ERWIN_BOOLdVector_DEFAULT_ARG(Global_ERWIN_TRUE))4840{4841returninsert_subvector(i,a,b,c,d);4842}48434844Vector_t&insert(Vector_index_ti,oTypeconst*a,Vector_cnt_tn)4845{4846Vector_insert_raw(it(),i,a,n);4847return*this;4848}48494850Vector_t&insert(Vector_index_ti,oTypeconst*a)4851{4852Vector_insert_string(it(),i,a);4853return*this;4854}48554856Vector_t&insert(Vector_index_ti,Vector_tconst*a)4857{4858Vector_insert_vector(it(),i,a->it());4859return*this;4860}48614862Vector_t&insert(Vector_index_ti,Vector_tconst&a)4863{4864Vector_insert_vector(it(),i,a.it());4865return*this;4866}48674868#endif48694870Vector_cnt_tstring_length(oTypeconst*a)const4871{4872returnVector_string_length(it(),a);4873}48744875Vector_t&ensure_size(Vector_cnt_ta)4876{Vector_ensure_size(it(),a);return*this;}48774878Vector_t&ensure_size(Vector_cnt_ta,oTypeTouchedb)4879{Vector_ensure_size_with(it(),a,b);return*this;}48804881Vector_t&set_size(Vector_cnt_ta)4882{Vector_set_size(it(),a);return*this;}48834884Vector_t&set_size(Vector_cnt_ta,oTypeTouchedb)4885{Vector_set_size_with(it(),a,b);return*this;}48864887intensure_table_size(Vector_cnt_ta)4888{returnVector_ensure_table_size(it(),a);}48894890Vector_element_ptr_tas_array(void)const4891{returnVector_as_array(it());}48924893Vector_element_ptr_tas_open_array(void)const4894{returnVector_as_open_array(it());}48954896Vector_element_ptr_tas_array_detach(void)4897{returnVector_as_array_detach(it());}48984899Vector_t&ensure_heap_storage(void)4900{4901Vector_ensure_heap_storage(it());4902return*this;4903}49044905boolhas_heap_storage()const4906{4907returnVector_has_heap_storage(it());4908}49094910staticVector_cnt_tinline_store_cnt()4911{4912returnVector_inline_store_cnt();4913}49144915Vector_element_ptr_tas_open_array_detach(void)4916{returnVector_as_open_array_detach(it());}49174918#IFEQ(isChar,1)4919Vector_element_ptr_toperator+(Vector_index_ti)4920{returnnth_ptr_char(i);}49214922#ifERWIN_IGNORE_BROKEN_MS_COMPILER4923oTypeconst*operator+(Vector_index_ti)const4924{return(oTypeconst*)((Vector_class*)this)->nth_ptr_char(i);}4925#endif49264927Vector_element_ref_toperator*()4928{return*nth_ptr_char(0);}49294930#ifERWIN_IGNORE_BROKEN_MS_COMPILER4931oTypeResultoperator*()const4932{returnnth_char(0);}4933#endif49344935Vector_element_ptr_toperator+()const4936{returnas_array();}49374938#ELSE49394940Vector_element_ptr_toperator+(Vector_index_ti)4941{returnnth_ptr_check(i);}49424943#ifERWIN_IGNORE_BROKEN_MS_COMPILER4944oTypeconst*operator+(Vector_index_ti)const4945{returnnth_ptr_check(i);}4946#endif49474948Vector_element_ref_toperator*()4949{return*nth_ptr_check(0);}49504951#ifERWIN_IGNORE_BROKEN_MS_COMPILER4952oTypeResultoperator*()const4953{returnnth(0);}4954#endif49554956Vector_element_ptr_toperator+()const4957{returnas_open_array();}4958/* No 0-termination with non-charactor types. That's consistent with using4959 * nth_ptr_check here instead of nth_ptr_char for the isChar case. */49604961#ENDIF49624963Vector_t&make_heap(Vector_cmp_tfVector_DEFAULT_ARG(Vector_CMP_T_NULL))4964{4965Vector_make_heap(it(),f);4966return*this;4967}49684969Vector_index_theap_left(Vector_index_ti)const4970{4971returnVector_heap_left(it(),i);4972}49734974Vector_index_theap_right(Vector_index_ti)const4975{4976returnVector_heap_right(it(),i);4977}49784979Vector_index_theap_father(Vector_index_ti)const4980{4981returnVector_heap_father(it(),i);4982}49834984oTypeVarheap_extract(Vector_cmp_tfVector_DEFAULT_ARG(Vector_CMP_T_NULL))4985{4986returnVector_heap_extract(it(),f);4987}49884989Vector_t&heap_raise(Vector_index_ti,Vector_cmp_tfVector_DEFAULT_ARG(Vector_CMP_T_NULL))4990{4991Vector_heap_raise(it(),i,f);4992return*this;4993}49944995Vector_t&heap_sink(Vector_index_ti,Vector_cmp_tfVector_DEFAULT_ARG(Vector_CMP_T_NULL))4996{4997Vector_heap_sink(it(),i,f);4998return*this;4999}50005001Vector_t&heap_fix(Vector_index_ti,Vector_cmp_tfVector_DEFAULT_ARG(Vector_CMP_T_NULL))5002{5003Vector_heap_fix(it(),i,f);5004return*this;5005}50065007Vector_t&heap_insert(5008oTypeParamelem,Vector_cmp_tfVector_DEFAULT_ARG(Vector_CMP_T_NULL))5009{5010Vector_heap_insert(it(),elem,f);5011return*this;5012}50135014Vector_t&heap_erase(5015Vector_index_ti,Vector_cmp_tfVector_DEFAULT_ARG(Vector_CMP_T_NULL))5016{5017Vector_heap_erase(it(),i,f);5018return*this;5019}50205021Vector_t&heap_sort(Vector_cmp_tfVector_DEFAULT_ARG(Vector_CMP_T_NULL))5022{5023Vector_heap_sort(it(),f);5024return*this;5025}502650275028Vector_t&qsort(Vector_cmp_tfVector_DEFAULT_ARG(Vector_CMP_T_NULL))5029{5030Vector_qsort(it(),f);5031return*this;5032}50335034Vector_t&sort(Vector_cmp_tfVector_DEFAULT_ARG(Vector_CMP_T_NULL))5035{5036Vector_sort(it(),f);5037return*this;5038}503950405041Vector_index_tbfind(oTypeParama,Vector_cmp_tf=NULL)const5042{5043returnVector_bfind(it(),a,f);5044}50455046Global_hashval_thash_raw(void)const5047{5048returnVector_hash_raw(it());5049}50505051Global_hashval_thash(void)const5052{5053returnVector_hash(it());5054}50555056voidinit_iterator(Vector_index_t*a)const5057{5058Vector_init_iterator(it(),a);5059}50605061boolnext_iteration(Vector_index_t*a,oType*b)const5062{5063returnGlobal_ERWIN_TO_BOOL(Vector_next_iteration(it(),a,b));5064}50655066boolnext_iteration_ptr(Vector_index_t*a,oTypeVar**b)5067{5068returnGlobal_ERWIN_TO_BOOL(Vector_next_iteration_ptr(it(),a,b));5069}50705071boolnext_iteration_ptr(Vector_index_t*a,oTypeVarconst**b)const5072{5073returnGlobal_ERWIN_TO_BOOL(Vector_next_iteration_ptr_const(it(),a,b));5074}50755076voidinit_iterator_reverse(Vector_index_t*a)const5077{5078Vector_init_iterator_reverse(it(),a);5079}50805081boolnext_iteration_reverse(Vector_index_t*a,oType*b)const5082{5083returnGlobal_ERWIN_TO_BOOL(Vector_next_iteration_reverse(it(),a,b));5084}50855086boolnext_iteration_ptr_reverse(Vector_index_t*a,oTypeVar**b)5087{5088returnGlobal_ERWIN_TO_BOOL(Vector_next_iteration_ptr_reverse(it(),a,b));5089}50905091boolnext_iteration_ptr_reverse(Vector_index_t*a,oTypeVarconst**b)const5092{5093returnGlobal_ERWIN_TO_BOOL(Vector_next_iteration_ptr_const_reverse(it(),a,b));5094}50955096Vector_t&shrink(booltight=true)5097{5098Vector_shrink(it(),tight?Global_ERWIN_TRUE:Global_ERWIN_FALSE);5099return*this;5100}5101Vector_t&clear()5102{Vector_clear(it());return*this;}51035104Vector_t&clear_keep(Vector_cnt_tn)5105{Vector_clear_keep(it(),n);return*this;}51065107Vector_t&clear_no_resize()5108{Vector_clear_no_resize(it());return*this;}51095110#IFEQ(oType,oTypeVar)5111staticvoiddelete_array(Vector_element_ptr_tarray)5112{5113Vector_delete_array(array);5114}5115#ENDIF51165117#IFEQ(oType,oTypeVar)5118Vector_t&clear(boola,boolb=true)5119{Vector_clear_flags(it(),a,b);return*this;}5120#ENDIF51215122#ifdefVector_INLINE__NENTRIES5123Vector_cnt_tnentries()const5124{5125#ifdefVector_ALLOW_NULL5126if(this==NULL)return0;5127#endif5128returnm_nentries;5129}5130#else5131Vector_cnt_tnentries()const5132{returnVector_nentries(it());}5133#endif51345135boolempty()const5136{returnnentries()==0;}51375138boolnon_empty()const5139{return!empty();}51405141Vector_cnt_ttable_size()const5142{returnVector_table_size(it());}51435144intcmp(Vector_tconst*other,5145Vector_cmp_tfcmpVector_DEFAULT_ARG(Vector_CMP_T_NULL))const5146{5147if(this==NULL)5148returnother==NULL?0:-1;5149if(other==NULL)5150return+1;5151returnVector_cmp(it(),other->it(),fcmp);5152}51535154intcmp(Vector_tconst&other,5155Vector_cmp_tcmp_funcVector_DEFAULT_ARG(Vector_CMP_T_NULL))const5156{5157returncmp(&other,cmp_func);5158}51595160intpriority_cmp(Vector_tconst*other,5161Vector_cmp_tfcmpVector_DEFAULT_ARG(Vector_CMP_T_NULL))const5162{5163if(this==NULL)5164returnother==NULL?0:-1;5165if(other==NULL)5166return+1;5167returnVector_priority_cmp(it(),other->it(),fcmp);5168}51695170intpriority_cmp(Vector_tconst&other,5171Vector_cmp_tfcmpVector_DEFAULT_ARG(Vector_CMP_T_NULL))const5172{5173returnpriority_cmp(&other,fcmp);5174}51755176booloperator==(Vector_tconst&b)const5177{returncmp(b,Vector_CMP_T_NULL)==0;}/* see cmp() */51785179booloperator==(Vector_tconst*b)const5180{returncmp(b,Vector_CMP_T_NULL)==0;}/* see cmp() */51815182booloperator!=(Vector_tconst&b)const5183{returncmp(b,Vector_CMP_T_NULL)!=0;}/* see cmp() */51845185booloperator!=(Vector_tconst*b)const5186{returncmp(b,Vector_CMP_T_NULL)!=0;}/* see cmp() */51875188booloperator<=(Vector_tconst&b)const5189{returncmp(b,Vector_CMP_T_NULL)<=0;}/* see cmp() */51905191booloperator<=(Vector_tconst*b)const5192{returncmp(b,Vector_CMP_T_NULL)<=0;}/* see cmp() */51935194booloperator>=(Vector_tconst&b)const5195{returncmp(b,Vector_CMP_T_NULL)>=0;}/* see cmp() */51965197booloperator>=(Vector_tconst*b)const5198{returncmp(b,Vector_CMP_T_NULL)>=0;}/* see cmp() */51995200booloperator<(Vector_tconst&b)const5201{returncmp(b,Vector_CMP_T_NULL)<0;}/* see cmp() */52025203booloperator<(Vector_tconst*b)const5204{returncmp(b,Vector_CMP_T_NULL)<0;}/* see cmp() */52055206booloperator>(Vector_tconst&b)const5207{returncmp(b,Vector_CMP_T_NULL)>0;}/* see cmp() */52085209booloperator>(Vector_tconst*b)const5210{returncmp(b,Vector_CMP_T_NULL)>0;}/* see cmp() */52115212Vector_t&swap(Vector_index_ta,Vector_index_tb)5213{5214Vector_swap(it(),a,b);5215return*this;5216}52175218boollocate(Vector_index_t&index,oTypeParamelement,inthow)const5219{5220returnGlobal_ERWIN_TO_BOOL(Vector_locate(&index,it(),element,Vector_CMP_T_NULL,how));5221}52225223boollocate(Vector_index_t&index,5224oTypeParamelement,5225Vector_cmp_tfcmpVector_DEFAULT_ARG(Vector_CMP_T_NULL),5226inthowVector_DEFAULT_ARG(0))const5227{5228returnGlobal_ERWIN_TO_BOOL(Vector_locate(&index,it(),element,fcmp,how));5229}52305231/*--END-CLASS--*/52325233#endif/* defined __cplusplus */5234};52355236#undefVector_LOCAL_WRAPPER52375238#ifdef__cplusplus52395240#IFEQ(0,0)52415242/* For nasty code like:5243 *5244 * extern "C" {5245 * #include <erwin/erwin.h>5246 * ...5247 * }5248 *5249 * Yes, some people do such things.5250 */5251extern"C++"{5252/* some nasty global functions that are useful e.g. for forall. Note that these5253 * are not local to one vector but will be overloaded by all different vector5254 * instantiations. */52555256ERWIN_WRAPPER5257Vector_t*Global_erwin_ptr_of(Vector_t*x){returnx;}52585259ERWIN_WRAPPER5260Vector_t*Global_erwin_ptr_of(Vector_t&x){return&x;}52615262ERWIN_WRAPPER5263Vector_tconst*Global_erwin_ptr_const_of(Vector_tconst*x){returnx;}52645265ERWIN_WRAPPER5266Vector_tconst*Global_erwin_ptr_const_of(Vector_tconst&x){return&x;}5267}52685269#ELSE52705271#ifndefGlobal_erwin_ptr_of5272#defineGlobal_erwin_ptr_of(x)x5273#endif52745275#ifndefGlobal_erwin_ptr_const_of5276#defineGlobal_erwin_ptr_const_of(x)x5277#endif52785279#ENDIF52805281/* Forall macros for C++ */5282#ifndefGlobal_vector_forall5283#defineGlobal_vector_forall(v,i,h)\5284for(Global_erwin_ptr_const_of(v)->init_iterator(&(i));\5285Global_erwin_ptr_const_of(v)->next_iteration(&(i),&(h));\5286/* no stepper */)5287#endif528852895290#ifndefGlobal_vector_forall_ptr5291#defineGlobal_vector_forall_ptr(v,i,h)\5292for(Global_erwin_ptr_of(v)->init_iterator(&(i));\5293Global_erwin_ptr_of(v)->next_iteration_ptr(&(i),&(h));\5294/* no stepper */)5295#endif529652975298#ifndefGlobal_vector_forall_ptr_const5299#defineGlobal_vector_forall_ptr_const(v,i,h)\5300for(Global_erwin_ptr_const_of(v)->init_iterator(&(i));\5301Global_erwin_ptr_const_of(v)->next_iteration_ptr(&(i),&(h));\5302/* no stepper */)5303#endif530453055306#ifndefGlobal_vector_forall_keys5307#defineGlobal_vector_forall_keys(v,i)\5308for((i)=0;((Vector_index_t)(i))<Global_erwin_ptr_const_of(v)->nentries();(i)++)5309#endif531053115312#ifndefGlobal_vector_forall_values5313#defineGlobal_vector_forall_values(v,h)\5314for(Vector_index_tERWIN_GENSYM(erwin_local_j)=-1;\5315Global_erwin_ptr_const_of(v)->next_iteration(&ERWIN_GENSYM(erwin_local_j),&(h));\5316/* no stepper */)5317#endif531853195320#ifndefGlobal_vector_forall_values_ptr5321#defineGlobal_vector_forall_values_ptr(v,h)\5322for(Vector_index_tERWIN_GENSYM(erwin_local_j)=-1;\5323Global_erwin_ptr_of(v)->next_iteration_ptr(&ERWIN_GENSYM(erwin_local_j),&(h));\5324/* no stepper */)5325#endif532653275328#ifndefGlobal_vector_forall_values_ptr_const5329#defineGlobal_vector_forall_values_ptr_const(v,h)\5330for(Vector_index_tERWIN_GENSYM(erwin_local_j)=-1;\5331Global_erwin_ptr_const_of(v)->next_iteration_ptr(&ERWIN_GENSYM(erwin_local_j),&(h));\5332/* no stepper */)5333#endif533453355336#ifndefGlobal_vector_forall_reverse5337#defineGlobal_vector_forall_reverse(v,i,h)\5338for(Global_erwin_ptr_const_of(v)->init_iterator_reverse(&(i));\5339Global_erwin_ptr_const_of(v)->next_iteration_reverse(&(i),&(h));\5340/* no stepper */)5341#endif534253435344#ifndefGlobal_vector_forall_ptr_reverse5345#defineGlobal_vector_forall_ptr_reverse(v,i,h)\5346for(Global_erwin_ptr_of(v)->init_iterator_reverse(&(i));\5347Global_erwin_ptr_of(v)->next_iteration_ptr_reverse(&(i),&(h));\5348/* no stepper */)5349#endif535053515352#ifndefGlobal_vector_forall_ptr_const_reverse5353#defineGlobal_vector_forall_ptr_const_reverse(v,i,h)\5354for(Global_erwin_ptr_const_of(v)->init_iterator_reverse(&(i));\5355Global_erwin_ptr_const_of(v)->next_iteration_ptr_reverse(&(i),&(h));\5356/* no stepper */)5357#endif535853595360#ifndefGlobal_vector_forall_keys_reverse5361#defineGlobal_vector_forall_keys_reverse(v,i)\5362for((i)=Global_erwin_ptr_const_of(v)->nentries()-1;((Vector_index_t)(i))>=0;(i)--)5363#endif536453655366#ifndefGlobal_vector_forall_values_reverse5367#defineGlobal_vector_forall_values_reverse(v,h)\5368for(Vector_index_tERWIN_GENSYM(erwin_local_j)=Global_erwin_ptr_const_of(v)->nentries();\5369Global_erwin_ptr_const_of(v)\5370->next_iteration_reverse(&ERWIN_GENSYM(erwin_local_j),&(h));\5371/* no stepper */)5372#endif53735374#ifndefGlobal_vector_forall_values_ptr_reverse5375#defineGlobal_vector_forall_values_ptr_reverse(v,h)\5376for(Vector_index_tERWIN_GENSYM(erwin_local_j)=\5377Global_erwin_ptr_const_of(v)->nentries();\5378Global_erwin_ptr_of(v)\5379->next_iteration_ptr_reverse(&ERWIN_GENSYM(erwin_local_j),&(h));\5380/* no stepper */)5381#endif53825383#ifndefGlobal_vector_forall_values_ptr_const_reverse5384#defineGlobal_vector_forall_values_ptr_const_reverse(v,h)\5385for(Vector_index_tERWIN_GENSYM(erwin_local_j)=\5386Global_erwin_ptr_const_of(v)->nentries();\5387Global_erwin_ptr_const_of(v)\5388->next_iteration_ptr_reverse(&ERWIN_GENSYM(erwin_local_j),&(h));\5389/* no stepper */)5390#endif53915392#endif/* defined __cplusplus */53935394/* ********************************************************************** */5395/* Inline implementations: */53965397#ifVector_POSITION_POINTER53985399ERWIN_WRAPPERVector_index_t*Vector_pos_ptr(Vector_t*);5400ERWIN_WRAPPERVector_index_t*Vector_pos_ptr(Vector_t*x){return&x->m_pos;}54015402ERWIN_WRAPPERVector_index_tVector_pos(Vector_t*);5403ERWIN_WRAPPERVector_index_tVector_pos(Vector_t*x){returnx->m_pos;}54045405ERWIN_WRAPPERvoidVector_set_pos(Vector_t*,Vector_index_t);5406ERWIN_WRAPPERvoidVector_set_pos(Vector_t*x,Vector_index_ty){x->m_pos=y;}54075408#endif54095410#ifdefVector_INLINE__NTH54115412ERWIN_STATIC_INLINE5413oTypeResultVector_nth(Vector_tconst*self,Vector_index_tidx)5414{5415returnself->m_table[idx];5416}54175418#endif54195420#ifdefVector_INLINE__NENTRIES54215422ERWIN_STATIC_INLINE5423Vector_cnt_tVector_nentries(Vector_tconst*self)5424{5425returnself->m_nentries;5426}54275428ERWIN_STATIC_INLINE5429Global_ERWIN_BOOLVector_empty(Vector_tconst*self)5430{5431returnself->m_nentries==0;5432}54335434#endif54355436#endif/* ERWINMM_Vector_ErwinHExt */