NSTimeZone

[url]http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSTimeZone_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40003748[/url]

估计不少同学都没有使用这种时间=。=

[url]http://justcoding.iteye.com/blog/1468089[/url]
// // TPSSAppContext.mm // SurveillanceCore // // Created by ChenYongan on 6/13/16. // Copyright © 2016 TP-LINK. All rights reserved. // #import "TPSSAppContext.h" #import "TPSSNotification.h" // FIXME //#import "TPSSLocalizationConstants.h" #include "IPCAppContext.h" #include "tpwlog.h" #include <set> #include "TPECCommonMethods.h" #import "TPSSAppContext+Private.h" #import <TPFoundation/TPLocalizationUtils.h> #define APPCONTEXT_LOG_TAG "TPSSAppContext:: " static BasicToken getBasicToken(const char *pcToken) { BasicToken token = BasicToken(); if (pcToken != NULL){ strlcpy(token.pcToken, [[TPECCommonMethods AES256DencryptWithTokenString:[NSString stringWithUTF8String: pcToken]] UTF8String], TPWCOMM_MAX_TOKEN_LENGTH); } return token; } TPBasicTokenCallMethod getBasicTokenMethod = { getBasicToken }; static struct tm LocalTime(long long time) { NSDate *date = [NSDate dateWithTimeIntervalSince1970:time]; NSDateComponents *dateComponents = [NSCalendar.currentCalendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond fromDate:date]; struct tm tm = { 0 }; tm.tm_year = (int)dateComponents.year - 1900; tm.tm_mon = (int)dateComponents.month - 1; tm.tm_mday = (int)dateComponents.day; tm.tm_hour = (int)dateComponents.hour; tm.tm_min = (int)dateComponents.minute; tm.tm_sec = (int)dateComponents.second; time_t t = mktime(&tm); return *localtime(&t); } @interface TPSSAppContext () @property (nonatomic, assign, readwrite) BOOL didRequestLogout; @property (nonatomic, assign, readwrite) TPAPPTargetType curTarget; @end @implementation TPSSAppContext + (instancetype)sharedContext { static TPSSAppContext *appContext = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ appContext = [[TPSSAppContext alloc] init]; }); return appContext; } - (instancetype)init { self = [super init]; if (self) { pLocalTimeFunction = LocalTime; pDecryptBasicsToken = getBasicTokenMethod.getBasicToken; _pAppContext = (IPCAPPCONTEXT *)[self createLowLevelAppContext]; // 加载target type,加载对应target的target config #ifdef APP_VIGI self.curTarget = TPAPPTargetTypeSurveillanceHome; NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"targetConfig" ofType:@"plist"]; self.targetConfig = [[NSDictionary alloc] initWithContentsOfFile:bundlePath]; #else self.curTarget = TPAPPTargetTypeOmadaSurveillance; NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"OmadaSurveillance-targetConfig" ofType:@"plist"]; self.targetConfig = [[NSDictionary alloc] initWithContentsOfFile:bundlePath]; #endif _pAppContext->SetCurTarget((APPTargetType)self.curTarget); _pAppContext->SetTimeDifference((int)NSTimeZone.localTimeZone.secondsFromGMT * 1000); _pAppContext->RegisterEventFlingerCallback(EventCallback, ExitCallback, (__bridge void *)self); //因要设置图片、视频存储路径,该path已通过fishhook修改为library path NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *configPath = [paths objectAtIndex:0]; configPath = [configPath stringByAppendingPathComponent:@"AppConfig"]; if (![[NSFileManager defaultManager] fileExistsAtPath:configPath]) { [[NSFileManager defaultManager] createDirectoryAtPath:configPath withIntermediateDirectories:NO attributes:nil error:nil]; } _pAppContext->SetAppDataPath([configPath UTF8String]); NSString *filePath = [paths objectAtIndex:0]; filePath = [filePath stringByAppendingPathComponent:@"AppFiles"]; if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) { [[NSFileManager defaultManager] createDirectoryAtPath:filePath withIntermediateDirectories:NO attributes:nil error:nil]; } _pAppContext->SetExternalDataPath([filePath UTF8String]); #if !TARGET_OS_IOS NSString *picturePath = [TPSSAppContext innerDownloadPath:TPGuardDownloadPathTypePicture context:_pAppContext]; NSString *videoPath = [TPSSAppContext innerDownloadPath:TPGuardDownloadPathTypeVideo context:_pAppContext]; _pAppContext->SetAlbumPath(picturePath.length > 0 ? picturePath.UTF8String : filePath.UTF8String, TP_LOCALALBUM_PATH_TYPE_PICTURE); _pAppContext->SetAlbumPath(videoPath.length > 0 ? videoPath.UTF8String : filePath.UTF8String, TP_LOCALALBUM_PATH_TYPE_VIDEO); #endif NSString *cachePath = [paths objectAtIndex:0]; cachePath = [cachePath stringByAppendingPathComponent:@"AppCache"]; if (![[NSFileManager defaultManager] fileExistsAtPath:cachePath]) { [[NSFileManager defaultManager] createDirectoryAtPath:cachePath withIntermediateDirectories:NO attributes:nil error:nil]; } _pAppContext->SetCachePath([cachePath UTF8String]); #ifdef DEBUG TPWLogInit(); TPWLogEnableModule(1, TPWLOG_MODULE_COMM); TPWLogEnableModule(1, TPWLOG_MODULE_PLAYER); TPWLogEnableModule(1, TPWLOG_MODULE_IPCAPP); TPWLogEnableModule(0, TPWLOG_MODULE_NET_CLIENT); TPWLogEnableModule(1, TPWLOG_MODULE_STATISTICS); TPWLogSetLevel(TPWLOG_LEVEL_VERBOSE); TPWLogEnableTimestamp(1); TPWLogSetTimestampFormat(TPWLOG_TIMESTAMP_FORMAT_DATETIME_MIL); #endif self.didRequestLogout = NO; [self setupPresetDSTMap]; [TPSSAppContext setPresetTimeZone:_pAppContext]; _currentSiteDevicelist = [NSArray array]; _localDeviceMac = [NSMutableSet set]; } return self; } - (void)dealloc { // wait unit stop finish, and then delete _pAppContext->AppReqStop(&_uiRequestID, 1); delete _pAppContext; } #pragma mark - low level context - (void *)createLowLevelAppContext { return new IPCAPPCONTEXT(); } - (void *)lowLevelAppContext { return _pAppContext; } - (BOOL)allowCelluar { if (_pAppContext) { return _pAppContext->GetWindowControllerAllowCelluar(); } return NO; } #pragma mark - getter - (TPSSAppContextStatus)status { switch (_pAppContext->GetAppContextStatus()) { case IPCAPP_STARTED: return TPSSAppContextStatusStarted; case IPCAPP_STOPPED: return TPSSAppContextStatusStopped; } } - (TPSSAppContextConfig)config { #ifdef BETA_EXPORT_SALE_CLOUD return TPSSAppContextConfigTestBeta; #endif return TPSSAppContextConfigNormal; } - (NSArray <TPSSDeviceForDeviceList *> *)searchSiteList { if (_searchSiteList == nil) { _searchSiteList = [NSArray new]; } return _searchSiteList; } #pragma mark - START/STOP - (TPSSCode)start { unsigned int uiRequestID; int iRet = _pAppContext->AppReqStart(&uiRequestID, 0); return REQUEST_RESULT(uiRequestID, iRet); } - (TPSSCode)syncStart { unsigned int uiRequestID; int iRet = _pAppContext->AppReqStart(&uiRequestID, 1); return REQUEST_RESULT(uiRequestID, iRet); } - (TPSSCode)stop { unsigned int uiRequestID; int iRet = _pAppContext->AppReqStop(&uiRequestID, 0); return REQUEST_RESULT(uiRequestID, iRet); } - (TPSSCode)syncStop { unsigned int uiRequestID; int iRet = _pAppContext->AppReqStop(&uiRequestID, 1); return REQUEST_RESULT(uiRequestID, iRet); } - (void)setupPresetDSTMap { static NSString *dstStartTimeKey = @"start_time"; static NSString *dstEndTimeKey = @"end_time"; static NSString *dstOffsetKey = @"dst_saving"; NSString *path = [[NSBundle mainBundle] pathForResource:@"daylight_saving" ofType:@"json"]; NSData *jsonData = [NSData dataWithContentsOfFile:path]; NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:nil]; map<string, map<string, TPWDSTInfo>> *pDSTMap = _pAppContext->GetDSTMap(); for (NSString *dstName in dict.allKeys) { NSDictionary *dstDict = dict[dstName]; map<string, TPWDSTInfo> DSTInfoMap; for (NSString *year in dstDict.allKeys) { NSDictionary *dstInfoDict = dstDict[year]; TPWDSTInfo DSTInfo = { 0 }; DSTInfo.llStartTime = [dstInfoDict[dstStartTimeKey] longLongValue]; DSTInfo.llEndTime = [dstInfoDict[dstEndTimeKey] longLongValue]; DSTInfo.iDSTOffset = [dstInfoDict[dstOffsetKey] intValue]; DSTInfoMap[year.UTF8String] = DSTInfo; } (*pDSTMap)[dstName.UTF8String] = DSTInfoMap; } } #pragma mark - Notification handler static void EventCallback(int iQueueID, TPMESSAGE * pMessage, void * pArgs) { @autoreleasepool { TPSSAppContext *ac = (__bridge TPSSAppContext *)pArgs; [ac _handleEventWithQueueId:iQueueID andMessage:pMessage]; } } - (void)_handleEventWithQueueId:(int)iQueueId andMessage:(TPMESSAGE *)pMessage { NSNotification *notification; TPSSEventType eventType; if (TPSequenceNumberGetPrefix(pMessage->iID) == IPC_BROADCAST_SEQ_PREFIX) { eventType = TPSSEventTypeBroadcast; } else { eventType = TPSSEventTypeResponse; } notification = [NSNotification notificationWithMessage:pMessage eventType:eventType]; dispatch_async(dispatch_get_main_queue(), ^{ [[NSNotificationCenter defaultCenter] postNotification:notification]; }); } static void ExitCallback(void * pArgs) { @autoreleasepool { TPSSAppContext *ac = (__bridge TPSSAppContext *)pArgs; [ac _handleExit]; } } - (void)_handleExit { } #pragma mark - network - (void)setNetworkType:(NSInteger)networkType provider:(NSString *)provider { _pAppContext->SetNetworkType((int)networkType, [provider UTF8String]); } - (void)connectivityChanged { _pAppContext->AppConnectivityChanged(); } - (void)pipeManagerOptimize { _pAppContext->GetNetworkPipeManager()->Optimize(); _pAppContext->GetNetworkPipeManager()->ReconnectAllPreconn(); } - (void)pipeManagerChangeMaxPunchingNum:(NSInteger)playWindowNum deviceIDArray:(NSArray<NSNumber *> *)deviceIDArray { //后续可根据需求进行定制 if (!deviceIDArray || playWindowNum == 0) { return; } std::set<long long> *llDeviceIDSet = new std::set<long long>(); for (int i = 0; i < deviceIDArray.count; i++) { llDeviceIDSet->insert([deviceIDArray[i] longLongValue]); } _pAppContext->GetNetworkPipeManager()->ChangeMaxPunchingNum((int)playWindowNum, llDeviceIDSet); } - (void)resetDeviceLocalValid { _pAppContext->AppResetDeviceLocalValid(); } #pragma mark - error message - (NSString *)legacyErrorMessageForIndex:(SInt32)errorIndex { char pcMessage[IPC_ERROR_MSG_STASH_ENTRY_BUFF_SIZE] = { 0 }; _pAppContext->GetErrorMessage(pcMessage, NULL, NULL, (int)errorIndex); NSString *errorMessage = [NSString stringWithUTF8String:pcMessage]; return [TPSSAppContext errorMsgForLocalizedKey:errorMessage]; } - (TPSSError *)legacyErrorForIndex:(SInt32)errorIndex { int iRval = 0; int iErrorCode = 0; int iCode = 0; char pcMessage[IPC_ERROR_MSG_STASH_ENTRY_BUFF_SIZE] = { 0 }; _pAppContext->GetErrorMessage(pcMessage, &iErrorCode, &iRval, (int)errorIndex); if (iErrorCode != IPC_EC_RVAL) { iCode = iErrorCode; } else { iCode = iRval; } return [TPSSError errorWithCode:iCode andMessage:[NSString stringWithUTF8String:pcMessage]]; } + (NSString *)errorMsgForLocalizedKey:(NSString *)localizedKey { NSString *localizedString = [TPLocalizationUtils localizedStringForKey:localizedKey andTableName:@"IPCAppStringResourceDefines"]; if (![localizedString isEqualToString:localizedKey]) { return localizedString; } NSString *localizedErrorString = [TPLocalizationUtils localizedStringForKey:localizedKey andTableName:@"commonErrormsg"]; if (![localizedErrorString isEqualToString:localizedKey]) { return localizedErrorString; } else if ([localizedErrorString isEqualToString:localizedKey]) { NSString *diffLocalizedString = [TPLocalizationUtils localizedStringForKey:localizedKey andTableName:@"Localizable_diff"]; if (![diffLocalizedString isEqualToString:localizedKey]) { return diffLocalizedString; } } return localizedKey; } #pragma mark - task - (TPSSCode)cancelTask:(TPSSCode)requestID { int iRet = _pAppContext->AppCancelTask(requestID); return iRet; } - (TPSSTaskInfo *)taskInfoByID:(NSUInteger)requestID { TASKINFO *pTaskinfo = new TASKINFO; _pAppContext->GetTaskInfo((unsigned int)requestID, pTaskinfo); TPSSTaskInfo *taskinfo = [[TPSSTaskInfo alloc] initWithTaskinfo:pTaskinfo]; delete pTaskinfo; return taskinfo; } #pragma mark - tool method - (void)updateDidRequestLogout:(BOOL)didRequestLogout { self.didRequestLogout = didRequestLogout; } #pragma mark - device type //桥接层的DeviceType值转化成C层的DeviceType值 - (int)determainDeviceType:(TPSSDeviceType)deviceType { int deviceTypeC; switch (deviceType) { case TPSSDeviceTypeIPC: deviceTypeC = TPW_DEVICE_TYPE_IPC; break; case TPSSDeviceTypeNVR: deviceTypeC = TPW_DEVICE_TYPE_NVR; break; case TPSSDeviceTypeSolar: deviceTypeC = TPW_DEVICE_TYPE_SOLAR; break; default: deviceTypeC = TPW_DEVICE_TYPE_IPC; break; } return deviceTypeC; } //桥接层的DeviceSubType值转化成C层的DeviceSubType值 - (int)determainDeviceSubType:(TPSSDeviceSubType)subType { int deviceSubType; switch (subType) { case TPSSDeviceSubTypeNVR: deviceSubType = TPW_DEVICE_TYPE_NVR; break; case TPSSDeviceSubTypeCameraDisplay: deviceSubType = TPW_DEVICE_TYPE_CAMERA_DISPLAY; break; case TPSSDeviceSubTypeDoorBellCamera: deviceSubType = TPW_DEVICE_TYPE_DOORBELL_CAMERA; break; case TPSSDeviceSubTypeSolar: deviceSubType = TPW_DEVICE_TYPE_SOLAR; break; default: deviceSubType = TPW_DEVICE_TYPE_IPC; break; } return deviceSubType; } + (NSString *)downloadPathKey:(TPGuardDownloadPathType)type { return [NSString stringWithFormat:@"download_path_%@", @(type)]; } + (void)setDownloadPath:(NSString *)path type:(TPGuardDownloadPathType)type { if (path.length == 0 || type == TPGuardDownloadPathTypeCount) { return; } NSURL *fileURL = [NSURL fileURLWithPath:path]; if (fileURL) { NSData *bookmarkData = [self createBookmarkForURL:fileURL]; [[NSUserDefaults standardUserDefaults] setObject:bookmarkData forKey:[self downloadPathKey:type]]; } else { return; } auto &context = [TPSSAppContext sharedContext]->_pAppContext; if (type == TPGuardDownloadPathTypePicture) { context->SetAlbumPath(path.UTF8String, TP_LOCALALBUM_PATH_TYPE_PICTURE); } else if (type == TPGuardDownloadPathTypeVideo) { context->SetAlbumPath(path.UTF8String, TP_LOCALALBUM_PATH_TYPE_VIDEO); } } + (NSString *)innerDownloadPath:(TPGuardDownloadPathType)type context:(IPCAPPCONTEXT *)pContext { NSString *path = [[NSUserDefaults standardUserDefaults] valueForKey:[self downloadPathKey:type]]; NSData *boomarkData = [[NSUserDefaults standardUserDefaults] dataForKey:[self downloadPathKey:type]]; if (boomarkData) { NSURL *fileURL = [self resolveBookmarkData:boomarkData]; if (fileURL.path.length > 0) { return fileURL.path; } } if (path.length == 0 && pContext != NULL) { path = [NSString stringWithUTF8String: pContext->GetExternalDataPath()]; } return path.length > 0 ? path : @""; } + (NSString *)downloadPath:(TPGuardDownloadPathType)type { return [self innerDownloadPath:type context:[TPSSAppContext sharedContext]->_pAppContext]; } + (void)setPresetTimeZone:(IPCAPPCONTEXT *)pContext { NSString *filePath = [[NSBundle mainBundle] pathForResource:@"timezone" ofType:@"json"]; NSData *data = [NSData dataWithContentsOfFile:filePath]; if (!data || pContext == NULL) { return; } NSError *error; NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]; NSArray *timeZones = jsonObject[@"timezones"]; if (![timeZones isKindOfClass:[NSArray class]]) { return; } map<string, TPWTimeZoneInfo> *map = pContext->GetTimeZoneMap(); for (NSDictionary *item in timeZones) { if (![item isKindOfClass:[NSDictionary class]]) { continue; } NSString *name = item[@"name"]; NSString *zone = item[@"timezone"]; int offset = [item[@"offset"] intValue]; if (name.length == 0 || zone.length == 0) { continue; } TPWTimeZoneInfo info = TPWTimeZoneInfo(); info.iTimeOffset = offset / 1000; strlcpy(info.pcTimezone, name.cString, MIN(name.cStringLength, TPW_URL_MAX_LENGTH)); strlcpy(info.pcZoneId, zone.cString, MIN(zone.cStringLength, TPW_URL_MAX_LENGTH)); map->insert(make_pair(zone.UTF8String, info)); } } + (NSURL *)resolveBookmarkData:(NSData *)data { NSError *error; BOOL isStale = NO; NSURL *url = [NSURL URLByResolvingBookmarkData:data options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&isStale error:&error]; if (error) { NSLog(@"解析书签失败: %@", error); return nil; } if (isStale) { NSLog(@"书签已过期,重新生成"); NSData *newBookmark = [self createBookmarkForURL:url]; if (newBookmark) { [[NSUserDefaults standardUserDefaults] setObject:newBookmark forKey:@"savedBookmark"]; } } if ([url startAccessingSecurityScopedResource]) { return url; } return nil; } + (nullable NSData *)createBookmarkForURL:(NSURL *)url { NSError *error; NSData *bookmarkData = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope includingResourceValuesForKeys:nil relativeToURL:nil error:&error]; if (error) { NSLog(@"创建书签失败: %@", error); } return bookmarkData; } @end TPSSAppContext类在这里了
09-20
【源码免费下载链接】:https://renmaiwang.cn/s/os2te 大整数乘法是计算机科学中的一个重要领域,特别是在算法设计和数学计算中有着广泛应用。它涉及到处理超过标准整型变量范围的数值运算。在C++编程语言中,处理大整数通常需要自定义数据结构和算法,因为内置的`int`、`long long`等类型无法满足大整数的存储和计算需求。以下是对这个主题的详细阐述:1. **大整数数据结构**: 在C++中,实现大整数通常采用数组或链表来存储每一位数字。例如,可以使用一个动态分配的数组,每个元素表示一个位上的数字,从低位到高位排列。这种数据结构允许我们方便地进行加减乘除等操作。2. **乘法算法**: - **暴力乘法**:最直观的方法是类似于小学的竖式乘法,但效率较低,时间复杂度为O(n^2)。 - **Karatsuba算法**:由Alexander Karatsuba提出,将两个n位数的乘法转化为三个较小的乘法,时间复杂度为O(n^1.585)。 - **Toom-Cook算法**:比Karatsuba更通用,通过多项式插值和分解进行计算,有不同的变体,如Toom-3、Toom-4等。 - **快速傅里叶变换(FFT)**:当处理的大整数可以看作是多项式系数时,可以利用FFT进行高效的乘法,时间复杂度为O(n log n)。FFT在数论和密码学中尤其重要。3. **算法实现**: 实现这些算法时,需要考虑如何处理进位、溢出等问题,以及如何优化代码以提高效率。例如,使用位操作可以加速某些步骤,同时要确保代码的正确性和可读性。4. **源代码分析**: "大整数乘法全解"的源代码应包含了上述算法的实现,可能还包括了测试用例和性能比较。通过阅读源码,我们可以学习如何将理论算法转化为实际的程序,并理解各种优化技巧。5. **加说明**: 通常,源代码附带的说明会解释
内容概要:本文详细介绍了一个基于Java与Vue技术栈的向量数据库语义检索与相似文档查重系统的设计与实现。系统通过集成BERT等深度学习模型将文本转化为高维语义向量,利用Milvus等向量数据库实现高效存储与近似最近邻检索,结合前后端分离架构完成从文档上传、向量化处理、查重分析到结果可视化的完整流程。项目涵盖需求分析、系统架构设计、数据库建模、API接口规范、前后端代码实现及部署运维等多个方面,并提供了完整的代码示例和模块说明,支持多格式文档解析、智能分段、自适应查重阈值、高亮比对报告生成等功能,具备高扩展性、安全性和多场景适用能力。; 适合人群:具备一定Java和Vue开发基础的软件工程师、系统架构师以及从事自然语言处理、知识管理、内容安全等相关领域的技术人员,尤其适合高校、科研机构、企业IT部门中参与智能文档管理系统开发的专业人员。; 使用场景及目标:①应用于学术论文查重、企业知识产权保护、网络内容监控、政务档案管理等需要高精度语义比对的场景;②实现深层语义理解下的文档查重,解决传统关键词匹配无法识别语义改写的问题;③构建可扩展、高可用的智能语义检索平台,服务于多行业数字化转型需求。; 阅读建议:建议读者结合提供的完整代码结构与数据库设计进行实践操作,重点关注文本向量化、向量数据库集成、前后端协同逻辑及安全权限控制等核心模块。在学习过程中应逐步部署运行系统,调试关键接口,深入理解语义检索与查重机制的工作原理,并可根据实际业务需求进行功能扩展与模型优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值