xref: /haiku/src/kits/translation/FuncTranslator.cpp (revision f2b4344867e97c3f4e742a1b4a15e6879644601a)
1 /*
2  * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Michael Wilber
7  *		Axel Dörfler, axeld@pinc-software.de
8  */
9 
10 /*!
11 	This file contains the BTranslator based object for
12 	function based translators, aka, the translators
13 	that don't use the make_nth_translator() mechanism.
14 
15 	This class is used by the BTranslatorRoster class
16 	so that function based translators, make_nth_translator()
17 	translators and private BTranslator objects could be
18 	accessed in the same way.
19 */
20 
21 
22 #include "FuncTranslator.h"
23 
24 #include <string.h>
25 
26 
27 namespace BPrivate {
28 
29 BFuncTranslator::BFuncTranslator(const translator_data& data)
30 {
31 	fData = data;
32 }
33 
34 
35 BFuncTranslator::~BFuncTranslator()
36 {
37 }
38 
39 
40 const char *
41 BFuncTranslator::TranslatorName() const
42 {
43 	return fData.name;
44 }
45 
46 
47 const char *
48 BFuncTranslator::TranslatorInfo() const
49 {
50 	return fData.info;
51 }
52 
53 
54 int32
55 BFuncTranslator::TranslatorVersion() const
56 {
57 	return fData.version;
58 }
59 
60 
61 const translation_format *
62 BFuncTranslator::InputFormats(int32* _count) const
63 {
64 	if (_count == NULL || fData.input_formats == NULL)
65 		return NULL;
66 
67 	int32 count = 0;
68 	while (fData.input_formats[count].type) {
69 		count++;
70 	}
71 
72 	*_count = count;
73 	return fData.input_formats;
74 }
75 
76 
77 const translation_format *
78 BFuncTranslator::OutputFormats(int32* _count) const
79 {
80 	if (_count == NULL || fData.output_formats == NULL)
81 		return NULL;
82 
83 	int32 count = 0;
84 	while (fData.output_formats[count].type) {
85 		count++;
86 	}
87 
88 	*_count = count;
89 	return fData.output_formats;
90 }
91 
92 
93 status_t
94 BFuncTranslator::Identify(BPositionIO* source, const translation_format* format,
95 	BMessage* ioExtension, translator_info* info, uint32 type)
96 {
97 	if (fData.identify_hook == NULL)
98 		return B_ERROR;
99 
100 	return fData.identify_hook(source, format, ioExtension, info, type);
101 }
102 
103 
104 status_t
105 BFuncTranslator::Translate(BPositionIO* source, const translator_info *info,
106 	BMessage* ioExtension, uint32 type, BPositionIO* destination)
107 {
108 	if (fData.translate_hook == NULL)
109 		return B_ERROR;
110 
111 	return fData.translate_hook(source, info, ioExtension, type, destination);
112 }
113 
114 
115 status_t
116 BFuncTranslator::MakeConfigurationView(BMessage* ioExtension,
117 	BView** _view, BRect* _extent)
118 {
119 	if (fData.make_config_hook == NULL)
120 		return B_ERROR;
121 
122 	return fData.make_config_hook(ioExtension, _view, _extent);
123 }
124 
125 
126 status_t
127 BFuncTranslator::GetConfigurationMessage(BMessage* ioExtension)
128 {
129 	if (fData.get_config_message_hook == NULL)
130 		return B_ERROR;
131 
132 	return fData.get_config_message_hook(ioExtension);
133 }
134 
135 }	// namespace BPrivate
136