본문으로 바로가기

BdfCpp

category 블로그 (Blog)/개발로그 (Devlogs) 2024. 6. 21. 22:49

JSON과 NBT의 영향을 받아 개발된 변수와 태그를 직렬화하기 위한 C++ 라이브러리...

물론 파일로 저장 및 저장된 파일로부터 복구가 가능..

// Create a reader object
BdfReader reader;

// Get the BdfObject instance
BdfObject* bdf = reader->getObject();

// Generate another BdfObject instance
BdfObject* bdf_new = bdf->newObject();

delete bdf_new;

// Get an integer
int v = bdf->getInteger();

// Set an integer
bdf->setInteger(5);

// Set an integer with an automatic type
bdf->setAutoInt(53);

// Set a primitive array of ints
int intArray[] = {3, 4, 5, 6};
bdf->setIntegerArray(intArray, 4);

// Get a byte array
char* byteArray;
int byteArraySize;
bdf->getByteArray(&byteArray, &byteArraySize);

delete[] byteArray;

// Get the type of variable of the object
int type = bdf->getType();

// Compare the type with a type from BdfTypes
if(type == BdfTypes::INTEGER)
{

}

// Serialize the BDF object
char* data;
int data_size;
bdf->serialize(&data, &data_size);

delete[] data;

// Load another reader object from the serialized bytes
BdfReader reader2(data, data_size);

/*
	A reader object can be serialized to the human readable
	representation as a string or sent over a stream
*/
reader2->serializeHumanReadable(std::cout, BdfIndent("\t", "\n"));
std::string data_hr = reader2->serializeHumanReadable(BdfIndent("\t", "\n"));

// A reader object can be loaded from a human readable object
BdfReaderHuman reader3(data_hr);

 

BdfReader reader;
BdfObject* bdf = reader->getObject();

// Can be created from a bdf object
BdfArray* array = bdf->newArray();

// Get the length of an array
int size = array->size();

// Remove any index from an array
array->remove(3);

// Set an object to an index of an array
array->set(4, bdf->newObject()->setString("A String"));

// Add an object to an array
array->add(bdf->newObject()->setByte(53));

// Set the array to the bdf object
bdf->setArray(array);
BdfReader reader;
BdfObject* bdf = reader->getObject();

// New named list
BdfNamedList* list = bdf->newNamedList();

// Set an element to the named list
list->set("key1", bdf->newObject()->setInteger(5));

// Use ids instead of strings for optimisation
// if set/get is being called multiple times
// on the same key.

int key2 = bdf->getKeyLocation("key2");
list->set(key2, bdf->newObject()->setFloat(42.0F));

// Get an elements value
int v = list->get("key1")->getInteger();

// Check if an element exists
bool has_key = list->contains("key1");

// Get the lists keys
std::vector<int> keys = list.getKeys();

// Iterate over the lists keys
for(int key : keys)
{
	// Get the keys name
	std::string key_name = bdf->getKeyName(key);
}

BdfCpp-master.zip
0.05MB

'블로그 (Blog) > 개발로그 (Devlogs)' 카테고리의 다른 글

개발 문서 생성기 'Sphinx'  (0) 2024.06.28
libGLU  (0) 2024.06.27
tcping  (0) 2024.06.21
subprocess for C++  (0) 2024.06.20
CGAL의 boolean operation  (0) 2024.06.18