mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-03-10 00:23:29 +08:00
43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
namespace UglyToad.Pdf.Cos
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
internal class CosObjectPool
|
|
{
|
|
private readonly Dictionary<CosObjectKey, CosObject> objects = new Dictionary<CosObjectKey, CosObject>();
|
|
|
|
public CosObject Get(CosObjectKey key)
|
|
{
|
|
if (key != null)
|
|
{
|
|
if (objects.TryGetValue(key, out var value))
|
|
{
|
|
return value;
|
|
}
|
|
}
|
|
|
|
// this was a forward reference, make "proxy" object
|
|
var obj = new CosObject(null);
|
|
if (key != null)
|
|
{
|
|
obj.SetObjectNumber(key.Number);
|
|
obj.SetGenerationNumber((int)key.Generation);
|
|
objects[key] = obj;
|
|
}
|
|
|
|
return obj;
|
|
}
|
|
|
|
public CosObject GetOrCreateDefault(CosObjectKey key)
|
|
{
|
|
if (!objects.TryGetValue(key, out CosObject obj))
|
|
{
|
|
obj = new CosObject(null);
|
|
}
|
|
|
|
return obj;
|
|
}
|
|
}
|
|
}
|