Skip to content

Commit 41573df

Browse files
committed
added STL compatible access functions to TArray.
This allows using them in templates made for STL containers.
1 parent 52c878c commit 41573df

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

src/common/engine/sc_man.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ bool FScanner::OpenFile (const char *name)
150150
auto filebuff = fr.Read();
151151
if (filebuff.size() == 0 && filesize > 0) return false;
152152

153-
ScriptBuffer = FString((const char *)filebuff.data(), filesize);
153+
ScriptBuffer = FString(filebuff.string(), filesize);
154154
ScriptName = name; // This is used for error messages so the full file name is preferable
155155
LumpNum = -1;
156156
PrepareScript ();

src/common/engine/sc_man.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,10 @@ class FScanner
7171
void Open(const char *lumpname);
7272
bool OpenFile(const char *filename);
7373
void OpenMem(const char *name, const char *buffer, int size);
74-
void OpenMem(const char *name, const TArray<uint8_t> &buffer)
75-
{
76-
OpenMem(name, (const char*)buffer.Data(), buffer.Size());
77-
}
78-
void OpenMem(const char* name, const std::vector<uint8_t>& buffer)
74+
template<class T>
75+
void OpenMem(const char* name, const T& buffer)
7976
{
77+
static_assert(sizeof(T::value_type) == 1);
8078
OpenMem(name, (const char*)buffer.data(), (int)buffer.size());
8179
}
8280
void OpenString(const char *name, FString buffer);

src/common/utility/tarray.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,44 @@ class TArray
657657
std::swap(Most, other.Most);
658658
}
659659

660+
// aliases with STL compliant names to allow using TArrays with templates designed for STL containers
661+
662+
size_t size() const
663+
{
664+
return Count;
665+
}
666+
667+
T* data() const
668+
{
669+
return Data();
670+
}
671+
672+
T& front() const
673+
{
674+
return *Data();
675+
}
676+
677+
T& back() const
678+
{
679+
return Last();
680+
}
681+
682+
void resize(size_t i)
683+
{
684+
Resize(i);
685+
}
686+
687+
void push_back(T& elem)
688+
{
689+
Push(elem);
690+
}
691+
692+
void clear()
693+
{
694+
Clear();
695+
}
696+
697+
660698
private:
661699
T *Array;
662700
unsigned int Count;

0 commit comments

Comments
 (0)