Compare Pastes

Differences between the pastes #130768 (29.12.2019 23:40) and #138306 (17.07.2020 06:24).
1
#include "StdAfx.h"
1
 
2
3
#include "c:\\mironena\\work\\SelfDev\\C++\\Projects\\Dll\\Export.h"
4
#pragma comment( lib, "c:\\mironena\\work\\SelfDev\\C++\\build\\bin\\Win32\\Debug\\Dll.lib" )
5
6
#include 
7
#include 
8
#include 
9
#include 
10
#include 
11
#include 
12
#include 
13
14
15
#include 
16
#include 
17
#include 
18
#include 
19
20
21
//template< typename Base, typename DerivedTypeDetails >
22
//class ObjectFactory
23
//{
24
//protected:
25
//
26
//    typedef void(*InstanceCreatorFunc)(Base*&);
27
//    typedef typename DerivedTypeDetails::KeyType KeyType;
28
//
29
//    struct ObjectType
30
//    {
31
//        InstanceCreatorFunc			pCreatorFunc;
32
//        const DerivedTypeDetails*	pObjectTypeDetails;
33
//
34
//        ObjectType()
35
//            : pCreatorFunc(NULL)
36
//            , pObjectTypeDetails(NULL)
37
//        {
38
//        }
39
//    };
40
//
41
//    //
42
//    // This is a map which maps strings to functions that create an
43
//    // object of the specified type.
44
//    //
45
//    typedef KeyValueMap< KeyType, ObjectType > ObjectTypeMap;
46
//
47
//    //
48
//    // Declare an additional type definition that is this particular
49
//    // type of object factory.
50
//    //
51
//    typedef ObjectFactory< Base, DerivedTypeDetails > FactoryType;
52
//
53
//protected:
54
//    //
55
//    // Protected Constructor
56
//    //
57
//    ObjectFactory()
58
//        : m_objectTypeMap()
59
//    {
60
//    }
61
//
62
//public:
63
//    //
64
//    // Here is a helper class used for registering the derived classes
65
//    // of type _base with the object factory, along with a pointer to a
66
//    // function that can create an object of that type.
67
//    //
68
//    // This is a nested class because it is a registrar for this type of factory,
69
//    // rather than just a general registrar that can work with any factory.
70
//    //
71
//    class Registrar
72
//    {
73
//    public:
74
//        Registrar(const DerivedTypeDetails&	objectTypeDetails,
75
//            InstanceCreatorFunc		pCreatorFunc)
76
//            : m_objectTypeDetails(objectTypeDetails)
77
//            , m_pCreatorFunc(pCreatorFunc)
78
//            , m_bRegistered(false)
79
//        {
80
//            registerClass();
81
//        }
82
//
83
//    public:
84
//        //
85
//        // Needed sometimes to force compiler to link in the registrar.
86
//        //
87
//        void registerClass()
88
//        {
89
//            if (m_bRegistered == false)
90
//            {
91
//                ObjectFactory& factory = ObjectFactory::instance();
92
//                factory.registerClass(m_objectTypeDetails, m_pCreatorFunc);
93
//                m_bRegistered = true;
94
//            }
95
//        }
96
//
97
//        bool isRegistered()
98
//        {
99
//            return m_bRegistered;
100
//        }
101
//
102
//    public:
103
//        //
104
//        // Private data members
105
//        //
106
//        const DerivedTypeDetails&	m_objectTypeDetails;
107
//        InstanceCreatorFunc			m_pCreatorFunc;
108
//        bool						m_bRegistered;
109
//    };
110
//
111
//public:
112
//    //
113
//    // Public type definitions
114
//    //
115
//    typedef typename ObjectTypeMap::KeyValueVectorType ObjectTypeVector;
116
//
117
//public:
118
//    //
119
//    // Public interface
120
//    //
121
//
122
//    //
123
//    // Singleton pattern static member for obtaining the single instance
124
//    // of the class.
125
//    //
126
//    static ObjectFactory& instance()
127
//    {
128
//        static ObjectFactory factory;
129
//        return factory;
130
//    }
131
//
132
//    //
133
//    // Destructor
134
//    //
135
//    ~ObjectFactory()
136
//    {
137
//    }
138
//
139
//    //
140
//    // This method will create an object of the specified type.
141
//    //
142
//    Base* createObject(const KeyType& key)
143
//    {
144
//        Base* pNewObj = NULL;
145
//
146
//        Risk::CSGuard guard(m_cs);
147
//
148
//        //
149
//        // Search for a map entry with the same name
150
//        //
151
//        ObjectTypeMap::iterator i = m_objectTypeMap.find(key);
152
//        if (i != m_objectTypeMap.end())
153
//        {
154
//            //
155
//            // Get a pointer to the creator function
156
//            //
157
//            InstanceCreatorFunc pCreatorFunc = (*i).second.pCreatorFunc;
158
//
159
//            //
160
//            // Unlock the critical section before calling the creator function
161
//            // Note: This may lead to race conditions
162
//            //
163
//            guard.unlock();
164
//
165
//            //
166
//            // Now call it to create an object of the specified type
167
//            //
168
//            (*pCreatorFunc)(pNewObj);
169
//        }
170
//
171
//        return pNewObj;
172
//    }
173
//
174
//    //
175
//    // Return a list of the object types this factory can create
176
//    //
177
//    void getObjectTypes(ObjectTypeVector& objecTypes)
178
//    {
179
//        m_objectTypeMap.convertToVector(objecTypes);
180
//    }
181
//
182
//
183
//protected:
184
//    //
185
//    // Protected helper functions
186
//    //
187
//
188
//    //
189
//    // This allows the Registrar to register the object creator functions
190
//    //
191
//    friend class Registrar;
192
//
193
//    //
194
//    // This method registers the type of objects that this factory
195
//    // can create.
196
//    //
197
//    void registerClass(const DerivedTypeDetails&	objectTypeDetails,
198
//        InstanceCreatorFunc			pCreatorFunc)
199
//    {
200
//        Risk::CSGuard guard(m_cs);
201
//
202
//        ObjectType objectType;
203
//        objectType.pCreatorFunc = pCreatorFunc;
204
//        objectType.pObjectTypeDetails = &objectTypeDetails;
205
//
206
//        m_objectTypeMap.insert(ObjectTypeMap::value_type(KeyType(objectTypeDetails.key), objectType));
207
//    }
208
//
209
//
210
//private:
211
//    //
212
//    // Private data members
213
//    //
214
//    CS			m_cs;
215
//
216
//    //
217
//    // This is the map which maps object names to a function
218
//    // that can create an object of that type.
219
//    //
220
//    ObjectTypeMap m_objectTypeMap;
221
//};
222
223
224
//struct String
225
//{
226
//
227
//	String(const char *str = "")
228
//	{
229
//		size_ = strlen( str );
230
//		str_ = new char[ size_ + 1 ];
231
//		strncpy( str_, str, size_+ 1 );
232
//	}
233
//
234
//	String(size_t n, char c)
235
//	{
236
//		size_ = n;
237
//		str_ = new char[ size_ + 1]();
238
//
239
//		for (int i = 0; i < size_; ++i)
240
//		{
241
//			str_[i] = c;
242
//		}
243
//		str_[size_ + 1] = '\0';
244
//	}
245
//
246
//	size_t size_;
247
//	char* str_;
248
//};
249
250
//namespace 
251
//{
252
//
253
//char* getline()
254
//{
255
//	char inputSymbol = '\0';
256
//	int stringLength = 1;
257
//	char* resultStr = new char[stringLength]();
258
//
259
//	while ( std::cin.get(inputSymbol) && inputSymbol != '\n' )
260
//	{
261
//		char* tmp = new char[ stringLength + 1 ]();
262
//
263
//		strcpy(tmp, resultStr);
264
//		tmp[ stringLength - 1 ] = inputSymbol;
265
//		delete[] resultStr;
266
//		resultStr = tmp;
267
//		++stringLength;
268
//	}
269
//
270
//	return resultStr;
271
//}
272
//
273
//void removeExtraSpaces(std::string& inputStr)
274
//{
275
//	size_t firstNonSpaceSymbol = inputStr.find_first_not_of(' ');
276
//	
277
//	if ( firstNonSpaceSymbol != std::string::npos )
278
//	{
279
//		inputStr = inputStr.substr( firstNonSpaceSymbol, inputStr.length() - firstNonSpaceSymbol );
280
//	}
281
//
282
//	size_t lastNonSpaceSymbol = inputStr.find_last_not_of(' ');
283
//	if ( lastNonSpaceSymbol != std::string::npos )
284
//	{
285
//		inputStr = inputStr.substr( 0, lastNonSpaceSymbol + 1 );
286
//	}
287
//
288
//	size_t repeatedSpaceLocation = inputStr.find("  ");
289
//	while( repeatedSpaceLocation != std::string::npos )
290
//	{
291
//		inputStr.replace( repeatedSpaceLocation, 2, " " );
292
//		repeatedSpaceLocation = inputStr.find("  ");
293
//	}
294
//}
295
//
296
//int** transpose(const int* const* m, size_t r, size_t c)
297
//{
298
//	int** resultMatrix = new int *[c];
299
//	for (unsigned int i = 0; i < c; i++)
300
//		resultMatrix[i] = new int[r];
301
//
302
//
303
//	for ( unsigned int i = 0; i < r; i++ )
304
//		for ( unsigned int j = 0; j < c; j++ )
305
//			resultMatrix[j][i] = m[i][j];
306
//
307
//	return resultMatrix;
308
//}
309
//
310
//void swap_min(int** mt, unsigned int m, unsigned int n)
311
//{
312
//	int rowNum = 0, minElem = mt[0][0];
313
//
314
//	for ( unsigned int i = 0; i < m; i++ )
315
//	{
316
//		for ( unsigned int j = 0; j < n; j++ )
317
//		{
318
//			if ( mt[i][j] < minElem)
319
//			{
320
//				minElem = mt[i][j];
321
//				rowNum = i;
322
//			}
323
//		}
324
//	}
325
//
326
//	if ( rowNum != 0 )
327
//	{
328
//		for ( unsigned int i = 0; i < n; ++i )
329
//		{
330
//			int tmp = mt[0][i];
331
//			mt[0][i] = mt[rowNum][i];
332
//			mt[rowNum][i] = tmp;
333
//		}
334
//	}
335
//}
336
//
337
//void outputMatrix(int** mt, int rows, int columns)
338
//{
339
//	for (int i = 0; i < rows; ++i )
340
//	{
341
//		for (int j = 0; j < columns; ++j)
342
//		{
343
//			std::cout << mt[i][j] << " ";
344
//		}
345
//		std::cout << std::endl;
346
//	}
347
//	std::cout << std::endl;
348
//}
349
//
350
//int** createAndFillMatrix(int rows, int columns)
351
//{
352
//	int** matrix = new int*[rows](); 
353
//	for ( int i = 0; i != rows; ++i )
354
//		matrix[i] = new int[columns]();
355
//
356
//	int k = 1;
357
//	for (int i = 0; i < rows; ++i )
358
//	{
359
//		for (int j = 0; j < columns; ++j)
360
//		{
361
//			matrix[i][j] = k;
362
//			++k;
363
//		}
364
//	}
365
//
366
//	return matrix;
367
//}
368
//
369
//void createFileMapping(const std::wstring& filePath)
370
//{
371
//	int a;
372
//	std::cin >> a;
373
//
374
//	TCHAR szName[] = TEXT("Global\\MyFileMappingObject");
375
//
376
//	HANDLE hFile = CreateFile(
377
//		filePath.c_str(),
378
//		GENERIC_READ | GENERIC_WRITE,
379
//		FILE_SHARE_READ | FILE_SHARE_WRITE,
380
//		NULL,
381
//		OPEN_EXISTING,
382
//		0,
383
//		0 );
384
//
385
//	// handle failure
386
//	if ( hFile == INVALID_HANDLE_VALUE )
387
//	{
388
//		_tprintf( TEXT( "Could not create file mapping object (%d).\n" ), GetLastError() );
389
//	}
390
//
391
//	HANDLE hFileMap = CreateFileMapping(
392
//		hFile,								// use paging file
393
//		NULL,								// default security
394
//		PAGE_READWRITE,						// read/write access
395
//		0,									// maximum object size (high-order DWORD)
396
//		0,									// maximum object size (low-order DWORD)
397
//		L"Global\\MyFileMappingObject" );	// name of mapping object
398
//
399
//	if ( hFileMap == NULL )
400
//	{
401
//		_tprintf( TEXT( "Could not create file mapping object (%d).\n" ), GetLastError() );
402
//	}
403
//}
404
//
405
//}
406
407
408
template
409
struct binary
410
{
411
	static unsigned long const value =
412
		binary::value << 1 | N % 10;
413
};
414
415
template <> struct binary<0>
416
{
417
	static unsigned long const value = 0;
418
};
419
420
int binary_conv(int binary)
421
{
422
	if (binary == 0)
423
		return 0;
424
425
	return binary_conv(binary / 10) << 1 | binary % 10;
426
}
427
428
std::vector&& xvalue_func()
429
{
430
	static std::vector vec;
431
	vec = std::vector(2, "Hola");
432
433
	return std::move(vec);
434
}
435
436
int main()
437
{
438
//*************************************************************************
439
// 	const int ROWS = 3, COLUMNS = 3;
440
// 
441
// 	int** matrix = createAndFillMatrix( ROWS, COLUMNS );
442
// 	outputMatrix( matrix, ROWS, COLUMNS );
443
// 
444
// 	swap_min(matrix, ROWS, COLUMNS);
445
// 	outputMatrix( matrix, ROWS, COLUMNS );
446
// 
447
// 	int** result = transpose(matrix, ROWS, COLUMNS);
448
// 	outputMatrix( matrix, COLUMNS, ROWS );
449
450
//*************************************************************************
451
// 	std::string someStr;
452
// 	std::getline( std::cin, someStr );
453
// 
454
// 	int** matrixVar; 
455
// 	removeExtraSpaces( someStr );
456
457
//	std::cout << someStr;
458
//*************************************************************************
459
//	int myints[] = {10,20,30,30,20,10,10,20};
460
//	std::multiset int_map(myints, myints+8);
461
//
462
//	auto iter = int_map.lower_bound( 20 );
463
//	std::cout << "Upperbound value: " << *int_map.upper_bound(20) << std::endl;
464
//	std::cout << "Lowerbound value: " << *iter << std::endl;
465
//	std::for_each(iter, int_map.end(), [=](int var)
466
//	{
467
//		std::cout  << var << " ";
468
//	});
469
//*************************************************************************
470
471
	std::wcout << binary_conv(101) << std::endl;
472
	std::wcout << binary<101>::value << std::endl;
473
474
//*************************************************************************
475
476
	std::vector value = xvalue_func();
477
	value.push_back("Hello");
478
	std::cout << "size= " << value.size() << std::endl;
479
	std::vector::iterator it = value.begin();
480
	while (it != value.end()) std::cout << *it++ << std::endl;
481
482
	std::vector&& v = xvalue_func();
483
	v.push_back("Guten tag");
484
	std::cout << "size= " << v.size() << std::endl;
485
	it = v.begin();
486
	while (it != v.end()) std::cout << *it++ << std::endl;
487
488
	v = xvalue_func();
489
	std::cout << "size= " << v.size() << std::endl;
490
	it = v.begin();
491
	while (it != v.end()) std::cout << *it++ << std::endl;
492
493
494
	return 0;