Reload xml files when resolution gets changed
[platform/core/uifw/libscl-ui.git] / xml2binary / encode_metadata.cpp
1 /*
2  * Copyright (c) 2012 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include "encode_metadata.h"
19 #include <assert.h>
20 #include <stdio.h>
21 #include "metadata.h"
22 using namespace std;
23 static const int FIELD_NUM_WIDTH = 2;
24 static void
25 encode_metadata_record(ResourceStorage& storage, const MetaData_Record& metadata_record ) {
26     storage.put(metadata_record.m_name);
27     unsigned short field_num = metadata_record.vField.size();
28     storage.put<sint_t>(field_num, FIELD_NUM_WIDTH);
29
30     std::vector<MetaData_Field>::const_iterator it;
31     for (it = metadata_record.vField.begin(); it != metadata_record.vField.end(); ++it) {
32         storage.put(it->m_name);
33         storage.put(it->m_type);
34         storage.put<sint_t>(it->m_width, FIELD_SIZE_WIDTH);
35     }
36 }
37 void
38 encode_metadata(ResourceStorage& storage, const MetaData& metadata ) {
39     int init_size = storage.get_size();
40
41     storage.reserve(8);
42     storage.put(metadata.m_version);
43
44     unsigned short size = metadata.m_vec_metadata_record.size();
45     storage.put<sint_t>(size, RECORD_SIZE_WIDTH);
46
47     for (int i = 0; i < size; ++i) {
48         encode_metadata_record(storage, metadata.m_vec_metadata_record.at(i));
49     }
50
51     int block_size = storage.get_size() - init_size;
52     storage.random_put<sint_t>(block_size, 8, init_size);
53 }
54