GAMS Data eXchange (GDX) API
Low-level "eXPert level" C++ API for reading and writing GAMS Data eXchange files
Loading...
Searching...
No Matches
gdx.hpp
1/*
2 * GAMS - General Algebraic Modeling System GDX API
3 *
4 * Copyright (c) 2017-2026 GAMS Software GmbH <support@gams.com>
5 * Copyright (c) 2017-2026 GAMS Development Corp. <support@gams.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26// WARNING: This file is generated by the "yaml2doxy" script from the API definition file "gdxapi.yaml"
27
28#pragma once
29
30#include "gxfile.hpp"
31
32#ifndef GDX_NS
33#define GDX_NS gdxlib::
34#endif
35
36namespace GDX_NS gdx
37{
38
41{
42public:
47 explicit TGXFileObj();
48
55
56 enum class TraceLevels : uint8_t
57 {
58 trl_none,
59 trl_errors,
60 trl_some,
61 trl_all
62 };
63 void SetTraceLevel( TraceLevels tl );
64
71 [[nodiscard]] int gdxStoreDomainSets() const;
72
79 void gdxStoreDomainSetsSet(int flag);
80
91 [[nodiscard]] int gdxAllowBogusDomains() const;
92
104 void gdxAllowBogusDomainsSet(int flag);
105
110 [[nodiscard]] int gdxMapAcronymsToNaN() const;
111
116 void gdxMapAcronymsToNaNSet(int flag);
117
129 int gdxAddAlias( const char *Id1, const char *Id2 );
130
139 int gdxAutoConvert( int NV );
140
145 int64_t gdxGetMemoryUsed();
146
149
174 int gdxAcronymAdd( const char *AName, const char *Txt, int AIndx );
175
181 int gdxAcronymCount() const;
182
195 int gdxAcronymGetInfo( int N, char *AName, char *Txt, int &AIndx ) const;
196
212 int gdxAcronymGetMapping( int N, int &orgIndx, int &newIndx, int &autoIndex );
213
220 int gdxAcronymIndex( double V ) const;
221
233 int gdxAcronymName( double V, char *AName );
234
251 int gdxAcronymNextNr( int NV );
252
275 int gdxAcronymSetInfo( int N, const char *AName, const char *Txt, int AIndx );
276
284 double gdxAcronymValue( int AIndx ) const;
285
287
288
291
300 int gdxSymbolAddComment( int SyNr, const char *Txt );
301
312 int gdxSymbolGetComment( int SyNr, int N, char *Txt );
313
315
316
319
329 int gdxSymbolGetDomain( int SyNr, int *DomainSyNrs );
330
357 int gdxSymbolGetDomainX( int SyNr, char **DomainIDs );
358
372 int gdxSymbolSetDomain( const char **DomainIDs );
373
386 int gdxSymbolSetDomainX( int SyNr, const char **DomainIDs );
387
417 int gdxGetDomainElements( int SyNr, int DimPos, int FilterNr, TDomainIndexProc_t DP, int &NrElem, void *Uptr );
418
420
421
424
429 int gdxErrorCount() const;
430
439 int gdxErrorStr( int ErrNr, char *ErrMsg ) const;
440
450 int gdxGetLastError();
451
453
454
457
464 int gdxClose();
465
488 int gdxOpenAppend( const char *FileName, const char *Producer, int &ErrNr );
489
507 int gdxOpenRead( const char *FileName, int &ErrNr );
508
528 int gdxOpenReadEx( const char *FileName, int ReadMode, int &ErrNr );
529
541 int gdxOpenWrite( const char *FileName, const char *Producer, int &ErrNr );
542
566 int gdxOpenWriteEx( const char *FileName, const char *Producer, int Compr, int &ErrNr );
567
569
570
573
580 int gdxFilterExists( int FilterNr );
581
592 int gdxFilterRegister( int UelMap );
593
599 int gdxFilterRegisterDone();
600
610 int gdxFilterRegisterStart( int FilterNr );
611
613
614
617
633 int gdxFindSymbol( const char *SyId, int &SyNr );
634
645 int gdxGetUEL( int UelNr, char *Uel );
646
648
649
652
661 int gdxSymbIndxMaxLength( int SyNr, int *LengthInfo );
662
667 int gdxSymbMaxLength() const;
668
674 int gdxUELMaxLength();
675
677
678
681
691 int gdxDataErrorCount() const;
692
713 int gdxDataErrorRecord( int RecNr, int *KeyInt, double *Values );
714
733 int gdxDataErrorRecordX( int RecNr, int *KeyInt, double *Values );
734
741 int gdxDataReadDone();
742
803 int gdxDataReadFilteredStart( int SyNr, const int *FilterAction, int &NrRecs );
804
814 int gdxDataReadMap( int RecNr, int *KeyInt, double *Values, int &DimFrst );
815
824 int gdxDataReadMapStart( int SyNr, int &NrRecs );
825
835 int gdxDataReadRaw( int *KeyInt, double *Values, int &DimFrst );
836
857 int gdxDataReadRawFast( int SyNr, TDataStoreProc_t DP, int &NrRecs );
858
886 int gdxDataReadRawFastEx( int SyNr, TDataStoreExProc_t DP, int &NrRecs, void *Uptr );
887
927 int gdxDataReadRawFastFilt( int SyNr, const char **UelFilterStr, TDataStoreFiltProc_t DP );
928
937 int gdxDataReadRawStart( int SyNr, int &NrRecs );
938
960 int gdxDataReadSlice( const char **UelFilterStr, int &Dimen, TDataStoreProc_t DP );
961
971 int gdxDataReadSliceStart( int SyNr, int *ElemCounts );
972
990 int gdxDataReadStr( char **KeyStr, double *Values, int &DimFrst );
991
1010 int gdxDataReadStrStart( int SyNr, int &NrRecs );
1011
1023 int gdxDataSliceUELS( const int *SliceKeyInt, char **KeyStr );
1024
1026
1027
1030
1038 int gdxGetSpecialValues( double *AVals );
1039
1047 int gdxMapValue( double D, int &sv );
1048
1054 int gdxResetSpecialValues();
1055
1067 int gdxSetReadSpecialValues( const double *AVals );
1068
1081 int gdxSetSpecialValues( const double *AVals );
1082
1084
1085
1088
1094 int gdxFileInfo( int &FileVer, int &ComprLev ) const;
1095
1102 int gdxSymbolDim( int SyNr );
1103
1115 int gdxSymbolInfo( int SyNr, char *SyId, int &Dimen, int &Typ );
1116
1180 int gdxSymbolInfoX( int SyNr, int &RecCnt, int &UserInfo, char *ExplTxt );
1181
1188 int gdxSystemInfo( int &SyCnt, int &UelCnt );
1189
1200 int gdxCurrentDim() const;
1201
1203
1204
1207
1218 int gdxAddSetText( const char *Txt, int &TxtNr );
1219
1255 int gdxGetElemText( int TxtNr, char *Txt, int &Node );
1256
1264 int gdxSetHasText( int SyNr );
1265
1276 int gdxSetTextNodeNr( int TxtNr, int Node );
1277
1279
1280
1283
1288 int gdxUELRegisterDone();
1289
1303 int gdxUELRegisterMap( int UMap, const char *Uel );
1304
1310 int gdxUELRegisterMapStart();
1311
1323 int gdxUELRegisterRaw( const char *Uel );
1324
1330 int gdxUELRegisterRawStart();
1331
1345 int gdxUELRegisterStr( const char *Uel, int &UelNr );
1346
1352 int gdxUELRegisterStrStart();
1353
1361 int gdxUMFindUEL( const char *Uel, int &UelNr, int &UelMap );
1362
1372 int gdxUMUelGet( int UelNr, char *Uel, int &UelMap );
1373
1381 int gdxUMUelInfo( int &UelCnt, int &HighMap );
1382
1391 int gdxRenameUEL( const char *OldName, const char *NewName );
1392
1394
1395
1398
1404 static int gdxGetDLLVersion( char *V );
1405
1414 int gdxFileVersion( char *FileStr, char *ProduceStr ) const;
1415
1422 int gdxSetTraceLevel( int N, const char *s );
1423
1425
1426
1429
1435 int gdxDataWriteDone();
1436
1444 int gdxDataWriteMap( const int *KeyInt, const double *Values );
1445
1509 int gdxDataWriteMapStart( const char *SyId, const char *ExplTxt, int Dimen, int Typ, int UserInfo );
1510
1524 int gdxDataWriteRaw( const int *KeyInt, const double *Values );
1525
1591 int gdxDataWriteRawStart( const char *SyId, const char *ExplTxt, int Dimen, int Typ, int UserInfo );
1592
1664 int gdxDataWriteRawStartKeyBounds( const char *SyId, const char *ExplTxt, int Dimen, int Typ, int UserInfo, const int *MinUELIndices, const int *MaxUELIndices );
1665
1720 int gdxDataWriteStr( const char **KeyStr, const double *Values );
1721
1737 int gdxDataWriteStrStart( const char *SyId, const char *ExplTxt, int Dimen, int Typ, int UserInfo );
1738
1740
1741
1742
1743private:
1744std::unique_ptr<gdlib::gmsstrm::TMiBufferedStream> FFile;
1745std::string lastFileName {};
1746TgxFileMode fmode { f_not_open }, fmode_AftReg { f_not_open };
1747enum : uint8_t
1748{
1749 stat_notopen,
1750 stat_read,
1751 stat_write
1752} fstatus { stat_notopen };
1753int fComprLev {};
1754std::unique_ptr<TUELTable> UELTable;
1755std::unique_ptr<TSetTextList> SetTextList {};
1756std::unique_ptr<int[]> MapSetText {};
1757int FCurrentDim {};
1758std::array<int, GLOBAL_MAX_INDEX_DIM> LastElem {}, PrevElem {}, MinElem {}, MaxElem {};
1759std::array<std::array<char, GLOBAL_UEL_IDENT_SIZE>, GLOBAL_MAX_INDEX_DIM> LastStrElem {};
1760int DataSize {};
1761tvarvaltype LastDataField {};
1762std::unique_ptr<TNameList> NameList;
1763std::unique_ptr<TDomainStrList> DomainStrList;
1764std::unique_ptr<LinkedDataType> SortList;
1765std::optional<LinkedDataIteratorType> ReadPtr;
1766std::unique_ptr<TTblGamsDataImpl<double>> ErrorList;
1767PgdxSymbRecord CurSyPtr {};
1768int ErrCnt {}, ErrCntTotal {};
1769int LastError {}, LastRepError {};
1770std::unique_ptr<TFilterList> FilterList;
1771TDFilter *CurFilter {};
1772TDomainList DomainList {};
1773bool StoreDomainSets { true }, AllowBogusDomain { true }, MapAcrToNaN {};
1774TIntlValueMapDbl intlValueMapDbl {}, readIntlValueMapDbl {};
1775TIntlValueMapI64 intlValueMapI64 {};
1776TraceLevels TraceLevel { TraceLevels::trl_all };
1777std::string TraceStr;
1778int VersionRead {};
1779std::string FProducer, FProducer2, FileSystemID;
1780int64_t MajorIndexPosition {};
1781int64_t NextWritePosition {};
1782int DataCount {}, NrMappedAdded {};
1783std::array<TgdxElemSize, GLOBAL_MAX_INDEX_DIM> ElemType {};
1784std::string MajContext;
1785std::array<TIntegerMapping, GLOBAL_MAX_INDEX_DIM> SliceIndxs {}, SliceRevMap {};
1786int SliceSyNr {};
1787std::array<std::string, GMS_MAX_INDEX_DIM> SliceElems;
1788bool DoUncompress {}, // when reading
1789 CompressOut {};// when writing
1790int DeltaForWrite {}; // delta for last dimension or first changed dimension
1791int DeltaForRead {}; // first position indicating change
1792double Zvalacr {}; // tricky
1793std::unique_ptr<TAcronymList> AcronymList;
1794std::array<TSetBitMap *, GLOBAL_MAX_INDEX_DIM> WrBitMaps {};
1795bool ReadUniverse {};
1796int UniverseNr {}, UelCntOrig {};// original uel count when we open the file
1797int AutoConvert { 1 };
1798int NextAutoAcronym {};
1799bool AppendActive {};
1800
1801#ifndef VERBOSE_TRACE
1802const TraceLevels defaultTraceLevel { TraceLevels::trl_none };
1803const bool verboseTrace {};
1804#else
1805const TraceLevels defaultTraceLevel { TraceLevels::trl_all };
1806const bool verboseTrace { true };
1807#endif
1808
1809//api wrapper magic for Fortran
1810TDataStoreFiltProc_t gdxDataReadRawFastFilt_DP {};
1811TDomainIndexProc_t gdxGetDomainElements_DP {};
1812
1813int64_t ReadUELPos {}, ReadAcronymPos {}, ReadSetTextPos {};
1814bool UelReadDeferred {}, SetTextReadDeferred {};
1815
1816bool PrepareSymbolWrite( std::string_view Caller, const char *AName, const char *AText, int ADim, int AType, int AUserInfo );
1817int PrepareSymbolRead( std::string_view Caller, int SyNr, const int *ADomainNrs, TgxFileMode newmode );
1818
1819void InitErrors();
1820void SetError( int N );
1821void ReportError( int N );
1822bool ErrorCondition( bool cnd, int N );
1823
1824bool MajorCheckMode( std::string_view Routine, TgxFileMode m );
1825bool MajorCheckMode( std::string_view Routine, const TgxModeSet &MS );
1826
1827bool CheckMode( std::string_view Routine );
1828bool CheckMode( std::string_view Routine, TgxFileMode m );
1829bool CheckMode( std::string_view Routine, const TgxModeSet &MS );
1830
1831void WriteTrace( std::string_view s ) const;
1832void InitDoWrite( int NrRecs );
1833bool DoWrite( const int *AElements, const double *AVals );
1834bool DoRead( double *AVals, int &AFDim );
1835void AddToErrorListDomErrs( const std::array<int, GLOBAL_MAX_INDEX_DIM> &AElements, const double *AVals );
1836void AddToErrorList( const int *AElements, const double *AVals );
1837void GetDefaultRecord( double *Avals ) const;
1838double AcronymRemap( double V );
1839bool IsGoodNewSymbol( const char *s );
1840bool ResultWillBeSorted( const int *ADomainNrs ) const;
1841
1842int gdxOpenReadXX( const char *Afn, int filemode, int ReadMode, int &ErrNr );
1843int ReadUELTable(bool isDeferred);
1844int ReadSetTextList(bool isDeferred);
1845
1846// This one is a helper function for a callback from a Fortran client
1847void gdxGetDomainElements_DP_FC( int RawIndex, int MappedIndex, void *Uptr );
1848int gdxDataReadRawFastFilt_DP_FC( const int *Indx, const double *Vals, void *Uptr );
1849
1850void mapDefaultRecordValues(double *AVals) const;
1851
1852public:
1853bool gdxGetDomainElements_DP_CallByRef {},
1854 gdxDataReadRawFastFilt_DP_CallByRef {},
1855 gdxDataReadRawFastEx_DP_CallByRef {};
1856};
1857
1858}// namespace gdx
1859
1860namespace gdx = GDX_NS gdx;
Definition: gdx.hpp:41
Definition: gxfile.hpp:196
Definition: gxfile.hpp:92