• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polserver / polserver / 21008991693

14 Jan 2026 08:35PM UTC coverage: 60.508% (+0.001%) from 60.507%
21008991693

push

github

web-flow
ClangTidy "modernize-use-override" (#851)

* let clang-tidy do its thing

* Automated clang-tidy change: modernize-use-override

* compile test

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>

82 of 153 new or added lines in 40 files covered. (53.59%)

3 existing lines in 3 files now uncovered.

44461 of 73479 relevant lines covered (60.51%)

512457.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.84
/pol-core/pol/storage.cpp
1
/** @file
2
 *
3
 * @par History
4
 * - 2005/11/26 Shinigami: changed "strcmp" into "stricmp" to suppress Script Errors
5
 */
6

7

8
#include "storage.h"
9

10
#include <exception>
11
#include <string>
12
#include <time.h>
13

14
#include "../bscript/berror.h"
15
#include "../bscript/bobject.h"
16
#include "../bscript/contiter.h"
17
#include "../bscript/impstr.h"
18
#include "../clib/cfgelem.h"
19
#include "../clib/cfgfile.h"
20
#include "../clib/clib.h"
21
#include "../clib/logfacility.h"
22
#include "../clib/rawtypes.h"
23
#include "../clib/stlutil.h"
24
#include "../clib/streamsaver.h"
25
#include "../plib/poltype.h"
26
#include "../plib/systemstate.h"
27
#include "containr.h"
28
#include "fnsearch.h"
29
#include "globals/object_storage.h"
30
#include "globals/uvars.h"
31
#include "item/item.h"
32
#include "loaddata.h"
33
#include "mkscrobj.h"
34
#include "ufunc.h"
35

36
namespace Pol
37
{
38
namespace Core
39
{
40
using namespace Bscript;
41

42
StorageArea::StorageArea( std::string name ) : _name( name ) {}
6✔
43

44
StorageArea::~StorageArea()
6✔
45
{
46
  while ( !_items.empty() )
10✔
47
  {
48
    Cont::iterator itr = _items.begin();
4✔
49
    Items::Item* item = ( *itr ).second;
4✔
50
    item->destroy();
4✔
51
    _items.erase( itr );
4✔
52
  }
53
}
6✔
54

55
size_t StorageArea::estimateSize() const
×
56
{
57
  size_t size = _name.capacity() + Clib::memsize( _items );
×
58
  return size;
×
59
}
60

61

62
Items::Item* StorageArea::find_root_item( const std::string& name )
6✔
63
{
64
  // LINEAR_SEARCH
65
  Cont::iterator itr = _items.find( name );
6✔
66
  if ( itr != _items.end() )
6✔
67
  {
68
    return ( *itr ).second;
6✔
69
  }
70
  return nullptr;
×
71
}
72

73
bool StorageArea::delete_root_item( const std::string& name )
1✔
74
{
75
  Cont::iterator itr = _items.find( name );
1✔
76
  if ( itr != _items.end() )
1✔
77
  {
78
    Items::Item* item = ( *itr ).second;
1✔
79
    item->destroy();
1✔
80
    _items.erase( itr );
1✔
81
    return true;
1✔
82
  }
83
  return false;
×
84
}
85

86
void StorageArea::insert_root_item( Items::Item* item )
5✔
87
{
88
  item->inuse( true );
5✔
89

90
  _items.insert( make_pair( item->name(), item ) );
5✔
91
}
5✔
92

93
extern Items::Item* read_item( Clib::ConfigElem& elem );  // from UIMPORT.CPP
94

95
void StorageArea::load_item( Clib::ConfigElem& elem )
6✔
96
{
97
  u32 container_serial = 0;                                  // defaults to item at storage root,
6✔
98
  (void)elem.remove_prop( "CONTAINER", &container_serial );  // so the return value can be ignored
6✔
99

100
  Items::Item* item = read_item( elem );
6✔
101
  // Austin added 8/10/2006, protect against further crash if item is null. Should throw instead?
102
  if ( item == nullptr )
6✔
103
  {
104
    elem.warn_with_line( "Error reading item SERIAL or OBJTYPE." );
×
105
    return;
×
106
  }
107
  if ( container_serial == 0 )
6✔
108
  {
109
    insert_root_item( item );
2✔
110
  }
111
  else
112
  {
113
    Items::Item* cont_item = Core::system_find_item( container_serial );
4✔
114

115
    if ( cont_item )
4✔
116
    {
117
      add_loaded_item( cont_item, item );
4✔
118
    }
119
    else
120
    {
121
      defer_item_insertion( item, container_serial );
×
122
    }
123
  }
124
}
125
StorageArea* Storage::find_area( const std::string& name )
3✔
126
{
127
  AreaCont::iterator itr = areas.find( name );
3✔
128
  if ( itr == areas.end() )
3✔
129
    return nullptr;
×
130
  else
131
    return ( *itr ).second;
3✔
132
}
133

134
StorageArea* Storage::create_area( const std::string& name )
6✔
135
{
136
  AreaCont::iterator itr = areas.find( name );
6✔
137
  if ( itr == areas.end() )
6✔
138
  {
139
    StorageArea* area = new StorageArea( name );
6✔
140
    areas[name] = area;
6✔
141
    return area;
6✔
142
  }
143
  else
144
  {
145
    return ( *itr ).second;
×
146
  }
147
}
148

149
StorageArea* Storage::create_area( Clib::ConfigElem& elem )
3✔
150
{
151
  const char* rest = elem.rest();
3✔
152
  if ( rest != nullptr && rest[0] )
3✔
153
  {
154
    return create_area( rest );
×
155
  }
156
  else
157
  {
158
    std::string name = elem.remove_string( "NAME" );
3✔
159
    return create_area( name );
3✔
160
  }
3✔
161
}
162

163

164
void StorageArea::print( Clib::StreamWriter& sw ) const
6✔
165
{
166
  for ( const auto& cont_item : _items )
10✔
167
  {
168
    const Items::Item* item = cont_item.second;
4✔
169
    if ( item->saveonexit() )
4✔
170
      item->printOn( sw );
4✔
171
  }
172
}
6✔
173

174
void StorageArea::on_delete_realm( Realms::Realm* realm )
×
175
{
176
  for ( Cont::const_iterator itr = _items.begin(), itrend = _items.end(); itr != itrend; ++itr )
×
177
  {
178
    Items::Item* item = ( *itr ).second;
×
179
    if ( item )
×
180
    {
181
      setrealmif( item, (void*)realm );
×
182
      if ( item->isa( UOBJ_CLASS::CLASS_CONTAINER ) )
×
183
      {
184
        UContainer* cont = static_cast<UContainer*>( item );
×
185
        cont->for_each_item( setrealmif, (void*)realm );
×
186
      }
187
    }
188
  }
189
}
×
190

191
void Storage::on_delete_realm( Realms::Realm* realm )
4✔
192
{
193
  for ( AreaCont::const_iterator itr = areas.begin(), itrend = areas.end(); itr != itrend; ++itr )
4✔
194
  {
195
    itr->second->on_delete_realm( realm );
×
196
  }
197
}
4✔
198

199
void Storage::read( Clib::ConfigFile& cf )
1✔
200
{
201
  static int num_until_dot = 1000;
202
  unsigned int nobjects = 0;
1✔
203

204
  StorageArea* area = nullptr;
1✔
205
  Clib::ConfigElem elem;
1✔
206

207
  clock_t start = clock();
1✔
208

209
  while ( cf.read( elem ) )
10✔
210
  {
211
    if ( --num_until_dot == 0 )
9✔
212
    {
213
      INFO_PRINT( "." );
×
214
      num_until_dot = 1000;
×
215
    }
216
    if ( elem.type_is( "StorageArea" ) )
9✔
217
    {
218
      area = create_area( elem );
3✔
219
    }
220
    else if ( elem.type_is( "Item" ) )
6✔
221
    {
222
      if ( area != nullptr )
6✔
223
      {
224
        try
225
        {
226
          area->load_item( elem );
6✔
227
        }
228
        catch ( std::exception& )
×
229
        {
230
          if ( !Plib::systemstate.config.ignore_load_errors )
×
231
            throw;
×
232
        }
×
233
      }
234
      else
235
      {
236
        ERROR_PRINTLN( "Storage: Got an ITEM element, but don't have a StorageArea to put it." );
×
237
        throw std::runtime_error( "Data file integrity error" );
×
238
      }
239
    }
240
    else
241
    {
242
      ERROR_PRINTLN( "Unexpected element type {} in storage file.", elem.type() );
×
243
      throw std::runtime_error( "Data file integrity error" );
×
244
    }
245
    ++nobjects;
9✔
246
  }
247

248
  clock_t end = clock();
1✔
249
  int ms = static_cast<int>( ( end - start ) * 1000.0 / CLOCKS_PER_SEC );
1✔
250

251
  INFO_PRINTLN( " {} elements in {} ms.", nobjects, ms );
1✔
252
}
1✔
253

254
void Storage::print( Clib::StreamWriter& sw ) const
4✔
255
{
256
  for ( const auto& area : areas )
10✔
257
  {
258
    sw.begin( "StorageArea" );
6✔
259
    sw.add( "Name", area.first );
6✔
260
    sw.end();
6✔
261
    area.second->print( sw );
6✔
262
  }
263
}
4✔
264

265
void Storage::clear()
3✔
266
{
267
  while ( !areas.empty() )
9✔
268
  {
269
    delete ( ( *areas.begin() ).second );
6✔
270
    areas.erase( areas.begin() );
6✔
271
  }
272
}
3✔
273

274
size_t Storage::estimateSize() const
1✔
275
{
276
  size_t size = Clib::memsize( areas );
1✔
277
  for ( const auto& area : areas )
1✔
278
  {
279
    if ( area.second != nullptr )
×
280
      size += area.second->estimateSize();
×
281
  }
282
  return size;
1✔
283
}
284

285
class StorageAreaIterator final : public ContIterator
286
{
287
public:
288
  StorageAreaIterator( StorageArea* area, BObject* pIter );
289
  BObject* step() override;
290

291
private:
292
  BObject* m_pIterVal;
293
  std::string key;
294
  StorageArea* _area;
295
};
296

297
StorageAreaIterator::StorageAreaIterator( StorageArea* area, BObject* pIter )
×
298
    : ContIterator(), m_pIterVal( pIter ), key( "" ), _area( area )
×
299
{
300
}
×
301

302
BObject* StorageAreaIterator::step()
×
303
{
304
  StorageArea::Cont::iterator itr = _area->_items.lower_bound( key );
×
305
  if ( !key.empty() && itr != _area->_items.end() )
×
306
  {
307
    ++itr;
×
308
  }
309

310
  if ( itr == _area->_items.end() )
×
311
    return nullptr;
×
312

313
  key = ( *itr ).first;
×
314
  m_pIterVal->setimp( new String( key ) );
×
315
  BObject* result = new BObject( make_itemref( ( *itr ).second ) );
×
316
  return result;
×
317
}
318

319
ContIterator* StorageAreaImp::createIterator( BObject* pIterVal )
×
320
{
321
  return new StorageAreaIterator( _area, pIterVal );
×
322
}
323

324
BObjectRef StorageAreaImp::get_member( const char* membername )
8✔
325
{
326
  if ( stricmp( membername, "count" ) == 0 )
8✔
327
  {
328
    return BObjectRef( new BLong( static_cast<int>( _area->_items.size() ) ) );
2✔
329
  }
330
  else if ( stricmp( membername, "totalcount" ) == 0 )
6✔
331
  {
332
    unsigned int total = 0;
6✔
333
    for ( StorageArea::Cont::iterator itr = _area->_items.begin(); itr != _area->_items.end();
12✔
334
          ++itr )
6✔
335
    {
336
      Items::Item* item = ( *itr ).second;
6✔
337
      total += item->item_count();
6✔
338
    }
339
    return BObjectRef( new BLong( total ) );
6✔
340
  }
341
  return BObjectRef( UninitObject::create() );
×
342
}
343

344

345
class StorageAreasIterator final : public ContIterator
346
{
347
public:
348
  StorageAreasIterator( BObject* pIter );
349
  BObject* step() override;
350

351
private:
352
  BObject* m_pIterVal;
353
  std::string key;
354
};
355

356
StorageAreasIterator::StorageAreasIterator( BObject* pIter )
×
357
    : ContIterator(), m_pIterVal( pIter ), key( "" )
×
358
{
359
}
×
360

361
BObject* StorageAreasIterator::step()
×
362
{
363
  Storage::AreaCont::iterator itr = gamestate.storage.areas.lower_bound( key );
×
364
  if ( !key.empty() && itr != gamestate.storage.areas.end() )
×
365
  {
366
    ++itr;
×
367
  }
368

369
  if ( itr == gamestate.storage.areas.end() )
×
370
    return nullptr;
×
371

372
  key = ( *itr ).first;
×
373
  m_pIterVal->setimp( new String( key ) );
×
374
  BObject* result = new BObject( new StorageAreaImp( ( *itr ).second ) );
×
375
  return result;
×
376
}
377

378
class StorageAreasImp final : public BObjectImp
379
{
380
public:
381
  StorageAreasImp() : BObjectImp( BObjectImp::OTUnknown ) {}
1✔
NEW
382
  BObjectImp* copy() const override { return new StorageAreasImp(); }
×
NEW
383
  std::string getStringRep() const override { return "<StorageAreas>"; }
×
NEW
384
  size_t sizeEstimate() const override { return sizeof( *this ); }
×
UNCOV
385
  ContIterator* createIterator( BObject* pIterVal ) override
×
386
  {
387
    return new StorageAreasIterator( pIterVal );
×
388
  }
389

390
  BObjectRef get_member( const char* membername ) override;
391

392
  BObjectRef OperSubscript( const BObject& obj ) override;
393
};
394

395
BObjectImp* CreateStorageAreasImp()
1✔
396
{
397
  return new StorageAreasImp();
1✔
398
}
399

400
BObjectRef StorageAreasImp::get_member( const char* membername )
1✔
401
{
402
  if ( stricmp( membername, "count" ) == 0 )
1✔
403
  {
404
    return BObjectRef( new BLong( static_cast<int>( gamestate.storage.areas.size() ) ) );
1✔
405
  }
406
  return BObjectRef( UninitObject::create() );
×
407
}
408
BObjectRef StorageAreasImp::OperSubscript( const BObject& obj )
×
409
{
410
  if ( obj.isa( OTString ) )
×
411
  {
412
    String& rtstr = (String&)obj.impref();
×
413
    std::string key = rtstr.value();
×
414

415
    Storage::AreaCont::iterator itr = gamestate.storage.areas.find( key );
×
416
    if ( itr != gamestate.storage.areas.end() )
×
417
    {
418
      return BObjectRef( new BObject( new StorageAreaImp( ( *itr ).second ) ) );
×
419
    }
420
    else
421
    {
422
      return BObjectRef( new BObject( new BError( "Storage Area not found" ) ) );
×
423
    }
424
  }
×
425
  return BObjectRef( new BObject( new BError( "Invalid parameter type" ) ) );
×
426
}
427
}  // namespace Core
428
}  // namespace Pol
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc