resonance 1.0.1
Loading...
Searching...
No Matches
remixdirinfo.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <stdio.h>
5#include <stdlib.h>
6#include <vector>
7
8#include "os/hxstr.h"
9
11constexpr int kMaxRemixesPerDirectory = 13;
12
14constexpr int kRemixFileNumberTextSize = 16;
15
17constexpr char kFirstRemixPayloadFileName[] = "1";
18
25constexpr int kRemixDirNumberOffset = 14;
26
51public:
62 RemixDirInfo(const HxStr &dirName, unsigned int nEntryCount)
63 : name(dirName), entryCount(nEntryCount), highestFileNumber(0) {
64 dirNumber =
65 atoi((name.mStr != nullptr ? name.mStr : g_szEmptyString) + kRemixDirNumberOffset);
66 }
67
79 static void RaiseHighestFileNumber(std::vector<RemixDirInfo> &infos,
80 const HxStr &dirName,
81 unsigned int nFileNumber) {
82 for (std::vector<RemixDirInfo>::iterator it = infos.begin(); it != infos.end(); ++it) {
83 if (it->name == dirName) {
84 it->highestFileNumber = std::max(nFileNumber, it->highestFileNumber);
85 return;
86 }
87 }
88 }
89
102 static HxStr NextPayloadFileName(const std::vector<RemixDirInfo> &infos) {
103 for (std::vector<RemixDirInfo>::const_iterator it = infos.begin(); it != infos.end();
104 ++it) {
105 if (it->entryCount < kMaxRemixesPerDirectory) {
106 char szNumber[kRemixFileNumberTextSize];
107 sprintf(szNumber, "%d", it->highestFileNumber + 1);
108 return HxStr(szNumber);
109 }
110 }
112 }
113
115 unsigned int dirNumber;
116 unsigned int entryCount;
117 unsigned int highestFileNumber;
118};
Heap-allocated NUL-terminated string.
Definition hxstr.h:41
unsigned int highestFileNumber
Definition remixdirinfo.h:117
static void RaiseHighestFileNumber(std::vector< RemixDirInfo > &infos, const HxStr &dirName, unsigned int nFileNumber)
Raise the highest file number of the first record named after a directory.
Definition remixdirinfo.h:79
static HxStr NextPayloadFileName(const std::vector< RemixDirInfo > &infos)
Name the payload file a new remix takes.
Definition remixdirinfo.h:102
unsigned int entryCount
Definition remixdirinfo.h:116
unsigned int dirNumber
Definition remixdirinfo.h:115
HxStr name
Definition remixdirinfo.h:114
RemixDirInfo(const HxStr &dirName, unsigned int nEntryCount)
Record a directory the listing found, with no file number seen yet.
Definition remixdirinfo.h:62
const char * g_szEmptyString
Text an empty HxStr points at, and the substitute for a null buffer.
constexpr char kFirstRemixPayloadFileName[]
Payload file name of the first remix in a fresh directory.
Definition remixdirinfo.h:17
constexpr int kRemixDirNumberOffset
Characters of a remix save directory name that precede its number.
Definition remixdirinfo.h:25
constexpr int kMaxRemixesPerDirectory
Entries one remix save directory accepts before SaveRemixMCT considers it full.
Definition remixdirinfo.h:11
constexpr int kRemixFileNumberTextSize
Bytes of the stack buffer a payload file number is formatted into.
Definition remixdirinfo.h:14